[PATCH] ksmbd: fix empty DACL handling in smb_check_perm_dacl()

From: Aamir Ahmed

Date: Mon Sep 07 2026 - 00:31:56 EST


smb_check_perm_dacl() does not properly enforce an empty (present,
zero-ACE) DACL. Per MS-DTYP section 2.4.5, an empty DACL grants no
access to anyone except the object owner's implicit READ_CONTROL and
WRITE_DAC permissions.

The current code has two problems:

1. Non-owners requesting only READ_CONTROL or WRITE_DAC are allowed
access because the code does not check caller identity before
granting these permissions.

2. When pdacl_size exceeds sizeof(struct smb_acl) (trailing bytes
after the zero-ACE DACL header), the condition
!(pdacl_size - sizeof(struct smb_acl)) evaluates to false, and the
function returns success (rc=0) regardless of the access requested.
This means trailing bytes after a zero-ACE DACL bypass all access
control.

Fix both by moving the uid/sid resolution and is_owner determination
before the num_aces check, then denying all non-owner access and
restricting owners to READ_CONTROL|WRITE_DAC.

Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Signed-off-by: Aamir Ahmed <elb12345@xxxxxxxxxxxxx>
---
fs/smb/server/smbacl.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 1fad6ccf3a72..ae55813790bd 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1490,21 +1490,27 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
if (pdacl_size > acl_size || pdacl_size < sizeof(struct smb_acl))
goto err_out;

- if (!pdacl->num_aces) {
- if (!(pdacl_size - sizeof(struct smb_acl)) &&
- *pdaccess & ~(FILE_READ_CONTROL_LE | FILE_WRITE_DAC_LE)) {
- rc = -EACCES;
- goto err_out;
- }
- goto err_out;
- }
-
if (!uid)
sid_type = SIDUNIX_USER;
id_to_sid(uid, sid_type, &sid);
vfsuid = i_uid_into_vfsuid(idmap, d_inode(path->dentry));
is_owner = uid == from_kuid(&init_user_ns, vfsuid_into_kuid(vfsuid));

+ if (!pdacl->num_aces) {
+ /*
+ * An empty (present, zero-ACE) DACL grants no access to
+ * anyone except the object owner's implicit READ_CONTROL
+ * and WRITE_DAC (MS-DTYP 2.4.5). Deny every other caller,
+ * deny the owner any access beyond those two bits, and do
+ * not let trailing bytes after a zero-ACE DACL become an
+ * implicit grant.
+ */
+ if (!is_owner ||
+ (*pdaccess & ~(FILE_READ_CONTROL_LE | FILE_WRITE_DAC_LE)))
+ rc = -EACCES;
+ goto err_out;
+ }
+
if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) {
ace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl));
aces_size = pdacl_size - sizeof(struct smb_acl);
--
2.43.0