linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] slab: Error out on duplicate cache names when DEBUG_VM=y
@ 2024-08-04 21:28 Pedro Falcato
  2024-08-05 10:24 ` Pedro Falcato
  0 siblings, 1 reply; 4+ messages in thread
From: Pedro Falcato @ 2024-08-04 21:28 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka
  Cc: Roman Gushchin, Hyeonggon Yoo, linux-mm, linux-kernel, Pedro Falcato

Duplicate slab cache names can create havoc for userspace tooling that
expects slab cache names to be unique. This is a reasonable expectation.

Link: https://lore.kernel.org/linux-fsdevel/2d1d053da1cafb3e7940c4f25952da4f0af34e38.1722293276.git.osandov@fb.com/
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
---
 mm/slab_common.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index 40b582a014b..c4f31c887f9 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -88,6 +88,19 @@ unsigned int kmem_cache_size(struct kmem_cache *s)
 EXPORT_SYMBOL(kmem_cache_size);
 
 #ifdef CONFIG_DEBUG_VM
+
+static bool kmem_cache_is_duplicate_name(const char *name)
+{
+	struct kmem_cache *s;
+
+	list_for_each_entry(s, &slab_caches, list) {
+		if (!strcmp(s->name, name))
+			return true;
+	}
+
+	return false;
+}
+
 static int kmem_cache_sanity_check(const char *name, unsigned int size)
 {
 	if (!name || in_interrupt() || size > KMALLOC_MAX_SIZE) {
@@ -95,6 +108,12 @@ static int kmem_cache_sanity_check(const char *name, unsigned int size)
 		return -EINVAL;
 	}
 
+	if (kmem_cache_is_duplicate_name(name)) {
+		/* Duplicate names will confuse slabtop, et al */
+		pr_err("%s: name %s already exists as a cache\n", __func__, name);
+		return -EINVAL;
+	}
+
 	WARN_ON(strchr(name, ' '));	/* It confuses parsers */
 	return 0;
 }
-- 
2.46.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-05 11:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-04 21:28 [PATCH] slab: Error out on duplicate cache names when DEBUG_VM=y Pedro Falcato
2024-08-05 10:24 ` Pedro Falcato
2024-08-05 10:38   ` Vlastimil Babka
2024-08-05 11:24     ` Mateusz Guzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox