mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ksmbd: build an inherited security descriptor with its own offsets
@ 2026-11-19  7:35 Ian Bridges
  0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-11-19  7:35 UTC (permalink / raw)
  To: linkinjeon
  Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel,
	Ian Bridges, stable

A new file or directory can lose the access rules it should inherit from
its parent. smb_inherit_dacl() sizes the child's descriptor for its SIDs
and inherited ACEs but copies the parent's offsets. The owner and group
SIDs keep their sizes, while the child's DACL can be smaller or larger.
The parent's offsets may therefore be wrong for the child.

ksmbd preserves the component order sent by the client. The Linux
cifs client puts the DACL before the owner and group SIDs, so their
offsets depend on the parent's DACL size. If the child's DACL is
smaller, the copied SID offsets can fall outside the allocation.
ksmbd then uses a default descriptor, losing inherited deny ACEs.
If the child's DACL is larger, it can overwrite the SIDs.

Build the child in owner, group, DACL order and calculate each offset
as its component is copied. These writes exactly fill the allocation,
so the checks on the copied parent offsets are no longer needed.

Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---

The inherited SIDs and ACEs are unchanged. Only their placement in the
child descriptor changes.

Tested on ksmbd-for-next 267029b35ad1 with KASAN. Children of DACL-first
parents now retain inherited deny ACEs and refuse the denied read.
Smaller child DACLs inherit correctly, and larger ones leave the owner
and group SIDs intact. Across the tested parent DACLs, both component
orders produce the same child DACL. Children of parents already in
owner, group, DACL order are byte-for-byte unchanged. smbtorture results
match the base. Windows client layouts were not tested.

This patch was developed with LLM assistance.

 fs/smb/server/smbacl.c | 63 ++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 43 deletions(-)

diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index a87c22fa9a6e..891bfb6f54e2 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1392,56 +1392,33 @@ int smb_inherit_dacl(struct ksmbd_conn *conn,
 		if (le16_to_cpu(parent_pntsd->type) & DACL_AUTO_INHERITED)
 			pntsd->type |= cpu_to_le16(DACL_AUTO_INHERITED);
 		pntsd_size = sizeof(struct smb_ntsd);
-		pntsd->osidoffset = parent_pntsd->osidoffset;
-		pntsd->gsidoffset = parent_pntsd->gsidoffset;
-		pntsd->dacloffset = parent_pntsd->dacloffset;
 
-		if ((u64)le32_to_cpu(pntsd->osidoffset) + powner_sid_size >
-		    pntsd_alloc_size) {
-			rc = -EINVAL;
-			kfree(pntsd);
-			goto free_aces_base;
-		}
-
-		if ((u64)le32_to_cpu(pntsd->gsidoffset) + pgroup_sid_size >
-		    pntsd_alloc_size) {
-			rc = -EINVAL;
-			kfree(pntsd);
-			goto free_aces_base;
-		}
-
-		if ((u64)le32_to_cpu(pntsd->dacloffset) + sizeof(struct smb_acl) + nt_size >
-		    pntsd_alloc_size) {
-			rc = -EINVAL;
-			kfree(pntsd);
-			goto free_aces_base;
-		}
-
-		if (pntsd->osidoffset) {
-			struct smb_sid *owner_sid = (struct smb_sid *)((char *)pntsd +
-					le32_to_cpu(pntsd->osidoffset));
-			memcpy(owner_sid, powner_sid, powner_sid_size);
+		/*
+		 * Lay out the child as owner, group and DACL. The parent may
+		 * store its components in another order, so its offsets do
+		 * not fit the child.
+		 */
+		if (powner_sid) {
+			pntsd->osidoffset = cpu_to_le32(pntsd_size);
+			memcpy((char *)pntsd + pntsd_size, powner_sid,
+			       powner_sid_size);
 			pntsd_size += powner_sid_size;
 		}
 
-		if (pntsd->gsidoffset) {
-			struct smb_sid *group_sid = (struct smb_sid *)((char *)pntsd +
-					le32_to_cpu(pntsd->gsidoffset));
-			memcpy(group_sid, pgroup_sid, pgroup_sid_size);
+		if (pgroup_sid) {
+			pntsd->gsidoffset = cpu_to_le32(pntsd_size);
+			memcpy((char *)pntsd + pntsd_size, pgroup_sid,
+			       pgroup_sid_size);
 			pntsd_size += pgroup_sid_size;
 		}
 
-		if (pntsd->dacloffset) {
-			struct smb_ace *pace;
-
-			pdacl = (struct smb_acl *)((char *)pntsd + le32_to_cpu(pntsd->dacloffset));
-			pdacl->revision = cpu_to_le16(2);
-			pdacl->size = cpu_to_le16(sizeof(struct smb_acl) + nt_size);
-			pdacl->num_aces = cpu_to_le16(ace_cnt);
-			pace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl));
-			memcpy(pace, aces_base, nt_size);
-			pntsd_size += sizeof(struct smb_acl) + nt_size;
-		}
+		pntsd->dacloffset = cpu_to_le32(pntsd_size);
+		pdacl = (struct smb_acl *)((char *)pntsd + pntsd_size);
+		pdacl->revision = cpu_to_le16(2);
+		pdacl->size = cpu_to_le16(sizeof(struct smb_acl) + nt_size);
+		pdacl->num_aces = cpu_to_le16(ace_cnt);
+		memcpy((char *)pdacl + sizeof(struct smb_acl), aces_base, nt_size);
+		pntsd_size += sizeof(struct smb_acl) + nt_size;
 
 		ksmbd_vfs_set_sd_xattr(conn, idmap, path, pntsd, pntsd_size);
 		kfree(pntsd);
-- 
2.47.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19  7:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  7:35 [PATCH] ksmbd: build an inherited security descriptor with its own offsets 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®