Skip to contentSkip to conversation

ksmbd: compare the whole SID when adding POSIX ACL entries to a DACL

PATCH Applied Ian Bridges 2 participants 2 messages Nov 19 – Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: compare the whole SID when adding POSIX ACL entries to a DACL

When a query returns a stored DACL, set_posix_acl_entries_dacl() adds an ACE for each POSIX ACL entry that the stored DACL does not already have. It checks that by comparing only the last sub-authority of the SIDs. A POSIX entry is then left out when a stored ACE for another principal ends in the same number. For example, a stored ACE for unix group 1300 hides the POSIX entry for the user with uid 1300, so the query does not show that this user has access.

Compare the whole SID. A POSIX entry for uid 0 is shown as S-1-22-1-0, but sid_to_id() maps the domain SID with RID 0 to uid 0, so a stored ACE with that SID also counts for it.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")

---

Tested on ksmbd-for-next 4616bbc5389a with KASAN. A file whose stored DACL has an ACE for unix group 1300 and whose POSIX ACL has an entry for uid 1300 now shows both in a query. A stored ACE for uid 0 with the domain SID still covers the POSIX entry for uid 0. Queries of the other tested files are unchanged. smbtorture results match the base.

This patch was developed with LLM assistance.

 fs/smb/server/smbacl.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
fs/smb/server/smbacl.c +24 -3
index 2651214c939a..03d771ea6676 100644
@@ -628,6 +628,25 @@ static int parse_dacl(const struct mnt_idmap *idmap,
 	return ret;
 }
 
+/*
+ * Whether a stored ACE is for the principal of a POSIX ACL entry. The entry
+ * for uid 0 is shown as S-1-22-1-0. sid_to_id() also maps the server domain
+ * SID with RID 0 to uid 0, so a stored ACE with that SID counts as well.
+ */
+static bool ace_is_for_entry(const struct smb_sid *ace_sid,
+			     const struct smb_sid *sid, bool root)
+{
+	const struct smb_sid *dom = &server_conf.domain_sid;
+
+	if (ace_sid->num_subauth == sid->num_subauth &&
+	    !compare_sids(ace_sid, sid))
+		return true;
+
+	return root && ace_sid->num_subauth == dom->num_subauth + 1 &&
+	       !compare_sids(ace_sid, dom) &&
+	       !ace_sid->sub_auth[dom->num_subauth];
+}
+
 static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap,
 				       struct smb_ace *pndace,
 				       struct smb_fattr *fattr, u16 *num_aces,
@@ -646,6 +665,7 @@ static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap,
 	pace = fattr->cf_acls->a_entries;
 	for (i = 0; i < fattr->cf_acls->a_count; i++, pace++) {
 		int flags = 0;
+		bool root = false;
 
 		sid = kmalloc_obj(struct smb_sid, KSMBD_DEFAULT_GFP);
 		if (!sid)
@@ -656,8 +676,10 @@ static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap,
 			unsigned int sid_type = SIDOWNER;
 
 			uid = posix_acl_uid_translate(idmap, pace);
-			if (!uid)
+			if (!uid) {
 				sid_type = SIDUNIX_USER;
+				root = true;
+			}
 			id_to_sid(uid, sid_type, sid);
 		} else if (pace->e_tag == ACL_GROUP) {
 			gid_t gid;
@@ -672,8 +694,7 @@ static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap,
 		}
 		ntace = pndace;
 		for (j = 0; j < existing_nt_aces; j++) {
-			if (ntace->sid.sub_auth[ntace->sid.num_subauth - 1] ==
-					sid->sub_auth[sid->num_subauth - 1])
+			if (ace_is_for_entry(&ntace->sid, sid, root))
 				goto pass_same_sid;
 			ntace = (struct smb_ace *)((char *)ntace +
 					le16_to_cpu(ntace->size));
Signature · 1 line
2.47.3
maintainer Applied
#1 lore raw
Quoted 9 lines · Ian Bridges

When a query returns a stored DACL, set_posix_acl_entries_dacl() adds an ACE for each POSIX ACL entry that the stored DACL does not already have. It checks that by comparing only the last sub-authority of the SIDs. A POSIX entry is then left out when a stored ACE for another principal ends in the same number. For example, a stored ACE for unix group 1300 hides the POSIX entry for the user with uid 1300, so the query does not show that this user has access.

Quoted 7 lines

Compare the whole SID. A POSIX entry for uid 0 is shown as S-1-22-1-0, but sid_to_id() maps the domain SID with RID 0 to uid 0, so a stored ACE with that SID also counts for it.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")

Applied it to #ksmbd-for-next.
Thanks!