Commit b0cdc1bb authored by Linus Torvalds's avatar Linus Torvalds Committed by Wen Zhiwei
Browse files

9p: fix slab cache name creation for real

stable inclusion
from stable-v6.6.62
commit 9da3636a4880e59495d52f2d13d59b275c3b7df3
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB5BUT

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9da3636a4880e59495d52f2d13d59b275c3b7df3



--------------------------------

commit a360f311f57a36e96d88fa8086b749159714dcd2 upstream.

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: default avatarOmar 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: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Thorsten Leemhuis <regressions@leemhuis.info>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent c193c0f2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -976,6 +976,7 @@ static int p9_client_version(struct p9_client *c)
struct p9_client *p9_client_create(const char *dev_name, char *options)
{
	int err;
	static atomic_t seqno = ATOMIC_INIT(0);
	struct p9_client *clnt;
	char *client_id;
	char *cache_name;
@@ -1035,7 +1036,8 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
	if (err)
		goto close_trans;

	cache_name = kasprintf(GFP_KERNEL, "9p-fcall-cache-%s", dev_name);
	cache_name = kasprintf(GFP_KERNEL,
		"9p-fcall-cache-%u", atomic_inc_return(&seqno));
	if (!cache_name) {
		err = -ENOMEM;
		goto close_trans;