From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796500365; b=Z5+q17HsBeYQbbRPC4h3Ad0lDz7v908awK+Ct831nQrJbyJ3k4b1+4Dj66GMb9sXK5Nl dXNoZybxj7lix2hiNQ0t+Zeikz17FL0AfQE+kFzlwQ60FwdsYHZ1QYanXeZkUfC9bGn5g HYAvUYGhkZJ59IeZKrok687ryvpY9KPLbe6f569jIVZp45JdV9LLxvsj8osihlq/uxxel QXMlvsMdRHH/aKwYDDDGN9zdEHzSNpynQpxYRnqw7Ok0olLJN6oCfpmoUsJqVmcPtsZU8 bcJeAnMXDXDEiKz2KciQTCL8XlPmSrRB7nO9Fx8yrsNHNY8VeVnHTmWc5KEzcJqMFIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796500365; 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=mOu/AE6gs6BBSqFVXJDxzClg1WtIQjKDt51/wdOXStE=; b=UYZRKiRTGqsglKgN96dtH//bPIzg9CICRmXSh8H25KvZbBB/AkO7DuZfvf/v8Lu7OQCn pBMfpulFqID7GVuafD6Ti13eA67GX+HrlxGBr30+n9YmNbtyDmoth3rgvIeX2nN7BwKoy aTrxB7W1pe/GpGvOsyKAHg008uaHr5JmcEm7G5XeDc/cN/8IrjePx9VusJmGnsSafUSy3 3PMEmsJGcTQgC/SLXFMr/rLjP9SCpPrXnuAkymWlmgGRNSd0kNAmsfbZuUn1wbmNIgMEn y1DZeuC6Go8UlHQAI7eSvN5moZqey4y2pbSN23R8oFpqRmBWLLosiU/vBULFjahBtcg== 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=EwnFYXh+; arc=none smtp.remote-ip=74.125.82.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 E0999606A333 for ; Sat, 5 Dec 2026 19:52:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E0999606A333 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=EwnFYXh+ Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b5d60183f9so2533648c88.1 for ; Sat, 05 Dec 2026 11:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796500364; x=1797105164; 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=mOu/AE6gs6BBSqFVXJDxzClg1WtIQjKDt51/wdOXStE=; b=EwnFYXh+U8vARZkeJ0fl/e4tKUL4OwKJPufScsS6kUT2jrXgLY70Vr3jugIXxBOXZD STI2wLdDvEzmFKkWSRU3qgC1f9zc2Yfcp+2lKj6t1byIZcTQ9XgfZFMRjTinV50yfGf4 Kmcdp1AudvB5MWxqKACvGXMbo6nvEgwQVty5Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796500364; x=1797105164; 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=mOu/AE6gs6BBSqFVXJDxzClg1WtIQjKDt51/wdOXStE=; b=IkTEfeW1/gLvOeEncTKEd7FmjVzxnQnJGblzBDGt2At5gXZVIZ4ysWVO6ogOy7KmDq pldsrptxVrH9v1stHeh3y3XLS1rPnKUi+AYbqDPh8XNG8/xTsedk+My+HR3vmkP7TCYO VBoFE5f800vAZKU4XCLtwyrYKUi529EG0vdsFh+AxHbACmfe8w1haQFU8D8Xz4rnkw0U /yZU8gBXpbqQXrSV8HhBm1x/0hPf4P8LXQ9SVQ6oiK0tH0QhQ3QZzzRyC+dnYOUmj3Sl tZYKQsrZcc83Ru+3dXlcdLmiuHLdtcNo0Ib6L9lcyOnmgajc26vtGAHo3TxVIZh9rt/v j5cw== X-Forwarded-Encrypted: i=1; AL+hErGSxLy/s3rw21/SWu0h/yz3BbscrT1NE4RaZCqf4midEAzVTPBWA9wEx6+TU5I40rU+kcZ8uU5bHAov1XQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/zWjAESGIFubVnODPPuuqDQCQ96UsQNAB3yHKVMVA06IMbJ5Rv EvGAejaT9q5Y2Qhde/LdkqqHMU3RqVe3056xq71Lo8Gs5F76Xa6uZ78E9UnJA7K1iVM= X-Gm-Gg: AZFdTZecbgJJuiXVoPIPnJX8AVrJ/uhEwfnJWMiGzxRx/W9oWGRFBdMzGc/N9x9kvfd rCIXUuMd33X1RPiV5BG5nnkyJX9xbe+9VSKk0Sl6g6thfUpyH3IqnBWPdWft3aamdoyakp6+fp/ 2XkCMf/iY77HesKWyi+0U4if9zSsnTIKeosfnhGg7+hbRxjM2/bdY0/PZ0Dgof60xgvJ7TGhcgf GJAorEpgGLHLZGZMLIMZtV4k9MJcREpG1TaGWnPkIm444VNCxMrOEobkX25qhl7PSixPGwxt+sF YKekuacQRnUjBtpW+EcDOiVoaNwTvjcyAsRWndH0jHxIB8jUbtXjQNeGKMoAivqOvb7w13pdcWm 4HIinp801clXimEUg08U5hlBAzcZbhZ8gVamZwnSYDwvomB+5xOV/zDVr3QZoO7vBI0rwGgMywF nQH8qxKACP+L5aJ19tNU742Br9Qyvnckvw1uLDzjspdX3lVsSc5zl7No9iJeAbP+YJ9x3wzxy1G Qn4DWI6LEexeMwJXcNi5Sd3GJ4TCJqx5zCN4eovWEu94uvW5uHKJzULrKI47uLSQAAsaBPB2sS4 wE0orVuZfQE+OgZVLpGccVzhyLOIzJdWnIRK9RxIdoPJyCTn0PckGI6YPhAkDLxBNDFWDHwiEcW flkf29jXGq1mvmWFGIRifEXpoTKnT6eFd0q8JFoclKAe9lAxZGElTZd0YoZ/PEtJV X-Received: by 2002:a05:7022:b1d3:20b0:1ac:2f6d:e1c6 with SMTP id a92af1059eb24-1b5d70fb574mr5420694c88.6.1796500363619; Sat, 05 Dec 2026 11:52:43 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5c89sm35761323eec.18.2026.12.05.11.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 11:52:43 -0800 (PST) From: Piyus Kedia To: Paulo Alcantara , Namjae Jeon , linux-cifs@vger.kernel.org Cc: Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] smb: client: the key-dump ioctls read ses->auth_key while session setup replaces it Date: Sun, 6 Dec 2026 01:22:37 +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, CIFS_DUMP_FULL_KEY copies the session key out of ses->auth_key with no lock against session setup, and for the AES-128 ciphers always 16 bytes of it, whatever auth_key holds: fs/smb/client/ioctl.c:463 (cifs_dump_full_key) switch (ses->server->cipher_type) { case SMB2_ENCRYPTION_AES128_CCM: case SMB2_ENCRYPTION_AES128_GCM: out.session_key_length = CIFS_SESS_KEY_SIZE; ... case SMB2_ENCRYPTION_AES256_CCM: case SMB2_ENCRYPTION_AES256_GCM: out.session_key_length = ses->auth_key.len; ... if (copy_to_user(in, &out, sizeof(out))) { /* :490 */ ... end = in->data; if (copy_to_user(end, ses->auth_key.response, /* :497 */ out.session_key_length)) { and the older CIFS_DUMP_KEY does the same with memcpy() (ioctl.c:612). Session setup, which every reconnect runs, replaces auth_key in steps under ses->session_mutex: fs/smb/client/connect.c:4229 (cifs_setup_session) kfree_sensitive(ses->auth_key.response); ses->auth_key.response = NULL; fs/smb/client/sess.c:722 (decode_ntlmssp_challenge) ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen, GFP_KERNEL); fs/smb/client/cifsencrypt.c:370 (set_auth_key_response) ses->auth_key.len = len; out: ses->auth_key.response = rsp; So auth_key is first NULL, then the target info of the server's NTLMSSP CHALLENGE - tilen bytes, as many as the server sent - then the NTLMv2 response, whose first 16 bytes become the session key; and a setup that fails stays at the step it reached. A dump during a reconnect, or after one whose session setup failed, copies 16 bytes from NULL or from a target info that can be shorter, and with AES-256 the length (line 471) and the buffer (line 497) can belong to different setups, since the copy_to_user() between them can sleep in a page fault. The fuzzer hit the short target info on 7.4.0-rc5: BUG: KASAN: slab-out-of-bounds in cifs_dump_full_key+0x65f/0x8a0 fs/smb/client/ioctl.c:497 Read of size 16 at addr ffff88804302dfa0 by task syz-executor/9603 copy_to_user include/linux/uaccess.h:241 [inline] cifs_dump_full_key+0x65f/0x8a0 fs/smb/client/ioctl.c:497 cifs_ioctl+0xb47/0xf10 fs/smb/client/ioctl.c:643 vfs_ioctl+0x5d/0xb0 fs/ioctl.c:52 ... Allocated by task 1299: kmemdup_noprof+0x3e/0xa0 mm/util.c:138 decode_ntlmssp_challenge+0x49a/0x690 fs/smb/client/sess.c:722 SMB2_sess_auth_rawntlmssp_negotiate+0x454/0x600 fs/smb/client/smb2pdu.c:1918 SMB2_sess_setup+0x200/0x3d0 fs/smb/client/smb2pdu.c:2087 cifs_setup_session+0x6a5/0xaa0 fs/smb/client/connect.c:4240 smb2_reconnect+0x851/0x1380 fs/smb/client/smb2pdu.c:411 smb2_reconnect_server+0x53b/0x9d0 fs/smb/client/smb2pdu.c:4450 The buggy address belongs to the object at ffff88804302dfa0 which belongs to the cache kmalloc-8 of size 8 The buggy address is located 0 bytes inside of allocated 4-byte region [ffff88804302dfa0, ffff88804302dfa4) and also the other two, under their own titles: "KASAN: null-ptr-deref Read in cifs_dump_full_key", a read of size 16 at address 0 at the same line, auth_key.response being NULL between cifs_setup_session() and the CHALLENGE; and, with AES-256, a read of size 200 of a 96-byte auth_key allocated by set_auth_key_response(). How it is reached. The reproducer is a minimal SMB 3.1.1 server on loopback - NTLMv2 with a password it knows, AES-GCM, one share that requires encryption (SHI1005_FLAGS_ENCRYPT_DATA, so that smb3_encryption_required() holds) - and a mount of it; it makes the client reconnect by closing the server's side of the connection, and calls the ioctl on a file of the mount at the wrong moment: 1. AES-256-GCM. The mount's CHALLENGE carries 108 bytes of target info, so auth_key.len is 200. CIFS_DUMP_FULL_KEY reads that length, then stops in copy_to_user() of its header on a page write-protected with userfaultfd; the client reconnects, the new CHALLENGE carries 4 bytes of target info and auth_key becomes a 96-byte buffer; the write protection is lifted and the ioctl copies 200 bytes from that buffer: BUG: KASAN: slab-out-of-bounds in _copy_to_user+0xad/0xd0 Read of size 200 at addr ffff88802476bd80 by task poc/9454 _copy_to_user+0xad/0xd0 lib/usercopy.c:24 cifs_dump_full_key fs/smb/client/ioctl.c:497 [inline] cifs_ioctl+0x1ec1/0x2660 fs/smb/client/ioctl.c:643 __x64_sys_ioctl+0x121/0x170 fs/ioctl.c:598 Allocated by task 3131: __kmalloc_noprof+0x357/0x810 mm/slub.c:5556 set_auth_key_response fs/smb/client/cifsencrypt.c:354 [inline] setup_ntlmv2_rsp+0x546/0xb60 fs/smb/client/cifsencrypt.c:429 build_ntlmssp_auth_blob+0x2a/0x780 fs/smb/client/sess.c:929 SMB2_sess_auth_rawntlmssp_authenticate+0x293/0x460 fs/smb/client/smb2pdu.c:1969 SMB2_sess_setup+0x1b4/0x470 fs/smb/client/smb2pdu.c:2087 cifs_setup_session+0x49d/0xaf0 fs/smb/client/connect.c:4240 smb2_reconnect.part.0+0x70e/0x18b0 fs/smb/client/smb2pdu.c:411 smb2_reconnect_server+0x71a/0x1100 fs/smb/client/smb2pdu.c:4450 The buggy address belongs to the object at ffff88802476bd80 which belongs to the cache kmalloc-96 of size 96 The buggy address is located 0 bytes inside of allocated 96-byte region [ffff88802476bd80, ffff88802476bde0) The ioctl returns 0 with session_key_length 200: bytes 16-95 of the key are the NTLMv2 response the server received in the reconnect, bytes 96-199 are what follows the buffer. 2. AES-128-GCM. The server refuses the reconnect's SESSION_SETUP (STATUS_ACCESS_DENIED), which leaves auth_key.response NULL until a session setup succeeds, and CIFS_DUMP_FULL_KEY copies 16 bytes from it: BUG: KASAN: null-ptr-deref in _copy_to_user+0xad/0xd0 Read of size 16 at addr 0000000000000000 by task poc/9449 _copy_to_user+0xad/0xd0 lib/usercopy.c:24 cifs_dump_full_key fs/smb/client/ioctl.c:497 [inline] cifs_ioctl+0x1ec1/0x2660 fs/smb/client/ioctl.c:643 after which the copy faults and the ioctl fails with EINVAL. CIFS_DUMP_KEY in the same state gives "null-ptr-deref in cifs_ioctl+0x1594/0x2660", from __asan_memcpy() at ioctl.c:612. 3. AES-128-GCM, 4 bytes of target info in every CHALLENGE, the server dropping the connection a few requests after every session setup, one thread stat()ing so that the client reconnects and another looping CIFS_DUMP_FULL_KEY: the 7.4-rc5 report above, read of size 16 of a 4-byte object allocated by decode_ntlmssp_challenge(), alongside null-ptr-deref reads as in 2. This one is a race. Impact - who can trigger it: - Only root issues the ioctls. Both check capable(CAP_SYS_ADMIN) (ioctl.c:600 and 649), in the initial user namespace, and mounting cifs needs the same. They are debugging interfaces, for decrypting captures of an encrypted share, and what they read goes to the caller's buffer. - The windows are opened by session setup, which every reconnect runs, so they are there whatever the server: a dump that lands in one reads from NULL, from the target info or from a buffer freed under it, and after a re-setup that failed before the CHALLENGE - refused, as here, or a sec=krb5 one, since SMB2_auth_kerberos() frees auth_key on any error (smb2pdu.c:1830; we did not test krb5) - auth_key.response stays NULL until a setup succeeds. A malicious server controls how far the reads go: the length of its target info (MS-NLMP has a server put at least its NetBIOS computer and domain names there, so a short one is the server's choice; a 16-byte read runs 16 - tilen bytes past it), whether key exchange is negotiated (with it auth_key.len ends up 16, without it the length of the NTLMv2 response, which grows with the target info, so an AES-256 length of up to 255 - session_key_length is a u8 - can go stale), and when the client has to set the session up again. - What the reads do. A stale AES-256 length copies past the end of the new auth_key into the caller's buffer: 104 bytes past a 96-byte object here, which in our runs held direct-map addresses, the address of module_ktype (this config has no KASLR) and pieces of strings: a sysfs device path, a udev rules file name. An AES-128 dump during the target-info window copies 16 - tilen bytes past it, 12 in the fuzzer's run. From NULL, CIFS_DUMP_FULL_KEY's copy_to_user() faults and the ioctl fails with EINVAL; CIFS_DUMP_KEY's memcpy() reads address 0, which without KASAN should oops (we have not run such a kernel) - with KASAN the copy is skipped after the report and the ioctl returned 0 with 16 bytes of uninitialised stack as the session key. - There is also a use-after-free. copy_to_user() can sleep in a fault on the user buffer half way through, and nothing keeps the buffer it copies from alive meanwhile. With the second part of the user buffer on a page userfaultfd had not filled, the copy stopped 64 bytes into a 200-byte AES-256 key, the reconnect (with the same target info, so the same length) freed auth_key.response, and the copy went on in the freed buffer: 116 of the remaining 136 bytes came back different from the key, every one of them zero, since kfree_sensitive() clears what it frees. KASAN checks the source range before the copy and reported nothing. Whether the freed buffer can be reallocated before the copy goes on we did not try. Seen on 7.4.0-rc5 and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04), whose fs/smb/client is identical to mainline (c3500c5ef648, 2026-12-04), with KASAN: the stale AES-256 length gave the report in 1. in 4 of 4 boots; the refused re-setup gave the null-ptr-deref read in 3 of 3 boots with each ioctl; the held copy read the freed buffer in 3 of 3 (from the bytes; no KASAN report); and the looped dumps gave the 7.4-rc5 report, 5 and 19 times, in 2 of the 3 boots we ran them in - the third, with an earlier version of the program, set the session up only twice - besides null-ptr-deref reads in all 3. The code is the same in cifs-next (9b62aa64ed00, 2026-12-03). CIFS_DUMP_KEY has copied 16 bytes from auth_key.response without a lock since it was added in 7e7db86c7e10 ("smb3: allow decryption keys to be dumped by admin for debugging"), v5.4, and CIFS_DUMP_FULL_KEY since aa22ebc3826b ("smb3.1.1: allow dumping GCM256 keys to improve debugging of encrypted shares"), v5.13; 1bb56810677f ("cifs: change format of CIFS_FULL_KEY_DUMP ioctl"), also v5.13, gave it the copy_to_user() above, and 5be7a0cef322 ("smb: client: Use FullSessionKey for AES-256 encryption key derivation"), v7.1, made the AES-256 length auth_key.len, which is where a stale length comes from. A patch follows in reply to this mail. It takes the keys under session_mutex, which every caller of cifs_setup_session() holds, into a buffer on the stack; refuses the dump with EAGAIN when auth_key.response is NULL - whatever auth_key.len says, since a channel-binding setup whose kmemdup() of the target info fails leaves the old length beside a NULL pointer (sess.c:722-726) - or shorter than the length to be reported; and copies the buffer to user space after dropping the mutex. A dump that comes during a session setup now waits for it. On ksmbd-for-next, same config and image, the patch the only change between the two builds: without the patch the reports above, and the held copy reading the freed buffer with the patch in each of 3 boots, which ran every case once: the held dumps return the keys as the ioctl first found them (all 200 bytes the mount's), both ioctls fail with EAGAIN after the refused re-setup, and the looped dumps all return a key, over 529, 582 and 563 session setups; no KASAN report and no lockdep report both with the connection left alone, or the re-setup accepted, the dumps return the session's current keys; the 16-byte session keys equal the one the server derived 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 a minimal SMB server and the mount in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia