From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796501665; b=jj/zXhTZsiEZ2fzaKp3S88x7PuWyWmvZA4cfbywLvZvWzvfkhu9HIzJaqcln/w5xi6Vk 8HuXKW8ZeSR7vRN8jqZRz9Ekv35c+8NJOxExQVE0CMw0LJ2RRWJIqQeKkODcADIhcLuXf 13MHHc5j1dJbrtlrz7oBN9OaJxFDOQIF8cHKlLnJqY088o6NXo2EQwgvcbO5mdXMs16Wg iJRbCxVUy/z+Pou+tR67SckY57SKvn7LxkCkMGP1z1Bq+aPIx9t/0Zw67sDrKG5z0gxHt zIvcUlg5WCMJpRqxhqVYjRoO9ANMWScUZvPZ4x9JUdK8FtSa4CE6dUrlF4dYON4tnRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796501665; 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=xTLUOmT3FDhnLgv+0YrhXmXg8wx1jHfLjMrFeLjt/40=; b=HrWKSFweMbRfDsQgOaCo8BgaJUBjB4BWqnE2r00sdZYLk8yAUR+VdK2LFYaWY6UJQ/8V 2QzelaQMP/NomHeOkg36sPi9Pq+Bt22bhx+sVzKE8buUB4j9RDaFUh0tn2qYFYr8/IDg2 8VW0El/wP6iFnsU0vdj3X//6DX7hgQhMCCYb+jZBOvEnPUAWdOTX6UrwYobjfngH855s6 SU66XtFQEdwMIxLnV54x3qGWOjvRS0gfD4l9cn4cKryTBKOCQ6J1ObfGnqAWHHuIKw4Nu G0NevnDfctzDEEvRS6aehOj38fi6ICIykVNwMWh9K1QUQeZc1js7CaC0yIJY6zOmgrA== 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=KcfoMTej; arc=none smtp.remote-ip=74.125.82.175 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (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 C46B6606A32F for ; Sat, 5 Dec 2026 20:14:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C46B6606A32F 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=KcfoMTej Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-38747f42472so3363720eec.0 for ; Sat, 05 Dec 2026 12:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796501664; x=1797106464; 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=xTLUOmT3FDhnLgv+0YrhXmXg8wx1jHfLjMrFeLjt/40=; b=KcfoMTejqpp0sXq4EnR7UHvf+3lG5L3SIeo1it4Dw7wmomXktyNV318Xc1yhlk2euc C5g8ggj9WKd2+6F0/cmOTO46oGZTOQskhXCfpcQ+evD7IKm22LQM57wFs58QtmJSLSb6 VFbeEf7Nnbnknh9KmWysvW7SQFg6HTlze64xE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796501664; x=1797106464; 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=xTLUOmT3FDhnLgv+0YrhXmXg8wx1jHfLjMrFeLjt/40=; b=ulsTIwslA7hOw3pxGD1U9mlqS69JaHQb1G2a38kTGhetJERobxsT9BY60UNhEr4fTC TJmFM5bkMdEhSxhq7cXOsE6K4ZTQ6Pxv1HZrYPbD297cm9CevPGFWn3rBpfTM2nOeO6F UTLKjn9Sv9yWR/etdYY25tdix2kHK9fi1Ow4/cgbZNfAZ9NFXDUivK/8E+f5cNnp6qJZ 5HczowDesq+8hb4hw9B8G4WDBuB2h5hI9Mv0HZ8HFTTWQcTry+m5BVqdvJdv0cXBJh2i HKFoxc3jnCyGLf2FezlfKW1L1O1B4LUfIDtmMGkhjykmRIFOls7CGi0a8LR81h6K1k2D Caqw== X-Forwarded-Encrypted: i=1; AL+hErF2Ye7Vr5ReAMTCWLNELdO0qqZkNY5OqD6rYt1qRIP44sQPynYkHO3wiOh4RfSGXhhjQ5VQfRJrJYHu6iw=@vger.kernel.org X-Gm-Message-State: APuU4Z/7LvRo5xKQpClqz2R++odywYmojO+DYuj+B0A6EPLr8xuYXy9U 8PWwZZERdQQVLHM73k1qYaU5JfePb59THOGN1bePya+MbjsNVuzDph2s6eKZfNRGq6zpi+Iguko 2UZjSnaO/FA== X-Gm-Gg: AZFdTZf2HQfpImYPfzJiBZiN+VAaqddDpOUaCejXrZ3+WMXjFjEuI5UK9GKSYY+MlKL BHKIdKtbtdpnUSVI4pQ7d2TjfmIUkH6KSWLJ1F2zbuTB5IwUCShIK2+gH2OJiATqFCF0v5DRTB0 pVLOWLtkYm9clbLXhPGw8JqrA84vAOSSs1nZ/O37xaVVdnVV3PkonSNsK1CW8IQl5qTrd9M9J2M kMBeShN6gUb2yOZMTLJEFtLV+yCmWhVfdW27fP0MCTUwpjuTA6YDhskjkTrxpr+qvYjBli4ihWh wDDdJcBuiimK1uJfnHkKLgbdOEcrqFgZOC6Jvyn4pdxSSKk2uu6rEASsZFxfre0dAL5/IU0QFhv uJ1eoAyEuIa33RUzx8+jsDij96X3u9YLeGTCdLTGORJD0orDt3k7DEMNlhodi9Th+JOtCCLljyK QHSf6anlLGTwpzkX7MlQ/4ZKNk7id4f1X2DlbF7r85fynn/wQuWtt3fEEpu5xPTcIdaTw67O0qY nGx5Q+arz3Ov85jiXEgbiQEleTOdCqETavlHFios+MiJ/cluU2mWHP7uTzLdbxgHz+rPOc06JMq wWkzSXA9EzxoIxSvdid6Eh6uCT6DVl4XezK0KD93wNAsCk0Sm3PiWJC5pl9/efuASSFoWrwqVza lIkR/u+GOPJKHCJNvTql2q5/BsQoVsNQ9mYVQNup1ysjUJPuTrA5Et+V2b52zGolw X-Received: by 2002:a05:693c:8951:10b0:387:702a:f166 with SMTP id 5a478bee46e88-387702af275mr1038674eec.18.1796501663720; Sat, 05 Dec 2026 12:14:23 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5c89sm35973382eec.18.2026.12.05.12.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 12:14:23 -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: slab-out-of-bounds write in SMB2_set_info_init() Date: Sun, 6 Dec 2026 01:44:17 +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, SMB2_set_info_init() copies the first data element of a SET_INFO request into the request buffer, after the fixed part of the request, without comparing its length with the buffer: fs/smb/client/smb2pdu.c:6000 (SMB2_set_info_init) req->BufferLength = cpu_to_le32(*size); memcpy(req->Buffer, *data, *size); The buffer comes from cifs_buf_get() (smb2_plain_req_init(), smb2pdu.c:5985) and is CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes, 16588 by default; req->Buffer is at offset 96, so it holds 16492 bytes. Two callers can pass more. 1. smb2_set_ea(), for setxattr() of a user.* attribute. cifs_xattr_set() lets a value of up to CIFSMaxBufSize (16384) bytes through (xattr.c:127) and smb2_set_ea() makes it a FILE_FULL_EA_INFORMATION of 8 + name + 1 + value bytes (smb2ops.c:1314): up to 16644, since the VFS allows 255 bytes for the whole name and os2.* is treated like user.*. The one limit on that is a check meant to keep the file's EAs readable, which first asks the server how many bytes of EAs the file has: fs/smb/client/smb2ops.c:1270 (smb2_set_ea) used_len = le32_to_cpu(rsp->OutputBufferLength); ... fs/smb/client/smb2ops.c:1280 if (CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 < used_len + ea_name_len + ea_value_len + 1) { rc = -ENOSPC; used_len is an int, and nothing holds the server's value to the data that came with it: smb2_get_data_area_len() logs a length that is negative as an int ("invalid data area (off=72 len=-16000)") and counts no data area (smb2misc.c:438-444), and smb2_check_message() accepts a response longer than that (smb2misc.c:339). With OutputBufferLength 0xFFFFC180 (-16000), a 250-character name and a 16384-byte value the right-hand side is 635, the check passes, and: BUG: KASAN: slab-out-of-bounds in SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000) Write of size 16643 at addr ffff8880436b0060 by task poc/9452 __asan_memcpy (mm/kasan/shadow.c:106) SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000) smb2_set_ea (fs/smb/client/smb2ops.c:1329) cifs_xattr_set (fs/smb/client/xattr.c:156) __vfs_setxattr (fs/xattr.c:223) ... __x64_sys_setxattr (fs/xattr.c:768 fs/xattr.c:764 fs/xattr.c:764) Allocated by task 9452: ... cifs_buf_get (fs/smb/client/misc.c:202) __smb2_plain_req_init (fs/smb/client/smb2pdu.c:591) SMB2_set_info_init (fs/smb/client/smb2pdu.c:625 fs/smb/client/smb2pdu.c:5985) smb2_set_ea (fs/smb/client/smb2ops.c:1329) The buggy address belongs to the object at ffff8880436b0000 which belongs to the cache cifs_request of size 16588 The buggy address is located 96 bytes inside of allocated 16588-byte region [ffff8880436b0000, ffff8880436b40cc) 151 bytes past the object. The check is the only bound: it runs whenever a value is set (query_all_EAs is set in every SMB2 operations table next to set_EA), with used_len 0 if the query fails, and with a used_len between 0 and 2^31 it does keep the EA (at most 15132 bytes) inside the buffer. 2. set_smb2_acl() -> SMB2_set_acl() -> send_set_info(), for chmod() on a cifsacl or modefromsid mount. As on SMB1, where we report the same thing in CIFSSMBSetCIFSACL() separately ("[BUG] smb: client: slab-out-of-bounds write in CIFSSMBSetCIFSACL() on chmod"), id_mode_to_cifs_acl() builds the descriptor from the server's: set_chmod_dacl() keeps the server's ACEs other than those for the owner, the group and three well-known SIDs, and adds up to five for the new mode (cifsacl.c:1286-1329), so it goes back longer than it came in. On SMB2 the server's descriptor alone may already be too long: a response of up to CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes is accepted (connect.c:1200), which leaves 16516 bytes for it. With a well-formed 16504-byte descriptor (an owner and a group SID of 15 sub-authorities and 215 ACCESS_ALLOWED ACEs of 76 bytes) chmod(file, 0640) adds 172 bytes: BUG: KASAN: slab-out-of-bounds in SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000) Write of size 16676 at addr ffff888043750060 by task poc/9458 __asan_memcpy (mm/kasan/shadow.c:106) SMB2_set_info_init (fs/smb/client/smb2pdu.c:6000) send_set_info (fs/smb/client/smb2pdu.c:6062) SMB2_set_acl (fs/smb/client/smb2pdu.c:6144) set_smb2_acl (fs/smb/client/smb2ops.c:3479) id_mode_to_cifs_acl (fs/smb/client/cifsacl.c:1903) cifs_setattr (fs/smb/client/inode.c:3490 fs/smb/client/inode.c:3592) notify_change (fs/attr.c:556) chmod_common (fs/open.c:686) ... The buggy address is located 96 bytes inside of allocated 16588-byte region [ffff888043750000, ffff8880437540cc) 184 bytes past the object. KASAN skips a copy it reports (__asan_memcpy() returns without copying), and on SMB2 nothing else stops the request: in both cases our server received the SET_INFO, with BufferLength 16643 and 16676, and setxattr() and chmod() returned 0. The other callers of SMB2_set_info_init() pass data of a fixed size (disposition, end of file, basic, rename and link information - the new name goes in an iov of its own - and the set-info passthrough's 8 bytes), and setxattr() of system.cifs_acl and the related names passes a descriptor of at most CIFSMaxBufSize bytes (xattr.c:127), which fits. How it is reached. The reproducer runs a minimal SMB 3.0 server on loopback (NTLMSSP accepted unchecked) and mounts it. For the EA, the server answers the FILE_FULL_EA_INFORMATION query with OutputBufferLength 0xFFFFC180 over 16 bytes of data, and the program sets user.<250 x 'a'> to a 16384-byte value; for the descriptor it mounts with cifsacl and calls chmod() on a file. The controls: when the server reports the 16 bytes of EAs it really sends, the same setxattr() fails with ENOSPC from the check above and no SET_INFO is built; with 10 ACEs (a 924-byte descriptor) the chmod() works - the server receives a 1096-byte descriptor and chmod() returns 0. Neither gives a report. Impact - who can trigger it: - The EA write needs two parties. The server has to answer the EA query with an OutputBufferLength of 2^31 or more that makes the sum wrap; an honest server does not, but one value covers every EA large enough to overflow (-16000 wraps for anything from 16000 to 31124 bytes). And someone on the client has to set a user.* attribute whose name and value come to more than 16484 bytes - with the 16384-byte maximum value, a name of 100 characters or more. That needs write permission to the file as the client sees it, no privilege, on any SMB2/3 mount that has not turned user xattrs off (nouser_xattr). The bytes written past the buffer are the end of that caller's value. - The descriptor write needs a server descriptor that nearly fills a response, which need not be malformed - ours is not - and chmod(2) of that file by its owner (as the client sees it) on an SMB2/3 mount with cifsacl or modefromsid. As on SMB1, the bytes written past the buffer are the end of the descriptor the client built: the new ACEs in our runs, or the server's inherited ACEs, which set_chmod_dacl() puts after them. We have not tried a Windows or Samba server and do not know how one answers for an ACL that size. - Mounting needs CAP_SYS_ADMIN in the initial user namespace. We ran everything as root. - What the write does: without KASAN the copy is done and the request is sent. With the default CIFSMaxBufSize the EA can end at most 152 bytes past the object (from the code: a 251-character os2.* name); we measured 151, and 184 for the descriptor. We did not establish what lies past a cifs_request object on a production kernel, which depends on the slab layout and so on CIFSMaxBufSize. Seen on 7.4.0-rc5, where the fuzzer's server sent the same EA answer and the same 16643-byte write was reported at the same lines (twice); the descriptor path we found while writing this up. REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04), whose fs/smb/client is identical to mainline (c3500c5ef648, 2026-12-04), with KASAN: the EA gave the first report above in 3 of 3 boots (and the hunt's own program in 1 of 1), the descriptor the second in 3 of 3, and the controls none. SMB2_set_info_init(), smb2_set_ea() and set_smb2_acl() are the same in cifs-next (9b62aa64ed00, 2026-12-03). History. SET_INFO data first went into a 448-byte small buffer, and the first caller with data of a variable size, 366ed846df60 ("cifs: Use smb 2 - 3 and cifsacl mount options setacl function"), v4.13, overflowed it with security descriptors; f46ecbd97f50 ("cifs: Fix slab-out-of-bounds in send_set_info() on SMB2 ACE setting"), v4.18, moved SET_INFO to the large buffer, without a bound. smb2_set_ea() came in 5517554e4313 ("cifs: Add support for writing attributes on SMB2+"), v4.14, with no limit; 63d37fb4ce5a ("CIFS: fix max ea value size"), v5.4, capped the value at CIFSMaxBufSize for this copy, but not the name and the header; the check above came in 85db6b7ae65f ("cifs: make sure we do not overflow the max EA buffer size"), v5.6, for the EAs' sake, and bounds the copy only while used_len is not negative. f5065508897a ("cifs: Retain old ACEs when converting between mode bits and ACL."), v5.12, made the chmod descriptor grow. 33eae65c6f49 ("smb: client: fix OOB in SMB2_query_info_init()"), v6.7, fixed the same kind of overflow in SMB2_query_info_init() by checking the length there. A patch follows in reply to this mail. Like 33eae65c6f49, it checks the length where the copy is, so that it holds for both callers: data longer than CIFSMaxBufSize is refused with -E2BIG before the buffer is allocated. CIFSMaxBufSize rather than the 16492 bytes that fit leaves room for the padding smb2_set_next_command() writes into the buffer of an encrypted compound (smb2_set_ea()'s is one), and it is the limit setxattr() already puts on a descriptor and that SMB1 has (SendReceive()). A descriptor of 16385 to 16492 bytes, which chmod() on SMB2 could send before, is refused too. smb2_set_ea()'s check still accepts a negative used_len, but with the patch that can only let through an EA that fits the request, so we left it alone. On ksmbd-for-next, same config and image, the patch the only change between the two builds: without the patch the reports above; setxattr() and chmod() return 0 with the patch no report in 6 boots (the EA 3 times, the descriptor 3 times); no SET_INFO is sent and setxattr() and chmod() fail with E2BIG both the controls: setxattr() fails with ENOSPC, the 924-byte-descriptor chmod() returns 0 and the server receives the 1096-byte descriptor 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 3.0 server and the mount in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia