Skip to contentSkip to conversation

ksmbd: enforce the DACL permission check on delete-on-close opens

PATCH In review Ian Bridges 2 participants 3 messages Oct 29 – Nov 1

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

PATCH v2 1/1 ksmbd: enforce the DACL permission check on delete-on-close opens

smb2_open() skips the DACL check for delete-on-close opens of existing files. On an acl_xattr share, a caller who passes the POSIX checks can therefore delete a file even when its stored DACL grants no access. The handle can also get read or write access that the DACL denies.

Add a dedicated DACL check for these opens. Evaluate the applicable ACEs in order (MS-DTYP 2.5.3.2). Allow the parent directory to grant DELETE and FILE_READ_ATTRIBUTES under MS-FSA 2.1.5.1.2.1. Use the DACL grants when resolving MAXIMUM_ALLOWED.

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

---

Notes:
Changes in v2
- Replace v1 and the proposed parent-delete follow-up with one patch.
- Use a dedicated check to preserve valid delete-on-close requests, including smbtorture smb2.acls.INHERITANCE and opens requesting FILE_READ_ATTRIBUTES or MAXIMUM_ALLOWED.

v1: https://lore.kernel.org/linux-cifs/[email protected]/

Tested on ksmbd-for-next af8c72f65507. The original deletion bypass is blocked. Targeted tests cover group and forced-group grants, parent permissions, owner rights, guest and anonymous sessions, streams and MAXIMUM_ALLOWED. smbtorture smb2.acls and eight related suites match the base results.

I did not Cc stable because of the patch's size. The size comes from keeping this check separate from smb_check_perm_dacl(), so this fix changes no other open. A backport needs 67cc25f7307c ("ksmbd: require DELETE access for delete-on-close opens").

This leaves smb_check_perm_dacl() with its own DACL walk, which could later use the one added here so that ksmbd has only one.

A reproducer is available on request.

This fix was developed with LLM assistance.

 fs/smb/server/smb2pdu.c |   8 ++-
 fs/smb/server/smbacl.c  | 153 ++++++++++++++++++++++++++++++++++++++++
 fs/smb/server/smbacl.h  |   3 +
 3 files changed, 163 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +7 -1
index 2e955d272f4b..b56fcbfc6039 100644
@@ -4848,7 +4848,13 @@ int smb2_open(struct ksmbd_work *work)
 
 	daccess = smb_map_generic_desired_access(req->DesiredAccess);
 
-	if (file_present && !(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) {
+	if (file_present && req->CreateOptions & FILE_DELETE_ON_CLOSE_LE) {
+		rc = smb_check_perm_delete_on_close(conn, &path,
+						    path.dentry == share->vfs_path.dentry,
+						    sess->user, &daccess);
+		if (rc)
+			goto err_out;
+	} else if (file_present) {
 		rc = smb_check_perm_dacl(conn, &path, &daccess,
 					 req->DesiredAccess,
 					 sess->user->uid, false);
fs/smb/server/smbacl.c +153 -0

165 lines not on this page · raw message

fs/smb/server/smbacl.h +3 -0
index 3342cebab333..d9b11bb06331 100644
@@ -98,6 +98,9 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, const struct path *path,
 int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
 			__le32 *pdaccess, __le32 raw_daccess, int uid,
 			bool strict);
+int smb_check_perm_delete_on_close(struct ksmbd_conn *conn,
+				   const struct path *path, bool share_root,
+				   struct ksmbd_user *user, __le32 *pdaccess);
 int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
 		 const struct path *path, struct smb_ntsd *pntsd, int ntsd_len,
 		 bool type_check, bool get_write, bool posix_open,

base-commit: af8c72f6550744fe948ef2dbc7ab8739c149aab2

Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 6 lines · Ian Bridges

smb2_open() skips the DACL check for delete-on-close opens of existing files. On an acl_xattr share, a caller who passes the POSIX checks can therefore delete a file even when its stored DACL grants no access. The handle can also get read or write access that the DACL denies.

Quoted 7 lines

Add a dedicated DACL check for these opens. Evaluate the applicable ACEs in order (MS-DTYP 2.5.3.2). Allow the parent directory to grant DELETE and FILE_READ_ATTRIBUTES under MS-FSA 2.1.5.1.2.1. Use the DACL grants when resolving MAXIMUM_ALLOWED.

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

Can you check Sashiko's review comments ?

https://sashiko.dev/#/patchset/20261029140535.260498-1-icb%40fastmail.org

Thanks.

#2 lore raw

Hi Namjae,

Please drop this patch.

I checked Sashiko's comments. It found two real problems in this patch. While fixing them I found that checking delete-on-close opens with smb_check_perm_dacl() makes some valid opens fail. Other issues need to be fixed first.

I will send patches for those issues, then resend a fix for this bug once those patches are merged.

Thanks,
Ian