[PATCH] mm/slab: fix probable issue of dentries registration under /sys/kernel/slab

From: Vladimir Zapolskiy

Date: Tue May 19 2026 - 21:11:21 EST


L2TP/IP and L2TP/IPv6 protocol names contain a slash symbol, however these
names are blindly used as symlinks to slab cache objects registered under
/sys/kernel/slab. This kind of symlink creation is successful, but its
dentry is obviously broken, as well it breaks the access to the list of
/sys/kernel/slab dentries.

Likely L2TP protocol renames cannot be done, since the defined protocol
names are exposed over /proc/net/protocols for years, but the symlink
names can be renamed, because they are yet to be properly created, and
this should be eventually done by this change.

The problem manifests itself, if CONFIG_L2TP_IP build symbol is selected.

Fixes: 81819f0fc8285 ("SLUB core")
Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@xxxxxxxxxx>
---
mm/slub.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index 0baa906f39ab..843bed864a7f 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -9634,6 +9634,7 @@ static struct saved_alias *alias_list;
int sysfs_slab_alias(struct kmem_cache *s, const char *name)
{
struct saved_alias *al;
+ const char *al_name;

if (slab_state == FULL) {
/*
@@ -9652,8 +9653,27 @@ int sysfs_slab_alias(struct kmem_cache *s, const char *name)
if (!al)
return -ENOMEM;

+ al_name = kstrdup_const(name, GFP_KERNEL);
+ if (!al_name) {
+ kfree(al);
+ return -ENOMEM;
+ }
+
+ if (strchr(al_name, '/')) {
+ char *n;
+
+ n = kstrdup(al_name, GFP_KERNEL);
+ kfree_const(al_name);
+ if (!n) {
+ kfree(al);
+ return -ENOMEM;
+ }
+
+ al_name = strreplace(n, '/', '_');
+ }
+
al->s = s;
- al->name = name;
+ al->name = al_name;
al->next = alias_list;
alias_list = al;
kmsan_unpoison_memory(al, sizeof(*al));
@@ -9691,6 +9711,7 @@ static int __init slab_sysfs_init(void)
if (err)
pr_err("SLUB: Unable to add boot slab alias %s to sysfs\n",
al->name);
+ kfree_const(al->name);
kfree(al);
}

--
2.49.0