FAILED: patch "[PATCH] ksmbd: grant a caller what its groups and OWNER RIGHTS ACEs" 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 42ac1f1917ae678ee2c47f415ab844af03bbd46b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112515-dock-lapel-1710@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 42ac1f1917ae678ee2c47f415ab844af03bbd46b Mon Sep 17 00:00:00 2001
From: Ian Bridges <[email protected]>
Date: Wed, 4 Nov 2026 12:58:04 -0600
Subject: [PATCH] ksmbd: grant a caller what its groups and OWNER RIGHTS ACEs
allow
smb_check_perm_dacl() does not match ACEs for the caller's Unix groups and refuses an owner named only by OWNER RIGHTS. These callers cannot use rights the DACL grants them under MS-DTYP 2.5.3.2.
Match Unix group SIDs (S-1-22-2) against the caller's credentials. Use the ordered DACL result when the existing SID lookup and POSIX ACL fallback do not decide access. In that result, deny ACEs for the caller's groups limit what it grants, also for MAXIMUM_ALLOWED. Count only the exact OWNER RIGHTS SID in that result, since compare_sids() also matches shorter and longer SIDs, and return only file access rights. Preserve the refusal for non-inherit-only object deny ACEs, which ksmbd does not parse.
MAXIMUM_ALLOWED still excludes group allow ACEs. Including them requires corresponding changes in smb2_open() to avoid breaking existing opens. An open relying on group grants can therefore still fail when it requests a maximal access reply. For the owner, that reply leaves out the rights of its groups.
fs/smb/server/smbacl.c +119 -47
@@ -1459,6 +1459,35 @@ bool smb_inherit_flags(int flags, bool is_dir)return false; } +/* Whether the caller's credentials hold the group of an S-1-22-2-<gid> SID */ +static bool smb_sid_in_group (const struct smb_sid *sid) +{ +gid_t gid; + +if (sid->num_subauth != sid_unix_groups.num_subauth +1 || +compare_sids (sid, &sid_unix_groups)) +return false; + gid =le32_to_cpu (sid->sub_auth[sid->num_subauth -1 ]); +/* +* ksmbd_override_fsids() builds the caller's credentials with +* make_kgid(&init_user_ns, ...), so the group membership test must +* compare in that space. Applying the mount idmap here (as when +* resolving a SID to an on-disk gid) would mismatch on idmapped +* mounts. +*/ +return in_group_p (make_kgid (&init_user_ns, gid)); +} + +/* +* compare_sids() compares only the sub-authorities both SIDs have, so it +* also matches a shorter or longer SID, such as S-1-3 or S-1-3-4-777 +*/ +static bool smb_sid_is_owner_rights (const struct smb_sid *sid) +{ +return sid->num_subauth == sid_owner_rights.num_subauth && + !compare_sids (sid, &sid_owner_rights); +} +int smb_check_perm_dacl (struct ksmbd_conn *conn,const struct path *path,__le32 *pdaccess,__le32 raw_daccess,int uid,bool strict)
@@ -1475,13 +1504,15 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,int granted = requested;struct smb_ace *ace;int i, found =0 ; -unsigned int access_bits =0 , denied =0 ; +unsigned int access_bits =0 , denied =0 , grp_granted =0 ; +unsigned int grp_allowed =0 , grp_denied =0 , bits;struct smb_ace *others_ace =NULL ; -bool or_ace = false; +bool or_ace = false, obj_deny = false, member, counted;struct posix_acl_entry *pa_entry;unsigned int sid_type =SIDOWNER ;unsigned short ace_size;bool is_owner, owner_rights = false; +bool maximal = *pdaccess &FILE_MAXIMAL_ACCESS_LE ;vfsuid_t vfsuid;ksmbd_debug (SMB ,"check permission using windows acl\n" );
@@ -1522,7 +1553,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,*/ if (is_owner) allowed =READ_CONTROL |WRITE_DAC ; -if (*pdaccess &FILE_MAXIMAL_ACCESS_LE ) +if (maximal) requested |= allowed;if (!allowed || requested & ~allowed) rc = -EACCES ;
@@ -1531,53 +1562,83 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, goto err_out; } -if (*pdaccess &FILE_MAXIMAL_ACCESS_LE ) { - ace = (struct smb_ace *)((char *)pdacl +sizeof (struct smb_acl )); - aces_size = pdacl_size -sizeof (struct smb_acl ); -for (i =0 ; i <le16_to_cpu (pdacl->num_aces); i++) { -if (aces_size < offsetof(struct smb_ace , sid) + -CIFS_SID_BASE_SIZE ) -break ; - ace_size =le16_to_cpu (ace->size); -if (ace_size > aces_size || - ace_size < offsetof(struct smb_ace , sid) + -CIFS_SID_BASE_SIZE ) -break ; - aces_size -= ace_size; +/* +* Evaluate the DACL in order (MS-DTYP 2.5.3.2). access_bits collects +* the MAXIMUM_ALLOWED result. grp_granted collects what ACEs for the +* caller's groups, or OWNER RIGHTS for the owner, grant. It is used +* when the SID lookup and POSIX ACL fallback below do not decide. +*/ + ace = (struct smb_ace *)((char *)pdacl +sizeof (struct smb_acl )); + aces_size = pdacl_size -sizeof (struct smb_acl ); +for (i =0 ; i <le16_to_cpu (pdacl->num_aces); i++) { +if (aces_size < offsetof(struct smb_ace , sid) + +CIFS_SID_BASE_SIZE ) +break ; + ace_size =le16_to_cpu (ace->size); +if (ace_size > aces_size || + ace_size < offsetof(struct smb_ace , sid) + +CIFS_SID_BASE_SIZE ) +break ; + aces_size -= ace_size; -if (ace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES || - ace_size < offsetof(struct smb_ace , sid) + -CIFS_SID_BASE_SIZE + -sizeof (__le32) * ace->sid.num_subauth) -break ; +if (ace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES || + ace_size < offsetof(struct smb_ace , sid) + +CIFS_SID_BASE_SIZE + +sizeof (__le32) * ace->sid.num_subauth) +break ; -if (!compare_sids (&sid_owner_rights, &ace->sid)) { - owner_rights = true; -if (!is_owner) - goto next_ace; - } +if ((ace->type ==ACCESS_DENIED_OBJECT_ACE_TYPE || + ace->type ==ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE ) && + !(ace->flags &INHERIT_ONLY_ACE )) + obj_deny = true; -if (ace->flags &INHERIT_ONLY_ACE || - (compare_sids (&sid, &ace->sid) && -compare_sids (&sid_unix_NFS_mode, &ace->sid) && -compare_sids (&sid_everyone, &ace->sid) && -compare_sids (&sid_authusers, &ace->sid) && -compare_sids (&sid_owner_rights, &ace->sid))) +if (!compare_sids (&sid_owner_rights, &ace->sid)) { + owner_rights = true; +if (!is_owner) goto next_ace; - -switch (ace->type) { -case ACCESS_ALLOWED_ACE_TYPE : - access_bits |=le32_to_cpu (ace->access_req); -break ; -case ACCESS_DENIED_ACE_TYPE : -case ACCESS_DENIED_CALLBACK_ACE_TYPE : - denied |= ~access_bits & -le32_to_cpu (ace->access_req); -break ; - } -next_ace: - ace = (struct smb_ace *)((char *)ace +le16_to_cpu (ace->size)); } + + member =smb_sid_in_group (&ace->sid); +/* The grp_ masks count groups and OWNER RIGHTS only */ + counted = member || + (is_owner &&smb_sid_is_owner_rights (&ace->sid)); +if (ace->flags &INHERIT_ONLY_ACE || + (compare_sids (&sid, &ace->sid) && +compare_sids (&sid_unix_NFS_mode, &ace->sid) && +compare_sids (&sid_everyone, &ace->sid) && +compare_sids (&sid_authusers, &ace->sid) && +compare_sids (&sid_owner_rights, &ace->sid) && + !member)) + goto next_ace; + + bits =le32_to_cpu (ace->access_req); +switch (ace->type) { +case ACCESS_ALLOWED_ACE_TYPE : +if (counted) + grp_allowed |= bits; +/* MAXIMUM_ALLOWED takes no group grants */ +if (maximal && member) +break ; +if (counted) + grp_granted |= bits; + access_bits |= bits; +break ; +case ACCESS_DENIED_ACE_TYPE : +case ACCESS_DENIED_CALLBACK_ACE_TYPE : +if (counted) + grp_denied |= ~grp_allowed & bits; +/* access_bits takes no group denials either */ +if (!member) + denied |= ~access_bits & bits; +break ; + } +next_ace: + ace = (struct smb_ace *)((char *)ace +le16_to_cpu (ace->size)); + } + +/* Keep only file rights, not MAXIMUM_ALLOWED or generic bits */ + grp_granted &=GENERIC_ALL_FLAGS & ~grp_denied; +if (maximal) {if (is_owner && !owner_rights) access_bits |=READ_CONTROL |WRITE_DAC |FILE_READ_ATTRIBUTES |DELETE ;
@@ -1587,6 +1648,9 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, (access_bits & GENERIC_READ_FLAGS) == GENERIC_READ_FLAGS) access_bits |=FILE_EXECUTE ; granted = requested | access_bits; + }else { +/* An explicit request uses only grp_granted and obj_deny */ + access_bits =0 ; } ace = (struct smb_ace *)((char *)pdacl +sizeof (struct smb_acl ));
@@ -1668,7 +1732,15 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,*/ if (is_owner && !or_ace) allowed =READ_CONTROL |WRITE_DAC ; -if (*pdaccess &FILE_MAXIMAL_ACCESS_LE ) +/* +* Add what ACEs for the caller's groups, or OWNER +* RIGHTS for the owner, grant in DACL order, unless an +* object deny ACE, which ksmbd does not parse, could +* apply. +*/ +if (!obj_deny) + allowed |= grp_granted; +if (maximal) requested |= allowed;if (!allowed || requested & ~allowed) {ksmbd_debug (SMB ,"Can't find corresponding sid\n" );
@@ -1680,7 +1752,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, } } -if (!(*pdaccess &FILE_MAXIMAL_ACCESS_LE )) { +if (!maximal) {switch (ace->type) {case ACCESS_ALLOWED_ACE_TYPE : access_bits =le32_to_cpu (ace->access_req);