[PATCH 2/2] ksmbd: let the parent's DACL grant DELETE and FILE_READ_ATTRIBUTES
From: Ian Bridges
Date: Sat Nov 07 2026 - 01:23:14 EST
A directory's FILE_DELETE_CHILD lets a caller delete the files in it,
and its FILE_LIST_DIRECTORY lets a caller list them with their
attributes. ksmbd checks only the file's DACL, so an open for DELETE
or FILE_READ_ATTRIBUTES can be refused even when the parent grants the
corresponding right. For example, this happens with an empty file DACL
under a parent that grants Everyone full access. Without DELETE on the
handle, the caller cannot rename the file or set its delete
disposition. A caller can also see a file's attributes in a directory
listing but be unable to open the file for FILE_READ_ATTRIBUTES.
When the file's DACL does not grant a requested DELETE or
FILE_READ_ATTRIBUTES, check the parent's DACL for FILE_DELETE_CHILD or
FILE_LIST_DIRECTORY respectively. Use exact SID matching, include group
allows and denies, exclude guest and anonymous sessions from
Authenticated Users, and fail closed on non-inherit-only object deny
ACEs. Do not look above the mount root. A missing or unreadable parent
DACL grants nothing.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
Notes:
Plain MAXIMUM_ALLOWED requests and maximal-access replies get
neither right from the parent. Deriving DELETE for them can make
smb2_open() refuse opens that succeed today when POSIX denies the
caller write access to the parent. FILE_READ_ATTRIBUTES is left
out there too, so that both rights come from the parent only when
the request names them.
Because smb2_open() fails an open whose maximal-access reply is
refused, a DELETE open requesting that reply can still fail when
the file DACL grants nothing, as on the base. A DELETE open also
still requires POSIX read access to the file.
fs/smb/server/smbacl.c | 82 +++++++++++++++++++++++++++++++++++-------
1 file changed, 69 insertions(+), 13 deletions(-)
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index f773ab8efb3f..89a03cbbdbb9 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1494,6 +1494,11 @@ static bool smb_sid_is_owner_rights(const struct smb_sid *sid)
!compare_sids(sid, &sid_owner_rights);
}
+static unsigned int smb_parent_derived_rights(struct ksmbd_conn *conn,
+ const struct path *path, int uid,
+ bool authenticated,
+ unsigned int want);
+
int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
__le32 *pdaccess, __le32 raw_daccess, int uid,
bool authenticated, bool strict)
@@ -1520,10 +1525,12 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
bool is_owner, owner_rights = false;
bool maximal = *pdaccess & FILE_MAXIMAL_ACCESS_LE;
/*
- * MAXIMUM_ALLOWED requests match every session against
- * Authenticated Users.
+ * MAXIMUM_ALLOWED requests that are not strict match every session
+ * against Authenticated Users and do not count ACEs for the
+ * caller's groups. Strict ones match SIDs as explicit requests do.
*/
- bool authusers = authenticated || maximal;
+ bool open_max = maximal && !strict;
+ bool authusers = authenticated || open_max;
vfsuid_t vfsuid;
ksmbd_debug(SMB, "check permission using windows acl\n");
@@ -1557,13 +1564,16 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
/*
* 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.
+ * and WRITE_DAC (MS-DTYP 2.5.3.2), besides what the parent
+ * grants. Deny every other right, and do not let trailing
+ * bytes after a zero-ACE DACL become an implicit grant.
*/
if (is_owner)
allowed = READ_CONTROL | WRITE_DAC;
+ if (!strict)
+ allowed |= smb_parent_derived_rights(conn, path, uid,
+ authenticated,
+ requested & ~allowed);
if (maximal)
requested |= allowed;
if (!allowed || requested & ~allowed)
@@ -1623,8 +1633,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
compare_sids(&sid_owner_rights, &ace->sid) &&
!member))
goto next_ace;
- /* An explicit request counts only SIDs that match exactly */
- if (!maximal && !member &&
+ /* Other requests count only SIDs that match exactly */
+ if (!open_max && !member &&
!smb_sid_equal(&sid, &ace->sid) &&
!smb_sid_equal(&sid_everyone, &ace->sid) &&
!(authusers && smb_sid_equal(&sid_authusers, &ace->sid)) &&
@@ -1636,8 +1646,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
case ACCESS_ALLOWED_ACE_TYPE:
if (counted)
grp_allowed |= bits;
- /* MAXIMUM_ALLOWED takes no group grants */
- if (maximal && member)
+ /* An open's MAXIMUM_ALLOWED takes no group grants */
+ if (open_max && member)
break;
if (counted)
grp_granted |= bits;
@@ -1647,8 +1657,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
case ACCESS_DENIED_CALLBACK_ACE_TYPE:
if (counted)
grp_denied |= ~grp_allowed & bits;
- /* MAXIMUM_ALLOWED takes no group denials either */
- if (!(maximal && member))
+ /* nor group denials */
+ if (!(open_max && member))
denied |= ~access_bits & bits;
break;
}
@@ -1663,6 +1673,9 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
access_bits |= READ_CONTROL | WRITE_DAC |
FILE_READ_ATTRIBUTES | DELETE;
access_bits &= ~denied;
+ /* An object deny ACE could deny the parent's rights */
+ if (!open_max && obj_deny)
+ access_bits = 0;
if ((raw_daccess & FILE_GENERIC_EXECUTE_LE) &&
S_ISREG(d_inode(path->dentry)->i_mode) &&
(access_bits & GENERIC_READ_FLAGS) == GENERIC_READ_FLAGS)
@@ -1767,6 +1780,10 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
*/
if (!obj_deny)
allowed |= grp_granted;
+ if (!strict)
+ allowed |= smb_parent_derived_rights(conn, path, uid,
+ authenticated,
+ requested & ~allowed);
if (maximal)
requested |= allowed;
if (!allowed || requested & ~allowed) {
@@ -1813,6 +1830,45 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
}
EXPORT_SYMBOL_IF_KUNIT(smb_check_perm_dacl);
+/*
+ * Return the rights in @want that @path gets from its parent directory:
+ * DELETE if the parent's DACL grants FILE_DELETE_CHILD, and
+ * FILE_READ_ATTRIBUTES if it grants FILE_LIST_DIRECTORY
+ * (MS-FSA 2.1.5.1.2.1). A parent with no DACL, or with one that ksmbd
+ * cannot read, gives nothing. Callers pass only rights that the request
+ * names.
+ */
+static unsigned int smb_parent_derived_rights(struct ksmbd_conn *conn,
+ const struct path *path, int uid,
+ bool authenticated,
+ unsigned int want)
+{
+ struct path parent = { .mnt = path->mnt };
+ __le32 granted = FILE_MAXIMAL_ACCESS_LE;
+ unsigned int rights = 0;
+ int rc;
+
+ if (!(want & (DELETE | FILE_READ_ATTRIBUTES)))
+ return 0;
+
+ /* The root of the mount, or a disconnected dentry, has no parent */
+ if (path->dentry == path->mnt->mnt_root || IS_ROOT(path->dentry))
+ return 0;
+
+ parent.dentry = dget_parent(path->dentry);
+ /* Strict, so the parent's own parent is not consulted */
+ rc = smb_check_perm_dacl(conn, &parent, &granted, 0, uid,
+ authenticated, true);
+ dput(parent.dentry);
+ if (rc || granted == FILE_MAXIMAL_ACCESS_LE)
+ return 0;
+ if (granted & FILE_DELETE_CHILD_LE)
+ rights |= DELETE;
+ if (granted & FILE_LIST_DIRECTORY_LE)
+ rights |= FILE_READ_ATTRIBUTES;
+ return rights & want;
+}
+
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,
--
2.47.3