]> git.hungrycats.org Git - linux/commitdiff
ksmbd: deny access for an empty DACL instead of granting the request
authorAamir Ahmed <elb12345@hotmail.co.uk>
Tue, 3 Nov 2026 14:59:19 +0000 (09:59 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:13 +0000 (12:06 -0500)
[ Upstream commit de0cffef897c1c232ed973f89928cd6c93d0b1e3 ]

smb_check_perm_dacl() returns the access mask it computes to the SMB2
CREATE handler, which uses it as the granted access for the open. For a
security descriptor whose DACL is present but contains no ACEs, the
function is supposed to deny access: an empty (non-NULL) DACL grants no
access to anyone except the object owner's implicit READ_CONTROL and
WRITE_DAC (MS-DTYP 2.4.5).

The empty-DACL branch only denies when both

  - the DACL has no trailing bytes (pdacl_size == sizeof(struct smb_acl)),
    and
  - the request contains bits beyond READ_CONTROL / WRITE_DAC.

In every other case it takes the shared "goto err_out" with rc still 0,
which returns success without modifying *pdaccess, so the caller grants
the full requested access. Three problems follow:

  - The READ_CONTROL / WRITE_DAC carve-out models the owner's implicit
    rights, but the check runs before is_owner is computed, so those
    rights are handed to *every* caller, not just the owner. For
    READ_CONTROL the SMB2 CREATE path does not fall back to
    inode_permission(), so any user can read the security descriptor of
    an object whose empty DACL is meant to deny them.

  - A request of exactly READ_CONTROL and/or WRITE_DAC is granted to any
    caller. WRITE_DAC lets the handle rewrite the DACL.

  - A DACL that declares zero ACEs but carries trailing bytes
    (pdacl_size > sizeof(struct smb_acl)) skips the deny entirely and is
    granted whatever was requested.

On shares where the NT ACL is the authoritative access control -- e.g.
"force user" shares, where every client maps to one POSIX identity so
POSIX cannot distinguish users -- this is an access-control bypass.

Compute is_owner before the empty-DACL branch and deny access from an
empty DACL unless the caller is the owner requesting no more than
READ_CONTROL / WRITE_DAC.

Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
[ sashal: added missing ownership declarations and initialization of is_owner using the mount’s ID mapping ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/server/smbacl.c

index 49a35974dd296632f98f38e690e201409fd02e8f..33a607e709f1831f32a6fb8617b1afbf2398cafb 100644 (file)
@@ -1469,6 +1469,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
        struct posix_acl_entry *pa_entry;
        unsigned int sid_type = SIDOWNER;
        unsigned short ace_size;
+       bool is_owner;
+       vfsuid_t vfsuid;
 
        ksmbd_debug(SMB, "check permission using windows acl\n");
        pntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap,
@@ -1489,19 +1491,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 (!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) {
-               if (!(pdacl_size - sizeof(struct smb_acl)) &&
-                   *pdaccess & ~(FILE_READ_CONTROL_LE | FILE_WRITE_DAC_LE)) {
+               /*
+                * 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;
-               }
                goto err_out;
        }
 
-       if (!uid)
-               sid_type = SIDUNIX_USER;
-       id_to_sid(uid, sid_type, &sid);
-
        if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) {
                access_bits = READ_CONTROL | WRITE_DAC | FILE_READ_ATTRIBUTES |
                        DELETE;