Skip to content

Commit 4c39529

Browse files
heatdtehcaster
authored andcommitted
slab: Warn on duplicate cache names when DEBUG_VM=y
Duplicate slab cache names can create havoc for userspace tooling that expects slab cache names to be unique [1]. This is a reasonable expectation. Sadly, too many duplicate name problems are out there in the wild, so simply warn instead of pr_err() + failing the sanity check. [ [email protected]: change to WARN_ON(), see the discussion at [2] ] Link: https://lore.kernel.org/linux-fsdevel/2d1d053da1cafb3e7940c4f25952da4f0af34e38.1722293276.git.osandov@fb.com/ [1] Link: https://lore.kernel.org/all/[email protected]/ [2] Signed-off-by: Pedro Falcato <[email protected]> Acked-by: Christoph Lameter <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 5be63fc commit 4c39529

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

mm/slab_common.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,30 @@ unsigned int kmem_cache_size(struct kmem_cache *s)
8888
EXPORT_SYMBOL(kmem_cache_size);
8989

9090
#ifdef CONFIG_DEBUG_VM
91+
92+
static bool kmem_cache_is_duplicate_name(const char *name)
93+
{
94+
struct kmem_cache *s;
95+
96+
list_for_each_entry(s, &slab_caches, list) {
97+
if (!strcmp(s->name, name))
98+
return true;
99+
}
100+
101+
return false;
102+
}
103+
91104
static int kmem_cache_sanity_check(const char *name, unsigned int size)
92105
{
93106
if (!name || in_interrupt() || size > KMALLOC_MAX_SIZE) {
94107
pr_err("kmem_cache_create(%s) integrity check failed\n", name);
95108
return -EINVAL;
96109
}
97110

111+
/* Duplicate names will confuse slabtop, et al */
112+
WARN(kmem_cache_is_duplicate_name(name),
113+
"kmem_cache of name '%s' already exists\n", name);
114+
98115
WARN_ON(strchr(name, ' ')); /* It confuses parsers */
99116
return 0;
100117
}

0 commit comments

Comments
 (0)