* [PATCH] ksmbd: compare the whole SID when adding POSIX ACL entries to a DACL
@ 2026-11-19 19:10 Ian Bridges
0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-11-19 19:10 UTC (permalink / raw)
To: linkinjeon
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel,
Ian Bridges, stable
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")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
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(-)
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 2651214c939a..03d771ea6676 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -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));
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 19:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 19:10 [PATCH] ksmbd: compare the whole SID when adding POSIX ACL entries to a DACL Ian Bridges
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®