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=1796501582; b=iqRSxdGFF7T49hHhCn1zpFKr7mT0qc/wuHYcIiI8ES0R3xXqydX3S8tW85blV3NoQN8f efJeDTQuT/W4/luBWN49N7r69K/0WQEHBqrgU/SbhoTZgiDXD6tyia3SS9Fhyt+20ryh2 8DMZ3/pQAJA/k+GEpge6wBVcxKfCPMmKhueIHcT2S0Mq4TGD285Np8JzlGbX9IWZrYIOp yJsipmGNcLtem1m91NI1WN3NF1q1n6okkqa4yAjoQS0hkEqaY5zCi0V4sOtYCS+tQjcRC 4EYYFeJ5cyaG2OPNDHYN7ic3tbCAGCzuMNnW1TaSwy9g5+4BTNE48Eg20bpWCz594FA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796501582; 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=PJQJp5Cm5hCz6P39vjkqv+74xO2o+iUkzaPmm6ZDK6o=; b=5Iq61gILWOEJxheWGHz5vd3Bp/7TLQLFEEqvq/3iAHBZKvLgTi3o/CGfxj0TB6BkKXph Rl9iLFWwN3BdiNviPu0NDk5NFjmjrxEfamLTn2trd7EyN0Q05DH7SJi8rSUkRO+SZpMsV vJOYgUKYzY29xfhj/+W0PAJb3uSjVmorPO3i/1GY2nX+44BfxfZU4eJhR0LkqDLQ3Wioo AqvbuPk4marjWf932a1Dbruag0tEk63Afb8X702tAkAXwd2sGgJThzGLn/I29lGavibte KHaGocr5AnJ0hG+tCgZGHfiuKgVKOB90NOiGqFuzEonXc/uEwB6HQUw1ro6J+tkqEIw== 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=gbniE0HK; 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 589A3606A31F for ; Sat, 5 Dec 2026 20:13:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 589A3606A31F 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=gbniE0HK Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b5e3f5d4b7so183743c88.0 for ; Sat, 05 Dec 2026 12:13:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796501580; x=1797106380; 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=PJQJp5Cm5hCz6P39vjkqv+74xO2o+iUkzaPmm6ZDK6o=; b=gbniE0HKoHhw12+D2j0VHu3+RWgbnaZlQ5ENbN59VNtAlNHKTSnuK4n7KOPa3ydur+ W3cZg8HkJAFUDqgT0hEQkJE4nEK/KuyAxLt4Eeof/xSNj490j9fd7yjnPbC6k/QOa7gn 0MPsoonmAeMUgCTr6y1KSu8UWt1F0F38Fjdf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796501580; x=1797106380; 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=PJQJp5Cm5hCz6P39vjkqv+74xO2o+iUkzaPmm6ZDK6o=; b=yiRym6IaIkQl9qdORKNn9Ra92VJJS8haH5PL3KpZBSGXBu5ioar1QqKsrSMuDuDd0g +d+SW3RGFkyTqnfHuBUkzHH/hLXjkC3f6DReT+CMQoEVBhZuV0/6gN9tHjTuJXIv6LwH Wxkb/i62XWtC1wjmuoDVMruTdOZ39UdsTXbUR+WEpiTJ6xiv6fw8vmudN+gFfMFp7urq 5361eAAsltYIDUZtKvlSLtdct894rrKmo7Ms4IEzwahKhB9bxwDTuccV1fofaEumXlNO Nuy+87nnPrE2fl8y4/x7cpCwSVAWUgV/rXMZ2YRHyrt1CZMuc2DtQ4/LDjDqIgTjbM2U s9kg== X-Forwarded-Encrypted: i=1; AL+hErH/BtAOems8DdMqNvhGaAxofmMHtzuCSy6JIKwS1UGdi/vBYYwEb+0eGnMn1J5Qvqfo3nXRSWgk9HQsbro=@vger.kernel.org X-Gm-Message-State: APuU4Z+7sLSdjBrpxGoQz1trZg0FHxt15Di1pVkQT9qKbcKwmM65aDlh p+4JjHN/4pvRCW31Na24rRskWSUuVWcFwJaNmwQxwavcasen1So84mWmZGkBdxXIQdc= X-Gm-Gg: AZFdTZdJ+yM1aUY1UvALV5uZQgKsopApDBmF2WTwzm5AKp/jpImGPOyXEND+TuC8TVn JfPwq8FD2Oqf3m6cIaj4MrEm9b8OeJShJQTAaIqW/hhsJwYh5i18irrnSnKVH53f2fotfpjEf05 6qXxS/d72caZxbSjqUYHClaiwxlt+f7MU7xlyum3wg3NbuMS7YhJbOiKApXEvXxQz7N+TcVKS1W DngvVhNbd/KNXmYLmna5GslpUmb+7LZwpH8eX2fhNmZimQ3VsiAY1mwgfxufb6OeAL7JUfWbjHC oKn048nQ9kyROFn8WbCi7b7o0WMNwZDGZxeJYXccUnAdkxNKtJAKhcLweyrV2adeftaFtAyfKYq XvQeY6nZK8lEFcNFdkyEyaRY0hY4ESDqUBE/v+cP6ZnkrRXyEWI0BxStJ1zliUBCIIft+KT9S2D 3xybbCVqNxz/fiobRa7EccOIFFuutGl0cclbJXAuIOcIsRmXrOEOTGZPDgB2NFRguryau6t5jDo v7HYBtS+EThS7BrdavdgIeR1C3xYcYcCzXkOsPNx9Qm2vBIBy5aIrqWwqbGjZ0DQhDnvLHFglKH CFC+ObBr8ZOfikifKMvbslrB3KB5cYjNw6+eLSJfXI3BPkEYOtrqhdn80gBmlR/d8GkwbOTK6sj ya1frICWlxse2q4JrUQc+KXchSZGu8qvbObDgNyyEUPIK7JptxNHjQ3+kbXJqMXl1 X-Received: by 2002:a05:701b:2610:b0:19d:233:989d with SMTP id a92af1059eb24-1b5d70fa9d4mr4966430c88.14.1796501580023; Sat, 05 Dec 2026 12:13:00 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6451976sm17914575c88.10.2026.12.05.12.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 12:12:59 -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 CIFSSMBSetCIFSACL() on chmod Date: Sun, 6 Dec 2026 01:42:53 +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, With the cifsacl (or modefromsid) mount option, chmod() reads the file's security descriptor from the server, builds a new one from it and sends that back. On SMB1 the sending is CIFSSMBSetCIFSACL(), which copies the descriptor into the request buffer without comparing its length with the buffer: fs/smb/client/cifssmb.c:3986 (CIFSSMBSetCIFSACL) if (pntsd && acllen) { memcpy((char *)pSMBr + data_offset, pntsd, acllen); The buffer comes from cifs_buf_get() (smb_init(), cifssmb.c:3955) and is CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes, 16588 by default; data_offset is 84, so it holds 16504 bytes of descriptor. Nothing keeps the descriptor that small. id_mode_to_cifs_acl() sizes it from the server's: fs/smb/client/cifsacl.c:1841 (id_mode_to_cifs_acl) else /* cifsacl */ nsecdesclen += secdesclen + 5 * sizeof(struct smb_ace); and set_chmod_dacl() copies every ACE of the server's DACL that is not for the owner, the group, Everyone, Authenticated Users or the NFS mode SID, and adds up to five ACEs for the new mode between the explicit and the inherited ones (cifsacl.c:1286-1329). So the descriptor that goes back is longer than the one that came in. Here the server's descriptor is 16352 bytes - an owner and a group SID of 15 sub-authorities and 213 ACCESS_ALLOWED ACEs of 76 bytes, each for a SID of its own - and chmod(file, 0640) adds an owner, a group and an Everyone ACE, 172 bytes: BUG: KASAN: slab-out-of-bounds in CIFSSMBSetCIFSACL (fs/smb/client/cifssmb.c:3986) Write of size 16524 at addr ffff888049550054 by task poc/9447 __asan_memcpy (mm/kasan/shadow.c:106) CIFSSMBSetCIFSACL (fs/smb/client/cifssmb.c:3986) set_cifs_acl (fs/smb/client/cifsacl.c:1723) 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) do_fchmodat (fs/open.c:731) __x64_sys_chmod (fs/open.c:755 fs/open.c:753 fs/open.c:753) do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89) Allocated by task 9447: ... mempool_alloc_noprof (mm/mempool.c:572) cifs_buf_get (fs/smb/client/misc.c:202) smb_init (fs/smb/client/cifssmb.c:288 fs/smb/client/cifssmb.c:320) CIFSSMBSetCIFSACL (fs/smb/client/cifssmb.c:3955) set_cifs_acl (fs/smb/client/cifsacl.c:1723) id_mode_to_cifs_acl (fs/smb/client/cifsacl.c:1903) The buggy address belongs to the object at ffff888049550000 which belongs to the cache cifs_request of size 16588 The buggy address is located 84 bytes inside of allocated 16588-byte region [ffff888049550000, ffff8880495540cc) That copy ends 20 bytes past the object. chmod(file, 0007) makes populate_new_aces() add a DENY ACE for the owner and one for the group as well, five in all: a 16676-byte copy, ending 172 bytes past it. The request is never sent. SendReceive() refuses one longer than CIFSMaxBufSize + MAX_CIFS_HDR_SIZE bytes (smb1transport.c:251): CIFS: VFS: \\127.0.0.1 Invalid length, greater than maximum frame, 16608 and chmod() fails with EIO - but that check comes after the copy. How it is reached. The reproducer runs a minimal SMB1 server on loopback (NT LM 0.12 with extended security; NTLMSSP accepted unchecked) whose files all have the descriptor above, mounts it with vers=1.0,cifsacl and calls chmod() on a file. With 10 ACEs instead of 213 (a 924-byte descriptor) the same chmod(0640) works: the server receives a 1096-byte descriptor, chmod() returns 0, no report. The other way into CIFSSMBSetCIFSACL(), setxattr of system.cifs_acl and the related names, is bounded: cifs_xattr_set() refuses a value larger than CIFSMaxBufSize (xattr.c:127), which fits. chown() on such a mount also builds its descriptor from the server's DACL in id_mode_to_cifs_acl(); we did not try it. Impact - who can trigger it: - The length comes from the server, as the size of the descriptor it returns for the file. Nothing in ours is malformed: it is a self-relative descriptor with an owner, a group and a DACL, the client parses it and maps it to a mode without complaint, and the 213 ACEs are ordinary ones. So it takes a malicious server, or a file whose ACL has enough ACEs that the descriptor nearly fills a response; we have not tried a Windows or Samba server and do not know how such a server answers for an ACL that size. - On the client it takes chmod(2) of that file on an SMB1 mount with cifsacl or modefromsid. The mount needs CAP_SYS_ADMIN in the initial user namespace and vers=1.0 (SMB1 is only negotiated when asked for, and needs CONFIG_CIFS_ALLOW_INSECURE_LEGACY). chmod(2) needs the caller to own the file as the client sees it: with cifsacl the uid comes from the owner SID, or is the mount's uid= when the SID does not map, as ours did not. We ran as root. - What the write does. KASAN reports the copy and skips it (__asan_memcpy() returns without copying), so our runs show its size and place, not its effect. Without KASAN the copy is done and the request then refused: the end of the descriptor the client built is written past the 16588-byte object, 20 bytes in the first run above and 172 with chmod 0007. The server's descriptor has to arrive in one response of at most CIFSMaxBufSize + MAX_CIFS_HDR_SIZE bytes (connect.c:1200) and chmod adds at most five ACEs, so from the code the overrun is at most a few hundred bytes. In our runs the bytes written past the end are the new ACEs, made from the server's owner and group SIDs and the mode; set_chmod_dacl() puts the server's inherited ACEs after the new ones (cifsacl.c:1290-1298), so a server that sends inherited ACEs chooses those bytes - their type, flags, mask and SID. We did not run that, and 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 16352-byte descriptor and the same write was reported at the same lines (twice), and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04), whose fs/smb/client is identical to mainline (c3500c5ef648, 2026-12-04), with KASAN: chmod 0640 gave the report above in 3 of 3 boots (and the hunt's own program in 1 of 1), chmod 0007 the 16676-byte write in 1 of 1, and the 924-byte control none. CIFSSMBSetCIFSACL(), id_mode_to_cifs_acl() and set_chmod_dacl() are the same in cifs-next (9b62aa64ed00, 2026-12-03). The copy has been unbounded since CIFSSMBSetCIFSACL() was added in 97837582bc1e ("[CIFS] Allow setting mode via cifs acl"), v2.6.25, but until v5.12 chmod sent back a descriptor of the length it had received. f5065508897a ("cifs: Retain old ACEs when converting between mode bits and ACL."), v5.12, made it keep the server's ACEs and add new ones. 0ee150794c75 and a377a3645c7d have since fixed the size of the buffer that descriptor is built in, not of the request it is copied to. A patch follows in reply to this mail. It refuses, with -E2BIG and before the copy, a descriptor that would make the request longer than SendReceive() sends, which also keeps the copy inside the buffer; that is CIFSMaxBufSize bytes of descriptor. CIFSSMBSetPosixACL() refuses a POSIX ACL that does not fit the same way (cifssmb.c:3610-3614). A request that size could never be sent, so nothing that works now is refused. On ksmbd-for-next, same config and image, the patch the only change between the two builds: without the patch the reports above; chmod() fails with EIO with the patch no report in 4 boots (chmod 0640 3 times, 0007 once); no SET_SECURITY_DESC is sent and chmod() fails with E2BIG both the 924-byte control: the server receives the 1096-byte descriptor and chmod() returns 0 The SMB2 side has the same problem in SMB2_set_info_init(), which set_smb2_acl() uses to send the same descriptor; we report that, with a large EA that reaches the same copy, in a separate mail ("[BUG] smb: client: slab-out-of-bounds write in SMB2_set_info_init()"), with its own patch. 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 SMB1 server and the mount in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia