Skip to contentSkip to conversation

ksmbd: reject a security descriptor with OffsetDacl but no DACL_PRESENT

PATCH Applied Ian Bridges 2 participants 2 messages Nov 22 – Nov 23

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

PATCH 1/1 ksmbd: reject a security descriptor with OffsetDacl but no DACL_PRESENT

parse_sec_desc() returns early when DACL_PRESENT is clear and checks nothing else in the descriptor. set_info_sec() then removes the POSIX ACLs and stores the descriptor as sent, OffsetDacl included. The access check, inheritance and QUERY use the DACL at OffsetDacl without looking at DACL_PRESENT. A SET_INFO without the flag can therefore store a DACL that was never checked or mapped to the mode, and that DACL is enforced.

A descriptor without DACL_PRESENT has no DACL, so its OffsetDacl must be zero. Reject a nonzero OffsetDacl in that case with -EINVAL, as parse_sec_desc() does for other malformed descriptors.

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

---

Tested on ksmbd-for-next 89d5e8fdd5a7 with KASAN. A SET_INFO with DACL_PRESENT clear and a nonzero OffsetDacl now fails with STATUS_INVALID_PARAMETER, and the file keeps its previous descriptor and POSIX ACL. Before, the DACL was stored without checks, the POSIX ACL was removed, and a deny ACE in the DACL was enforced. A CREATE whose security descriptor context has this form now fails the same way after the file is created, as a CREATE with another malformed context does. Descriptors with DACL_PRESENT set, owner and group changes from 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 | 3 +++
 1 file changed, 3 insertions(+)
fs/smb/server/smbacl.c +3 -0
index 7bb28ea195c8..446b4f69d7c4 100644
@@ -963,6 +963,9 @@ int parse_sec_desc(const struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
 	pntsd_type = le16_to_cpu(pntsd->type);
 	if (!(pntsd_type & DACL_PRESENT)) {
 		ksmbd_debug(SMB, "DACL_PRESENT in DACL type is not set\n");
+		/* Without DACL_PRESENT, OffsetDacl must be 0 (MS-DTYP 2.4.6) */
+		if (dacloffset)
+			return -EINVAL;
 		return rc;
 	}
 
Signature · 1 line
2.47.3
maintainer Applied
#1 lore raw
Quoted 9 lines · Ian Bridges

parse_sec_desc() returns early when DACL_PRESENT is clear and checks nothing else in the descriptor. set_info_sec() then removes the POSIX ACLs and stores the descriptor as sent, OffsetDacl included. The access check, inheritance and QUERY use the DACL at OffsetDacl without looking at DACL_PRESENT. A SET_INFO without the flag can therefore store a DACL that was never checked or mapped to the mode, and that DACL is enforced.

Quoted 7 lines

A descriptor without DACL_PRESENT has no DACL, so its OffsetDacl must be zero. Reject a nonzero OffsetDacl in that case with -EINVAL, as parse_sec_desc() does for other malformed descriptors.

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

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