mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] 9p: Add const and unsigned to wnames allocation type
@ 2026-09-17 21:11 Kees Cook
  2026-09-17 23:30 ` Dominique Martinet
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2026-09-17 21:11 UTC (permalink / raw)
  To: Eric Van Hensbergen
  Cc: Kees Cook, Kees Cook, Latchesar Ionkov, Dominique Martinet,
	Christian Schoenebeck, v9fs, linux-kernel, linux-hardening

From: Kees Cook <kees+treewide@kernel.org>

In preparation for converting the kmalloc family of allocators to the
type-aware kmalloc_obj family, we need to make sure that the returned
type from the allocation matches the type of the variable being
assigned. (The kmalloc family returns "void *", which can be implicitly
cast to any pointer type.)

The assigned type is "const unsigned char **", but the converted
allocation type would be "char **", which differs in both the const
qualifier and the signedness of the character type. Take the size from
the assignment target instead. No change in allocation size results.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
fs/9p/fid.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
---
Cc: Eric Van Hensbergen <ericvh@kernel.org>
Cc: Latchesar Ionkov <lucho@ionkov.net>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Christian Schoenebeck <linux_oss@crudebyte.com>
Cc: <v9fs@lists.linux.dev>
---
 fs/9p/fid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/9p/fid.c b/fs/9p/fid.c
index 76242d450aa7..65dc7972b396 100644
--- a/fs/9p/fid.c
+++ b/fs/9p/fid.c
@@ -154,7 +154,7 @@ static int build_path_from_dentry(struct v9fs_session_info *v9ses,
 	for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
 		n++;
 
-	wnames = kmalloc_array(n, sizeof(char *), GFP_KERNEL);
+	wnames = kmalloc_array(n, sizeof(*wnames), GFP_KERNEL);
 	if (!wnames)
 		goto err_out;
 
-- 
2.34.1


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

end of thread, other threads:[~2026-09-17 23:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 21:11 [PATCH] 9p: Add const and unsigned to wnames allocation type Kees Cook
2026-09-17 23:30 ` Dominique Martinet

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

all inboxes | Powered by JetHome®