From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796397274; b=0dzDkPQ3QuesmAyJxtk3cNwhPh4vBKKg+HtbSstO1vCvgqyqDQ2VIGsawzwEII31nvCg jJvU2RDAJmJrARLBUAh5iwS5HAHbYR+8f6KPsoUxZu2kbCScBqoQnhtRDyTIKVkWJVIiw sADnKX4wfEyWHBk2HQQ8eQvAVpcnkS6kFwMeff0w5VzLFDvrAvxeOHVO/55UaMSgw8hVp tVXszfCUp9NysKGlmObQRRTQdcBocO9vr+w576zA2L5l1+O6dD62Hm66UxoCRKeG3juJX vw41OkG1J9bgtMECZSLsfZwaruEcM7x0XRqKec6clxWyfa4F59GrVWEo/Q4kIIZrXiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796397274; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=kG6oqlCMXPWT0U+k0i1XCPGxJl28DvddsWZBmB+/904=; b=Wkhx57K53Xupc2raJPjnc7gVEGxmd/j8jrqbZEVpeSkBpA/Soe8GgBaeBtcJMpIZJ9R+ cBPaooWfRx5X0BdkuXKJH8K7G1YRKpEZtCV4ihZbhaMYA4wYgHvIfSDPTkTv1LxGLdlIZ VUTycfk1qYCABetXCmbXUdCA8Qm/FmoLtOXL9+p0/4RosuW+S9855CzEj51pQfqri5AYh jbGJ3j+L/YB79KyoGxxXm7iQQg4MIAjaR9qUqzf1JYrbPHtThxOpnJsuu4GTwu5n5cJfb +7o1ARaBru1qvW2ZGBdcpme3pYQ1LL/w251JoFHDjHH0cTORaiJflyKCBkwBR/FegHg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=gJJj6dn7; arc=none smtp.remote-ip=209.85.215.176 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11D83606A322 for ; Fri, 4 Dec 2026 15:14:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 11D83606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=gJJj6dn7 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cded3aee68bso608826a12.0 for ; Fri, 04 Dec 2026 07:14:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796397272; x=1797002072; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=kG6oqlCMXPWT0U+k0i1XCPGxJl28DvddsWZBmB+/904=; b=gJJj6dn7LamyQXTWUda0yOk+r4Y6qq51CQ0jbm3yPMUxoTaNAwYp2vI2hMn0qwIUVt mlqWxxwHl4FbE+1eN1DH2xJW8k9GOk+e3CyUHn5aUG9XG3Ra6VDiGGXqcqoCKYHvAf2J qDC7PyBPRgq3SncfU3uoggkfYvpUIk5YUipwE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796397272; x=1797002072; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kG6oqlCMXPWT0U+k0i1XCPGxJl28DvddsWZBmB+/904=; b=zDQpohjw2j1MkzX/6dgQ/QCjY270FlgA8IIpWURE3XpwSqlxackbpXG7FDfdf4fXyz qmVyr7RzXFN0Tx2XBfBaH7HgLu3gOf2W963lB6oZCJSIwBgtTcwghdz8WRzXy4SEUean fSo8opTZdR5Ee90ghahFZv6MbK8hNUnfEcyFklm/Myage5uSotJS9JhIFci1aVaJ4FZ3 ym/QDOUrV7Lk4fkrPpwQd9EH/cFyfY7bfaAI61XqHFf3Rm4nd6XAyOBp21M39Pq4JG/J q6fNTkmp6PhubPEN2ltHjLvRc0WAGGOfJG9xWbDV6x9qXC32yoUaLL6vVQ04tZv3Ik11 lt0A== X-Forwarded-Encrypted: i=1; AL+hErHIQzCba1Kzqc5aS7N34E7f2Pb5TGBlquvEMWgHwkgZuXuTNgRmz5GqyoJNemxr9BphzKsxruRKqNHXp88=@vger.kernel.org X-Gm-Message-State: AB4q+uF/8IpAiI+eTRNmtby/XEBEofTL6gW587lBTyIO4TPn5WBcUcmg Ce7MFDD5YQVnSBD0LFOA4gKX4lBX31a5fqXmvCrwoi/kEjCeFLj/atBqGaQMY4d3OpQ= X-Gm-Gg: AZFdTZde5phuRM0DaeMXzraODKkozPeWxytqXmvrR2J56GI42hMkVMGon/tayacUPhW J4+FEN4fngeqajXeeqTD4CslAjX1Z0PSj3DGDObBCgoXdPKJ/fm9AAtJokbhl3X0cEWtS69/Zus mgLvE2vPxTYbalQoni5x6mSTQQcohONcTEbmWtzlXXWQu4mZCmD8+/j83s6lICtfEdLLYwyFSOu CMAP5Sj2KdnC9/kBhm5vBW5ZpuCBRS3yMY8Xu2M1cJG6Zszm7SFejwGqcx+CGkkq8+K6ezzikQx 4yHO8D6TCEZThN+DByK5KzIm93axcv0mw5LI7kXy9rFNTEIDaq/zH2iWuCg6ybZ1NnviYiaF2SP Ympb2Ifdu1s1j8Vl326ac1i7JU4zs67Oh/snLLp5AEMOeM/B+GAHOegiwNZpdd+uk7c9m9TeDwp QdoPuz2CCUDQhqAvXPOLO/j/g8ZI00JTLyADk7FnYcJ1yola7AV5riq0sO0gs53BMzgRIUtXIvT h1hOY3uiCHNiG4FxiwmO2nFzKozX07ACvWUqaWnkH8rxca5nYViL9XRTUWbTai7bnZNH9NIXlFW 3cbB/lC2SFR9pdAPwbumOifJcvGCf9gj9hzk4XZJHxyx/G61InwO2fbIDsf01zDTeK2TswmI9MY 29iTk3tvCiJD24U60gaZrFY+/SwsHQO+FqwTkjw+M4h+kxFkeh627JA6TIjSqQg7fvA== X-Received: by 2002:a17:902:ea10:b0:2ed:662:e485 with SMTP id d9443c01a7336-2f1ba05958dmr16084505ad.2.1796397272248; Fri, 04 Dec 2026 07:14:32 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b7964777sm14151285ad.67.2026.12.04.07.14.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:14:31 -0800 (PST) From: Piyus Kedia To: Namjae Jeon , linux-cifs@vger.kernel.org Cc: Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] ksmbd: slab-out-of-bounds read in ksmbd_compare_user() on session re-authentication Date: Fri, 4 Dec 2026 20:44:26 +0530 Message-Id: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, ksmbd_compare_user() compares two users' passkeys over the length of the first one only: fs/smb/server/mgmt/user_config.c:108 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: fs/smb/server/mgmt/user_config.c:59 user->passkey_sz = resp->hash_sz; user->passkey = kmalloc(resp->hash_sz, KSMBD_DEFAULT_GFP); so nothing makes u2's passkey as long as u1's. ntlm_authenticate() calls it when a client re-authenticates a session, with u1 the session's user and u2 the user just logged in for this request (fs/smb/server/smb2pdu.c:2344; the expired-session branch at 2355 makes the same call). When the second login response carried a shorter hash, memcmp() reads past the end of the new passkey: BUG: KASAN: slab-out-of-bounds in memcmp+0x51/0xd0 lib/string.c:665 Read of size 8 at addr ffff888040fc1dc0 by task kworker/2:2/3253 Workqueue: ksmbd-io handle_ksmbd_work memcmp+0x51/0xd0 lib/string.c:665 bcmp+0x36/0x60 lib/string.c:697 ksmbd_compare_user+0x97/0xd0 fs/smb/server/mgmt/user_config.c:108 ntlm_authenticate+0x37e/0x9a0 fs/smb/server/smb2pdu.c:2344 smb2_sess_setup+0x155e/0x1730 fs/smb/server/smb2pdu.c:2774 __process_request+0x28f/0x4e0 fs/smb/server/server.c:163 __handle_ksmbd_work+0x440/0xbc0 fs/smb/server/server.c:296 handle_ksmbd_work+0x5f/0xa0 fs/smb/server/server.c:387 Allocated by task 3253: __kmalloc_noprof+0x2ba/0x620 mm/slub.c:5562 ksmbd_alloc_user+0x13b/0x360 fs/smb/server/mgmt/user_config.c:60 ksmbd_login_user+0xb2/0x100 fs/smb/server/mgmt/user_config.c:28 session_user+0x1ba/0x240 fs/smb/server/smb2pdu.c:2294 ntlm_authenticate+0x212/0x9a0 fs/smb/server/smb2pdu.c:2328 The buggy address belongs to the object at ffff888040fc1dc0 which belongs to the cache kmalloc-8 of size 8 The buggy address is located 0 bytes inside of allocated 1-byte region [ffff888040fc1dc0, ffff888040fc1dc1) How it is reached. The reproducer registers itself as the ksmbd daemon over the ksmbd generic netlink family (KSMBD_EVENT_STARTING_UP), then connects to the server over TCP as an SMB 3.1.1 client and does an NTLMSSP session setup as user "u" twice on the same SessionId. Its daemon answers the two LOGIN_REQUESTs for "u" with hash_sz 18 and then 1, with KSMBD_USER_FLAG_GUEST_ACCOUNT set so the NTLMv2 check is skipped and the first setup leaves the session valid. The second setup then compares the session's 18-byte passkey with the new 1-byte one. It has reproduced every time we ran it: five runs on two kernels, one of them unprivileged (below). Impact - who can trigger it: - The two lengths come from the daemon's login responses; an SMB client controls only the account name and the NTLMSSP blobs. So the trigger is a daemon that reports a different hash size for the same account on a later login. We have not found a way to make ksmbd.mountd do that from the network, but we have not audited ksmbd-tools either. This is the trust boundary of 7405d0ba2943 ("ksmbd: fix slab-out-of-bounds read in ksmbd_alloc_user()"), which bounds hash_sz from above; nothing bounds it from below against the session's earlier login. - With CONFIG_SMB_SERVER_CHECK_CAP_NET_ADMIN=y, the default, handle_startup_event() and handle_generic_event() require CAP_NET_ADMIN, checked by netlink_capable() against the initial user namespace. An unprivileged user cannot register as the daemon or send it a login response, from a user namespace either, so on a default build this needs root (or a compromised or buggy daemon). - With that option disabled, neither handler checks anything. We ran the same reproducer as uid 65534 with every capability dropped (CapEff and CapBnd 0), on a 7.4.0-rc5 build with the option off and no daemon running: it registered as the daemon and triggered the same KASAN report. So on such a build any local user can trigger it while ksmbd.mountd is not running. While it is running, handle_startup_event() refuses a second daemon, but handle_generic_event() matches a response to its request only by type and by a handle from an IDA, not by sender, so a forged LOGIN_RESPONSE from another process would be accepted as well; we have not tried that. - What the read does: it reads up to passkey_sz bytes from a shorter allocation, here 17 bytes past a 1-byte kmalloc-8 object. Nothing read is returned to the client; the bytes only decide whether the re-authentication is accepted or fails with -EKEYREJECTED. Seen on 7.4.0-rc5 and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04) with KASAN. On 7.4-rc5 the read came from the valid-session call (smb2pdu.c:2344 there); on ksmbd-for-next the same program reached it through the expired-session call, smb2pdu.c:2402: BUG: KASAN: slab-out-of-bounds in memcmp+0x8b/0xb0 Read of size 8 at addr ffff88805834a120 by task kworker/1:0/26 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 ksmbd_compare_user() and both calls are the same in mainline (007722b8211f, 2026-12-03). The comparison has been this way since it was added in a58b45a4dbfd ("ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO"), so v5.17 and later. A patch follows in reply to this mail. Users whose passkeys differ in length are not the same user, so it compares the lengths before the bytes. On ksmbd-for-next, same config and image before and after, only that change between the two builds: without the patch KASAN slab-out-of-bounds read, as above with the patch the same program runs to the end and the re-authentication is rejected (STATUS_ACCESS_DENIED, as before), no report, twice This was found by AI-driven fuzzing built on top of syzkaller; its analysis was then checked by hand against the code and every claim above was reproduced. The reproducer is fuzzer-generated, runs the daemon and the client in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796397292; b=R1hA8ko6Qv7/R+rERwAADZxOmszPcvU4ygGTcSn8RuAslfM6o+52UHrWbuVfD/KcCF2A 6/su1Zt3GMyHfEOmTJvVAErRzKikkd6o0Y9Ujy0RG4x+No0tW/pCIkrsyOzTwgy/lReZc iz6aITIcwI+i4Mc8WllcH/q0Sig9SvXWoqzdZ0/CaJnBxLtfbitJvRjIoeZQ8csq5e2BA bYujNDnZoMz/lNw/iXSD1F+4i5yOEUTNMIKn9B5O5PeN32/KQw0uj4YkY7muxxrS0mKn5 NyVnX/r5qonIbvMlu8C/lvvesrqIsuSkpKJ3XhkCVDQMAZUWMd3Kcu+hCljAZBGBcLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796397292; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=kG6oqlCMXPWT0U+k0i1XCPGxJl28DvddsWZBmB+/904=; b=Cazp+/yyyyBiT9LWKDG2I4dq7J4hJYUy+JT/PhAgepQLKqgMMUcdO0x9ui5wftMq+NX4 lkG8lFSPcx8Db9wtuXDENJiryfH6njwqgnpfvksPSsCVwSF/tbWC2hvfQf2XqSeuTv+3z Js8rklFIFcFKOg3WZC7RfINATTz34OCjxJ7JggE6gpsdCGkFdrUTxqytaFcsZ/gG1G+Wv lz0eG+c1vcONeVdXHBe+JTDiLfg+VejvpUnlBnTtCqROyPoVI7DQNwQBCy6FGu6dnM2DA sKDyMmRvTzhUZoM+Q75XazL0pVQxN4jfpoOChykAUi8pou+My7Cmjj39RhkGM1xwNsg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=flhmtzpz; arc=none smtp.remote-ip=209.85.214.177 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A5BC606A32C for ; Fri, 4 Dec 2026 15:14:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A5BC606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=flhmtzpz Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2efddf749e5so10748735ad.1 for ; Fri, 04 Dec 2026 07:14:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796397291; x=1797002091; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=kG6oqlCMXPWT0U+k0i1XCPGxJl28DvddsWZBmB+/904=; b=flhmtzpzJrsySQliBnWJcJWciwOWij5ekovTzeFrBm8grT3mZ5WO4lE9r4qpKtK/Jx LLhEG+6e9MTVgJYj+VecYN7/VWGO5Vu0jkCKQ/PvWmekoA8J9JdVvly0Bha8hBKgfo84 RATSWoEXsH6KWSC6TviLTwMQv9K1z0Pk7IHH0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796397291; x=1797002091; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kG6oqlCMXPWT0U+k0i1XCPGxJl28DvddsWZBmB+/904=; b=CvZTd1nlY09m0EpsLAAGnsDGzO7DnQHbcim1wfalgRqjs0hGe7gqUZg55QxnC6kswT xDtuyVYP/DH2Qqu/Gvq9TELMEBq0XLDaraKF5YROrCU/q940VwCOiqXMFLVbhIiAobhn 8XtbEmLG1LDpWHLv++WS5vjFGCvCqI9UBjWtrawzqI7sRLFLgBgiDHWFQnV0bwhHCgpB /Pi8WCOCiZne7H5/sUCqX3HFAIDmOW9PvJXDtVjvTLqg+KMNZUiWIfKqiDBQL98/mKec g3JFFplM7E6dCRfQeWSjrz9atnw8IFM1ZN3gN5HRf8u3Q93SUQVcl6RYLu8b8a9C+M/U vH9A== X-Forwarded-Encrypted: i=1; AL+hErEeniYG2/S7KrizafvbH6P9gWIb9J1C6LorKDdQ328P+ma/nF9QJNc21bXJgJAvHP2UvJkuDjn0wISWlAs=@vger.kernel.org X-Gm-Message-State: AB4q+uE6WXr6dpIa8CdhOJTgbaVuDotGojW1zmPuZ4/vvGaN4HsFYGvs IhhhJOxKKLMFw0uNCvcN6fO9gf59DZMWedr5761Ic4yTxI0CJzH/3apVksLXBO+8oAc= X-Gm-Gg: AZFdTZdww9Bp1Pwsh52F5iGFdJpKYiOWybrb22eGCnPwamigzaBsNapuIP/slnthXaT +qPc3ficHQyLVGu5AgeNWUro60z0IFObFYLm2BpSbksGcHLZPYD1hnh5UNOqrLcUU+/O//7vU0h P62yHXiMTmLJt6fPEf4jlfuPJFC1uyML6pcETTKCyDda8PL2V0S3/NMgOhU3hC/tJDXeWm/NLyW 4WG6Jgsl4igtqHZEfI0+zKkN+oyR1n8ULNFRd6zXjtQmRca4DpNQcVUGH729O0u3oZDjU5uvAUg B0CSv1jLKEgi+Nq4LRwybVpOjpGAnf4Q64tRXO0VwqeKZKQECCzwDkgzZOJtRKj9WX4GrS1Teys dcDykSRZvpR8NVoXaa1ng4L1PJXtoj5g5xBeLD/p4xINwnn5JPav7hH3uGFW37zo1pBB7V/gf0v c9/itqVy9h+Tx/gaA0WgSgHap0vmpczMiTn7LwegpBxEE953XxQ/FvhqYW4ZTTKNp5iA+xH7ebc 7eCwAQDN6a20CjZ35UCLArpwoWpzTlpb4RQGFc7AJZ+YPLYWPBmBNbSbSKDBz523BshFrFNcUWn YeZpFMtF0GkpyaNs6uBrUgLQmW4e4G15HFUU9lJeHvudqsS8sjmWWMacBOoWuRHXxUZh4AWdboz A50F+t/EPM05IXj/Uu6Y5JI7xZ6xqqY+9GUYkvMHsOJoBfI6Em7BRin4H6Og35r+W X-Received: by 2002:a17:902:ec86:b0:2e9:5e06:3345 with SMTP id d9443c01a7336-2f197076780mr45156095ad.2.1796397290788; Fri, 04 Dec 2026 07:14:50 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b784da61sm14284285ad.1.2026.12.04.07.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:14:50 -0800 (PST) From: Piyus Kedia To: Namjae Jeon , linux-cifs@vger.kernel.org Cc: Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] ksmbd: slab-out-of-bounds read in ksmbd_compare_user() on session re-authentication Date: Fri, 4 Dec 2026 20:44:45 +0530 Message-ID: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: <20261204151445.0JTQkluyTK-SmGb2K12_LG_pBCkcgyIqkEzh9Y-KTzQ@z> Hi, ksmbd_compare_user() compares two users' passkeys over the length of the first one only: fs/smb/server/mgmt/user_config.c:108 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: fs/smb/server/mgmt/user_config.c:59 user->passkey_sz = resp->hash_sz; user->passkey = kmalloc(resp->hash_sz, KSMBD_DEFAULT_GFP); so nothing makes u2's passkey as long as u1's. ntlm_authenticate() calls it when a client re-authenticates a session, with u1 the session's user and u2 the user just logged in for this request (fs/smb/server/smb2pdu.c:2344; the expired-session branch at 2355 makes the same call). When the second login response carried a shorter hash, memcmp() reads past the end of the new passkey: BUG: KASAN: slab-out-of-bounds in memcmp+0x51/0xd0 lib/string.c:665 Read of size 8 at addr ffff888040fc1dc0 by task kworker/2:2/3253 Workqueue: ksmbd-io handle_ksmbd_work memcmp+0x51/0xd0 lib/string.c:665 bcmp+0x36/0x60 lib/string.c:697 ksmbd_compare_user+0x97/0xd0 fs/smb/server/mgmt/user_config.c:108 ntlm_authenticate+0x37e/0x9a0 fs/smb/server/smb2pdu.c:2344 smb2_sess_setup+0x155e/0x1730 fs/smb/server/smb2pdu.c:2774 __process_request+0x28f/0x4e0 fs/smb/server/server.c:163 __handle_ksmbd_work+0x440/0xbc0 fs/smb/server/server.c:296 handle_ksmbd_work+0x5f/0xa0 fs/smb/server/server.c:387 Allocated by task 3253: __kmalloc_noprof+0x2ba/0x620 mm/slub.c:5562 ksmbd_alloc_user+0x13b/0x360 fs/smb/server/mgmt/user_config.c:60 ksmbd_login_user+0xb2/0x100 fs/smb/server/mgmt/user_config.c:28 session_user+0x1ba/0x240 fs/smb/server/smb2pdu.c:2294 ntlm_authenticate+0x212/0x9a0 fs/smb/server/smb2pdu.c:2328 The buggy address belongs to the object at ffff888040fc1dc0 which belongs to the cache kmalloc-8 of size 8 The buggy address is located 0 bytes inside of allocated 1-byte region [ffff888040fc1dc0, ffff888040fc1dc1) How it is reached. The reproducer registers itself as the ksmbd daemon over the ksmbd generic netlink family (KSMBD_EVENT_STARTING_UP), then connects to the server over TCP as an SMB 3.1.1 client and does an NTLMSSP session setup as user "u" twice on the same SessionId. Its daemon answers the two LOGIN_REQUESTs for "u" with hash_sz 18 and then 1, with KSMBD_USER_FLAG_GUEST_ACCOUNT set so the NTLMv2 check is skipped and the first setup leaves the session valid. The second setup then compares the session's 18-byte passkey with the new 1-byte one. It has reproduced every time we ran it: five runs on two kernels, one of them unprivileged (below). Impact - who can trigger it: - The two lengths come from the daemon's login responses; an SMB client controls only the account name and the NTLMSSP blobs. So the trigger is a daemon that reports a different hash size for the same account on a later login. We have not found a way to make ksmbd.mountd do that from the network, but we have not audited ksmbd-tools either. This is the trust boundary of 7405d0ba2943 ("ksmbd: fix slab-out-of-bounds read in ksmbd_alloc_user()"), which bounds hash_sz from above; nothing bounds it from below against the session's earlier login. - With CONFIG_SMB_SERVER_CHECK_CAP_NET_ADMIN=y, the default, handle_startup_event() and handle_generic_event() require CAP_NET_ADMIN, checked by netlink_capable() against the initial user namespace. An unprivileged user cannot register as the daemon or send it a login response, from a user namespace either, so on a default build this needs root (or a compromised or buggy daemon). - With that option disabled, neither handler checks anything. We ran the same reproducer as uid 65534 with every capability dropped (CapEff and CapBnd 0), on a 7.4.0-rc5 build with the option off and no daemon running: it registered as the daemon and triggered the same KASAN report. So on such a build any local user can trigger it while ksmbd.mountd is not running. While it is running, handle_startup_event() refuses a second daemon, but handle_generic_event() matches a response to its request only by type and by a handle from an IDA, not by sender, so a forged LOGIN_RESPONSE from another process would be accepted as well; we have not tried that. - What the read does: it reads up to passkey_sz bytes from a shorter allocation, here 17 bytes past a 1-byte kmalloc-8 object. Nothing read is returned to the client; the bytes only decide whether the re-authentication is accepted or fails with -EKEYREJECTED. Seen on 7.4.0-rc5 and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04) with KASAN. On 7.4-rc5 the read came from the valid-session call (smb2pdu.c:2344 there); on ksmbd-for-next the same program reached it through the expired-session call, smb2pdu.c:2402: BUG: KASAN: slab-out-of-bounds in memcmp+0x8b/0xb0 Read of size 8 at addr ffff88805834a120 by task kworker/1:0/26 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 ksmbd_compare_user() and both calls are the same in mainline (007722b8211f, 2026-12-03). The comparison has been this way since it was added in a58b45a4dbfd ("ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO"), so v5.17 and later. A patch follows in reply to this mail. Users whose passkeys differ in length are not the same user, so it compares the lengths before the bytes. On ksmbd-for-next, same config and image before and after, only that change between the two builds: without the patch KASAN slab-out-of-bounds read, as above with the patch the same program runs to the end and the re-authentication is rejected (STATUS_ACCESS_DENIED, as before), no report, twice This was found by AI-driven fuzzing built on top of syzkaller; its analysis was then checked by hand against the code and every claim above was reproduced. The reproducer is fuzzer-generated, runs the daemon and the client in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia