[PATCH] ksmbd: compare the passkey lengths in ksmbd_compare_user()
From: Piyus Kedia
Date: Fri Dec 04 2026 - 10:14:43 EST
ksmbd_compare_user() compares the passkeys of two users over the
length of the first one:
if (memcmp(u1->passkey, u2->passkey, u1->passkey_sz))
Each passkey is allocated by ksmbd_alloc_user() at the hash_sz of its
own login response from the user-space daemon, so the second one can
be shorter. ntlm_authenticate() makes this comparison when a session
is re-authenticated, valid or expired, between the session's user and
the user just logged in, and when the later login response carried a
smaller hash_sz, memcmp() reads past the end of the new passkey:
BUG: KASAN: slab-out-of-bounds in memcmp+0x8b/0xb0
Read of size 8 at addr ffff88805834a120 by task kworker/1:0/26
Workqueue: ksmbd-io handle_ksmbd_work
memcmp+0x8b/0xb0 lib/string.c:665
ksmbd_compare_user+0x82/0xb0 fs/smb/server/mgmt/user_config.c:108
smb2_sess_setup+0x222d/0x3610 fs/smb/server/smb2pdu.c:2402
handle_ksmbd_work+0x4d7/0x13d0 fs/smb/server/server.c:223
process_one_work+0x6f7/0x11a0 kernel/workqueue.c:3497
worker_thread+0x417/0x7b0 kernel/workqueue.c:3580
Allocated by task 26:
__kmalloc_noprof+0x357/0x810 mm/slub.c:5556
ksmbd_alloc_user+0x122/0x2f0 fs/smb/server/mgmt/user_config.c:60
ksmbd_login_user+0x7d/0xd0 fs/smb/server/mgmt/user_config.c:28
smb2_sess_setup+0x2172/0x3610 fs/smb/server/smb2pdu.c:2375
The buggy address belongs to the object at ffff88805834a120
which belongs to the cache kmalloc-8 of size 8
The buggy address is located 0 bytes inside of
allocated 1-byte region [ffff88805834a120, ffff88805834a121)
Users whose passkeys differ in length are not the same user, so
compare the lengths before the bytes.
The lengths come from the daemon's login responses, so this takes a
daemon that reports a different hash size for the same account on a
later login. Like the upper bound on hash_sz in ksmbd_alloc_user(),
the check keeps such a response from becoming an out-of-bounds read.
We found this with a syzkaller-based fuzzing harness driven by an AI tool.
Fixes: a58b45a4dbfd ("ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO")
Closes: https://lore.kernel.org/linux-cifs/ksmbd-compare-user-passkey.20261204@xxxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
---
Tested on ksmbd-for-next (d70570cf8003) with KASAN, the same config and
image before and after, only this change between the two builds. The
reproducer plays the user-space daemon over the ksmbd genetlink family,
answers the two LOGIN_REQUESTs for one account with hash_sz 18 and then
1, and re-authenticates an NTLMSSP session over TCP:
before KASAN slab-out-of-bounds read in memcmp, from the call at
smb2pdu.c:2402 (on 7.4-rc5 the same read came from the
valid-session call, then at smb2pdu.c:2344)
after the same program runs to the end, the re-authentication is
rejected (STATUS_ACCESS_DENIED, as before), no report, twice
fs/smb/server/mgmt/user_config.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/mgmt/user_config.c b/fs/smb/server/mgmt/user_config.c
index 5efc3d7455b9..2bebf1ca0d80 100644
--- a/fs/smb/server/mgmt/user_config.c
+++ b/fs/smb/server/mgmt/user_config.c
@@ -105,7 +105,8 @@ bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2)
{
if (strcmp(u1->name, u2->name))
return false;
- if (memcmp(u1->passkey, u2->passkey, u1->passkey_sz))
+ if (u1->passkey_sz != u2->passkey_sz ||
+ memcmp(u1->passkey, u2->passkey, u1->passkey_sz))
return false;
return true;
--
2.34.1