FAILED: patch "[PATCH] smb: client: fail DACL rewrite when the new DACL exceeds 64K" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x d05045177a855386bca5e1909e08d06290e6e3b3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026091603-giddily-overstate-4978@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d05045177a855386bca5e1909e08d06290e6e3b3 Mon Sep 17 00:00:00 2001
From: Bjoern Doebel <[email protected]>
Date: Tue, 8 Sep 2026 16:10:01 +0000
Subject: [PATCH] smb: client: fail DACL rewrite when the new DACL exceeds 64K
replace_sids_and_copy_aces() and set_chmod_dacl() accumulate the size of the DACL they build in a u16. That accumulator can wrap.
validate_dacl() caps num_aces at (dacl_size - sizeof(struct smb_acl)) / 20, i.e. 3276 for a maximally sized DACL, while each rewritten ACE can grow to sizeof(struct smb_ace) (76 bytes) once its SID is replaced with one carrying SID_MAX_SUB_AUTHORITIES sub-authorities. The worst case is therefore sizeof(struct smb_acl) + 3276 * 76 = 248984 bytes, far beyond what a u16 can hold. A wraparound is reached with 863 ACEs.
After the wraparound, ndacl_ptr->size becomes meaningless and the offset will point anywhere in the ACE array. As a result, we will see corruption of the DACL, which then gets sent to the server. This is not an out-of-bounds write as the allocation now covers the worst-case expansion, so writes will always go into the buffer.
Adjust the code to use a u32 internally and return -EOVERFLOW in the overflow case. The operation must be refused, because a DACL can only hold 2^16-1 bytes on the wire and larger DACLs cannot be represented.
set_chmod_dacl() carries the same pattern and is fixed the same way. It only wraps once the source DACL comes within roughly 380 bytes of the 64K ceiling, but the failure mode is identical.
fs/smb/client/cifsacl.c +26 -13
@@ -1096,13 +1096,13 @@ unsigned int setup_special_user_owner_ACE(struct smb_ace *pntace)static void populate_new_aces (char *nacl_base,struct smb_sid *pownersid,struct smb_sid *pgrpsid, -__u64 *pnmode,u16 *pnum_aces,u16 *pnsize, +__u64 *pnmode,u16 *pnum_aces,u32 *pnsize,bool modefromsid,bool posix) {__u64 nmode;u16 num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;__u64 user_mode;__u64 group_mode;__u64 other_mode;
@@ -1201,17 +1201,17 @@ static void populate_new_aces(char *nacl_base, *pnsize = nsize; } -static __u16 replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl, -struct smb_sid *pownersid,struct smb_sid *pgrpsid, -struct smb_sid *pnownersid,struct smb_sid *pngrpsid, -int *aclflag) +static int replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl, +struct smb_sid *pownersid,struct smb_sid *pgrpsid, +struct smb_sid *pnownersid,struct smb_sid *pngrpsid, +int *aclflag,u16 *pnsize) {int i;u16 size =0 ;struct smb_ace *pntace =NULL ;char *acl_base =NULL ;u16 src_num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;struct smb_ace *pnntace =NULL ;char *nacl_base =NULL ;u16 ace_size =0 ;
@@ -1240,9 +1240,12 @@ static __u16 replace_sids_and_copy_aces(struct smb_acl *pdacl, struct smb_acl *p size +=le16_to_cpu (pntace->size); nsize += ace_size; +if (nsize >U16_MAX ) +return -EOVERFLOW ; } -return nsize; + *pnsize = nsize; +return 0 ; } static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,
@@ -1254,7 +1257,7 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,struct smb_ace *pntace =NULL ;char *acl_base =NULL ;u16 src_num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;struct smb_ace *pnntace =NULL ;char *nacl_base =NULL ;u16 num_aces =0 ;
@@ -1305,6 +1308,8 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl, nsize +=cifs_copy_ace (pnntace, pntace,NULL ); num_aces++; +if (nsize >U16_MAX ) +return -EOVERFLOW ; next_ace: size +=le16_to_cpu (pntace->size);
@@ -1321,6 +1326,10 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl, } finalize_dacl: +/* The DACL size field is 16-bit on the wire, see MS-DTYP 2.4.5 */ +if (nsize >U16_MAX ) +return -EOVERFLOW ; + pndacl->num_aces =cpu_to_le16 (num_aces); pndacl->size =cpu_to_le16 (nsize);
@@ -1473,6 +1482,8 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd, rc =set_chmod_dacl (dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr, pnmode, mode_from_sid, posix); +if (rc) +return rc; sidsoffset = ndacloffset +le16_to_cpu (ndacl_ptr->size);/* copy the non-dacl portion of secdesc */
@@ -1548,10 +1559,12 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd,if (dacloffset) {/* Replace ACEs for old owner with new one */ - size =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, - owner_sid_ptr, group_sid_ptr, - nowner_sid_ptr, ngroup_sid_ptr, - aclflag); + rc =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, + owner_sid_ptr, group_sid_ptr, + nowner_sid_ptr, ngroup_sid_ptr, + aclflag, &size); +if (rc) + goto chown_chgrp_exit; ndacl_ptr->size =cpu_to_le16 (size); }
Sasha Levin
maintainerPATCH 1/3 smb: client: refactor ACL setting control flow in id_mode_to_cifs_acl()
From: Ralph Boehme <[email protected]>
[ Upstream commit a540a64c4801fe02e452ee37e961018106418260 ]
Refactor the control flow in id_mode_to_cifs_acl() to reduce nesting and prevent error code overwriting.
Instead of wrapping the call to ops->set_acl() in a conditional block, introduce early exits (goto id_mode_to_cifs_acl_exit) when build_sec_desc() fails or ops->set_acl is NULL. This ensures that any actual error returned by build_sec_desc() is not overwritten with -EOPNOTSUPP.
Stable-dep-of: d05045177a85 ("smb: client: fail DACL rewrite when the new DACL exceeds 64K")
--- fs/smb/client/cifsacl.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/smb/client/cifsacl.c +10 -6
@@ -1778,14 +1778,18 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,cifs_dbg (NOISY ,"build_sec_desc rc: %d\n" , rc); -if (ops->set_acl ==NULL ) - rc = -EOPNOTSUPP ; +if (rc !=0 ) + goto id_mode_to_cifs_acl_exit; -if (!rc) { -/* Set the security descriptor */ - rc = ops->set_acl (pnntsd, nsecdesclen, inode, path, aclflag); -cifs_dbg (NOISY ,"set_cifs_acl rc: %d\n" , rc); +if (ops->set_acl ==NULL ) { + rc = -EOPNOTSUPP ; + goto id_mode_to_cifs_acl_exit; } + +/* Set the security descriptor */ + rc = ops->set_acl (pnntsd, nsecdesclen, inode, path, aclflag); +cifs_dbg (NOISY ,"set_cifs_acl rc: %d\n" , rc); + id_mode_to_cifs_acl_exit:cifs_put_tlink (tlink);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 smb/client: fix security flag calculation when setting security descriptors
From: Ralph Boehme <[email protected]>
[ Upstream commit 4939889c985da68936090cc013e58c28b7bff34f ]
In id_mode_to_cifs_acl(), aclflag was initialized to CIFS_ACL_DACL by default. This forced the client to request setting the DACL even when only an ownership (chown) or group (chgrp) change was being performed.
Let build_sec_desc() do the proper flag calculation by initializing aclflag to 0. build_sec_desc() sets the appropriate bits (CIFS_ACL_OWNER, CIFS_ACL_GROUP, or CIFS_ACL_DACL) depending on what actually changed. During ownership transfer, CIFS_ACL_DACL is only set if replace_sids_and_copy_aces() actually replaces the SIDs inside any of the DACL's ACEs.
If build_sec_desc() results in aclflag being 0 (meaning no changes were mapped), exit early to avoid sending an empty security descriptor update to the server.
Stable-dep-of: d05045177a85 ("smb: client: fail DACL rewrite when the new DACL exceeds 64K")
--- fs/smb/client/cifsacl.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
fs/smb/client/cifsacl.c +16 -6
@@ -1113,7 +1113,8 @@ static void populate_new_aces(char *nacl_base,static __u16 replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl,struct smb_sid *pownersid,struct smb_sid *pgrpsid, -struct smb_sid *pnownersid,struct smb_sid *pngrpsid) +struct smb_sid *pnownersid,struct smb_sid *pngrpsid, +int *aclflag) {int i;u16 size =0 ;
@@ -1137,12 +1138,15 @@ static __u16 replace_sids_and_copy_aces(struct smb_acl *pdacl, struct smb_acl *p pntace = (struct smb_ace *) (acl_base + size); pnntace = (struct smb_ace *) (nacl_base + nsize); -if (pnownersid &&compare_sids (&pntace->sid, pownersid) ==0 ) +if (pnownersid &&compare_sids (&pntace->sid, pownersid) ==0 ) { ace_size =cifs_copy_ace (pnntace, pntace, pnownersid); -else if (pngrpsid &&compare_sids (&pntace->sid, pgrpsid) ==0 ) + *aclflag |=CIFS_ACL_DACL ; + }else if (pngrpsid &&compare_sids (&pntace->sid, pgrpsid) ==0 ) { ace_size =cifs_copy_ace (pnntace, pntace, pngrpsid); -else + *aclflag |=CIFS_ACL_DACL ; + }else { ace_size =cifs_copy_ace (pnntace, pntace,NULL ); + } size +=le16_to_cpu (pntace->size); nsize += ace_size;
@@ -1464,7 +1468,8 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd,/* Replace ACEs for old owner with new one */ size =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr, - nowner_sid_ptr, ngroup_sid_ptr); + nowner_sid_ptr, ngroup_sid_ptr, + aclflag); ndacl_ptr->size =cpu_to_le16 (size); }
@@ -1679,7 +1684,7 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode, kuid_t uid, kgid_t gid) { int rc = 0; -int aclflag =CIFS_ACL_DACL ;/* default flag to set */ +int aclflag =0 ;__u32 secdesclen =0 ;__u32 nsecdesclen =0 ;__u32 dacloffset =0 ;
@@ -1781,6 +1786,11 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,if (rc !=0 ) goto id_mode_to_cifs_acl_exit; +if (aclflag ==0 ) { +cifs_dbg (FYI ,"set_cifs_acl aclflag=0, no change mapped\n" ); + goto id_mode_to_cifs_acl_exit; + } +if (ops->set_acl ==NULL ) { rc = -EOPNOTSUPP ; goto id_mode_to_cifs_acl_exit;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 smb: client: fail DACL rewrite when the new DACL exceeds 64K
In reply to Sasha LevinFrom: Bjoern Doebel <[email protected]>
[ Upstream commit d05045177a855386bca5e1909e08d06290e6e3b3 ]
replace_sids_and_copy_aces() and set_chmod_dacl() accumulate the size of the DACL they build in a u16. That accumulator can wrap.
validate_dacl() caps num_aces at (dacl_size - sizeof(struct smb_acl)) / 20, i.e. 3276 for a maximally sized DACL, while each rewritten ACE can grow to sizeof(struct smb_ace) (76 bytes) once its SID is replaced with one carrying SID_MAX_SUB_AUTHORITIES sub-authorities. The worst case is therefore sizeof(struct smb_acl) + 3276 * 76 = 248984 bytes, far beyond what a u16 can hold. A wraparound is reached with 863 ACEs.
After the wraparound, ndacl_ptr->size becomes meaningless and the offset will point anywhere in the ACE array. As a result, we will see corruption of the DACL, which then gets sent to the server. This is not an out-of-bounds write as the allocation now covers the worst-case expansion, so writes will always go into the buffer.
Adjust the code to use a u32 internally and return -EOVERFLOW in the overflow case. The operation must be refused, because a DACL can only hold 2^16-1 bytes on the wire and larger DACLs cannot be represented.
set_chmod_dacl() carries the same pattern and is fixed the same way. It only wraps once the source DACL comes within roughly 380 bytes of the 64K ceiling, but the failure mode is identical.
--- fs/smb/client/cifsacl.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
fs/smb/client/cifsacl.c +26 -13
@@ -1006,13 +1006,13 @@ unsigned int setup_special_user_owner_ACE(struct smb_ace *pntace)static void populate_new_aces (char *nacl_base,struct smb_sid *pownersid,struct smb_sid *pgrpsid, -__u64 *pnmode,u16 *pnum_aces,u16 *pnsize, +__u64 *pnmode,u16 *pnum_aces,u32 *pnsize,bool modefromsid,bool posix) {__u64 nmode;u16 num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;__u64 user_mode;__u64 group_mode;__u64 other_mode;
@@ -1111,17 +1111,17 @@ static void populate_new_aces(char *nacl_base, *pnsize = nsize; } -static __u16 replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl, -struct smb_sid *pownersid,struct smb_sid *pgrpsid, -struct smb_sid *pnownersid,struct smb_sid *pngrpsid, -int *aclflag) +static int replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl, +struct smb_sid *pownersid,struct smb_sid *pgrpsid, +struct smb_sid *pnownersid,struct smb_sid *pngrpsid, +int *aclflag,u16 *pnsize) {int i;u16 size =0 ;struct smb_ace *pntace =NULL ;char *acl_base =NULL ;u16 src_num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;struct smb_ace *pnntace =NULL ;char *nacl_base =NULL ;u16 ace_size =0 ;
@@ -1150,9 +1150,12 @@ static __u16 replace_sids_and_copy_aces(struct smb_acl *pdacl, struct smb_acl *p size +=le16_to_cpu (pntace->size); nsize += ace_size; +if (nsize >U16_MAX ) +return -EOVERFLOW ; } -return nsize; + *pnsize = nsize; +return 0 ; } static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,
@@ -1164,7 +1167,7 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,struct smb_ace *pntace =NULL ;char *acl_base =NULL ;u16 src_num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;struct smb_ace *pnntace =NULL ;char *nacl_base =NULL ;u16 num_aces =0 ;
@@ -1215,6 +1218,8 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl, nsize +=cifs_copy_ace (pnntace, pntace,NULL ); num_aces++; +if (nsize >U16_MAX ) +return -EOVERFLOW ; next_ace: size +=le16_to_cpu (pntace->size);
@@ -1231,6 +1236,10 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl, } finalize_dacl: +/* The DACL size field is 16-bit on the wire, see MS-DTYP 2.4.5 */ +if (nsize >U16_MAX ) +return -EOVERFLOW ; + pndacl->num_aces =cpu_to_le16 (num_aces); pndacl->size =cpu_to_le16 (nsize);
@@ -1391,6 +1400,8 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd, rc =set_chmod_dacl (dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr, pnmode, mode_from_sid, posix); +if (rc) +return rc; sidsoffset = ndacloffset +le16_to_cpu (ndacl_ptr->size);/* copy the non-dacl portion of secdesc */
@@ -1466,10 +1477,12 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd,if (dacloffset) {/* Replace ACEs for old owner with new one */ - size =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, - owner_sid_ptr, group_sid_ptr, - nowner_sid_ptr, ngroup_sid_ptr, - aclflag); + rc =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, + owner_sid_ptr, group_sid_ptr, + nowner_sid_ptr, ngroup_sid_ptr, + aclflag, &size); +if (rc) + goto chown_chgrp_exit; ndacl_ptr->size =cpu_to_le16 (size); }
Signature · 1 line
2.53.0