Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

9p: fix slab cache name creation for real

This was attempted by using the dev_name in the slab cache name, but as
Omar Sandoval pointed out, that can be an arbitrary string, eg something
like "/dev/root". Which in turn trips verify_dirent_name(), which fails
if a filename contains a slash.

So just make it use a sequence counter, and make it an atomic_t to avoid
any possible races or locking issues.

Reported-and-tested-by: Omar Sandoval <osandov@fb.com>
Link: https://lore.kernel.org/all/ZxafcO8KWMlXaeWE@telecaster.dhcp.thefacebook.com/
Fixes: 79efebae4afc ("9p: Avoid creating multiple slab caches with the same name")
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Thorsten Leemhuis <regressions@leemhuis.info>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+3 -1
+3 -1
net/9p/client.c
··· 977 977 struct p9_client *p9_client_create(const char *dev_name, char *options) 978 978 { 979 979 int err; 980 + static atomic_t seqno = ATOMIC_INIT(0); 980 981 struct p9_client *clnt; 981 982 char *client_id; 982 983 char *cache_name; ··· 1037 1036 if (err) 1038 1037 goto close_trans; 1039 1038 1040 - cache_name = kasprintf(GFP_KERNEL, "9p-fcall-cache-%s", dev_name); 1039 + cache_name = kasprintf(GFP_KERNEL, 1040 + "9p-fcall-cache-%u", atomic_inc_return(&seqno)); 1041 1041 if (!cache_name) { 1042 1042 err = -ENOMEM; 1043 1043 goto close_trans;