[PATCH] ksmbd: return only the control flags of the parts in a query reply
From: Ian Bridges
Date: Sun Nov 22 2026 - 11:02:04 EST
build_sec_desc() copies the stored control flags into the query reply
and clears only the DACL flags when the DACL is not requested. A
SET_INFO without DACL_PRESENT stores the control word as the client
sent it. Its other flags then appear in every reply, such as
OWNER_DEFAULTED in a reply without the owner, and SACL_PRESENT
although ksmbd refuses to query the SACL.
Copy a stored control flag into the reply only when the part it goes
with is in the reply. OWNER_DEFAULTED goes with the owner and
GROUP_DEFAULTED with the group. DACL_PRESENT, DACL_DEFAULTED,
DACL_AUTO_INHERITED and DACL_PROTECTED go with the DACL. The SACL
flags and the other stored bits, such as SERVER_SECURITY and
RM_CONTROL_VALID, are not copied.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
Tested on ksmbd-for-next 89d5e8fdd5a7 with KASAN. After a SET_INFO of
the owner with DACL_PRESENT clear and other control flags set, every
query reply returned those flags, for example 0xebf3 for the owner
alone. The replies are now 0x8001 for the owner, 0x8002 for the group
and 0x8004 for the DACL. Replies for descriptors stored with
DACL_PRESENT, smbcacls and the Linux cifs client, and smbtorture give
the same results as the base.
This patch was developed with LLM assistance.
fs/smb/server/smbacl.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 7bb28ea195c8..a4a36983852b 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1111,13 +1111,17 @@ int build_sec_desc(const struct mnt_idmap *idmap,
pntsd->revision = cpu_to_le16(1);
pntsd->type = cpu_to_le16(SELF_RELATIVE);
if (ppntsd) {
- pntsd->type |= ppntsd->type;
- /* These DACL flags are returned only with the DACL */
- if (!(addition_info & DACL_SECINFO))
- pntsd->type &= ~cpu_to_le16(DACL_PRESENT |
- DACL_DEFAULTED |
- DACL_AUTO_INHERITED |
- DACL_PROTECTED);
+ u16 flags = 0;
+
+ /* Return the stored flags only of the parts in the reply */
+ if (addition_info & OWNER_SECINFO)
+ flags |= OWNER_DEFAULTED;
+ if (addition_info & GROUP_SECINFO)
+ flags |= GROUP_DEFAULTED;
+ if (addition_info & DACL_SECINFO)
+ flags |= DACL_PRESENT | DACL_DEFAULTED |
+ DACL_AUTO_INHERITED | DACL_PROTECTED;
+ pntsd->type |= ppntsd->type & cpu_to_le16(flags);
}
if (addition_info & OWNER_SECINFO) {
--
2.47.3