* [PATCH] ksmbd: do not treat an unreadable security descriptor as none
@ 2026-11-16 12:47 Ian Bridges
2026-11-16 14:02 ` Namjae Jeon
0 siblings, 1 reply; 2+ messages in thread
From: Ian Bridges @ 2026-11-16 12:47 UTC (permalink / raw)
To: linkinjeon
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel,
Ian Bridges, stable
On acl_xattr shares, a failed security descriptor load makes access
checks fall back to POSIX permissions. An allocation or read failure
can therefore bypass a stored deny ACE. Security queries also fall
back, returning a descriptor built from the inode instead.
Fail access checks and security queries on allocation and read errors.
Keep the existing fallback for missing xattrs, unsupported xattrs, and
malformed or stale descriptors.
Propagate POSIX ACL read and allocation failures during descriptor
validation too. Otherwise, hashing an unreadable ACL as absent can
make a valid descriptor appear stale and allow the same fallback.
Leave the descriptor store path's error handling unchanged.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Fixes: f44158485826 ("cifsd: add file operations")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
Notes:
Tested on ksmbd-for-next 3bc1fb9c3b20 with KASAN and failslab.
Failed descriptor and POSIX ACL allocations now fail opens and
security queries instead of falling back to POSIX permissions. With
hide unreadable enabled, directory listings omit the file. Files
with no stored descriptor behave as before, including under
allocation failure. smbtorture results match the base.
This fix was developed with LLM assistance.
fs/smb/server/smb2pdu.c | 7 ++++++-
fs/smb/server/smbacl.c | 5 ++++-
fs/smb/server/smbacl.h | 6 ++++++
fs/smb/server/vfs.c | 28 ++++++++++++++++++++++++----
4 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 9ef2d086fc4e..a900f1331c42 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -8503,10 +8503,15 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
}
if (test_share_config_flag(work->tcon->share_conf,
- KSMBD_SHARE_FLAG_ACL_XATTR))
+ KSMBD_SHARE_FLAG_ACL_XATTR)) {
ppntsd_size = ksmbd_vfs_get_sd_xattr(work->conn, idmap,
fp->filp->f_path.dentry,
&ppntsd);
+ if (ppntsd_size < 0 && !smb_no_stored_sd(ppntsd_size)) {
+ rc = ppntsd_size == -ENOMEM ? -ENOMEM : -EIO;
+ goto release_acl;
+ }
+ }
/* Check if sd buffer size exceeds response buffer size */
max_len = smb2_calc_max_out_buf_len(work,
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 0ca093de83c6..9aac87ff3b4a 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1545,8 +1545,11 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
ksmbd_debug(SMB, "check permission using windows acl\n");
pntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap,
path->dentry, &pntsd);
- if (pntsd_size <= 0 || !pntsd)
+ if (pntsd_size <= 0 || !pntsd) {
+ if (pntsd_size < 0 && !smb_no_stored_sd(pntsd_size))
+ rc = pntsd_size == -ENOMEM ? -ENOMEM : -EACCES;
goto err_out;
+ }
dacl_offset = le32_to_cpu(pntsd->dacloffset);
if (!dacl_offset ||
diff --git a/fs/smb/server/smbacl.h b/fs/smb/server/smbacl.h
index bbd35948a379..6bb64fef02cd 100644
--- a/fs/smb/server/smbacl.h
+++ b/fs/smb/server/smbacl.h
@@ -95,6 +95,12 @@ int compare_sids(const struct smb_sid *ctsid, const struct smb_sid *cwsid);
bool smb_inherit_flags(int flags, bool is_dir);
int smb_inherit_dacl(struct ksmbd_conn *conn, const struct path *path,
unsigned int uid, unsigned int gid);
+/* Missing, unsupported, malformed or stale SDs retain the POSIX fallback */
+static inline bool smb_no_stored_sd(int rc)
+{
+ return rc == -ENODATA || rc == -EOPNOTSUPP || rc == -EINVAL;
+}
+
int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
__le32 *pdaccess, __le32 raw_daccess, int uid,
bool authenticated, bool strict);
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 09dad151360c..45618b2bc1fb 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -1630,13 +1630,15 @@ static struct xattr_smb_acl *ksmbd_vfs_make_xattr_posix_acl(const struct mnt_idm
posix_acls = get_inode_acl(inode, acl_type);
if (IS_ERR_OR_NULL(posix_acls))
- return NULL;
+ return ERR_CAST(posix_acls);
smb_acl = kzalloc(sizeof(struct xattr_smb_acl) +
sizeof(struct xattr_acl_entry) * posix_acls->a_count,
KSMBD_DEFAULT_GFP);
- if (!smb_acl)
+ if (!smb_acl) {
+ smb_acl = ERR_PTR(-ENOMEM);
goto out;
+ }
smb_acl->count = posix_acls->a_count;
pa_entry = posix_acls->a_entries;
@@ -1712,11 +1714,17 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
sha256(acl.sd_buf, acl.sd_size, acl.hash);
+ /* A POSIX ACL that cannot be read is hashed as none, as before */
smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
ACL_TYPE_ACCESS);
- if (S_ISDIR(inode->i_mode))
+ if (IS_ERR(smb_acl))
+ smb_acl = NULL;
+ if (S_ISDIR(inode->i_mode)) {
def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
ACL_TYPE_DEFAULT);
+ if (IS_ERR(def_smb_acl))
+ def_smb_acl = NULL;
+ }
rc = ndr_encode_posix_acl(&acl_ndr, idmap, inode,
smb_acl, def_smb_acl);
@@ -1770,11 +1778,23 @@ int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
if (rc)
goto out_free;
+ /* ACL read failures must not masquerade as a stale SD */
smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
ACL_TYPE_ACCESS);
- if (S_ISDIR(inode->i_mode))
+ if (IS_ERR(smb_acl)) {
+ rc = PTR_ERR(smb_acl) == -ENOMEM ? -ENOMEM : -EIO;
+ smb_acl = NULL;
+ goto out_free;
+ }
+ if (S_ISDIR(inode->i_mode)) {
def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
ACL_TYPE_DEFAULT);
+ if (IS_ERR(def_smb_acl)) {
+ rc = PTR_ERR(def_smb_acl) == -ENOMEM ? -ENOMEM : -EIO;
+ def_smb_acl = NULL;
+ goto out_free;
+ }
+ }
rc = ndr_encode_posix_acl(&acl_ndr, idmap, inode, smb_acl,
def_smb_acl);
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ksmbd: do not treat an unreadable security descriptor as none
2026-11-16 12:47 [PATCH] ksmbd: do not treat an unreadable security descriptor as none Ian Bridges
@ 2026-11-16 14:02 ` Namjae Jeon
0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-11-16 14:02 UTC (permalink / raw)
To: Ian Bridges
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel, stable
On Mon, Nov 16, 2026 at 9:48 PM Ian Bridges <icb@fastmail.org> wrote:
>
> On acl_xattr shares, a failed security descriptor load makes access
> checks fall back to POSIX permissions. An allocation or read failure
> can therefore bypass a stored deny ACE. Security queries also fall
> back, returning a descriptor built from the inode instead.
>
> Fail access checks and security queries on allocation and read errors.
> Keep the existing fallback for missing xattrs, unsupported xattrs, and
> malformed or stale descriptors.
>
> Propagate POSIX ACL read and allocation failures during descriptor
> validation too. Otherwise, hashing an unreadable ACL as absent can
> make a valid descriptor appear stale and allow the same fallback.
> Leave the descriptor store path's error handling unchanged.
>
> Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
> Fixes: f44158485826 ("cifsd: add file operations")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ian Bridges <icb@fastmail.org>
Applied it to #ksmbd-for-next.
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 14:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 12:47 [PATCH] ksmbd: do not treat an unreadable security descriptor as none Ian Bridges
2026-11-16 14:02 ` Namjae Jeon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®