ksmbd: do not treat an unreadable security descriptor as none
Subsystems (3)
PATCH 1/1 ksmbd: do not treat an unreadable security descriptor as none
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.
---
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(-)
fs/smb/server/smb2pdu.c +6 -1
@@ -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,
fs/smb/server/smbacl.c +4 -1
@@ -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 ||
fs/smb/server/smbacl.h +6 -0
@@ -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);
fs/smb/server/vfs.c +24 -4
@@ -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);
Signature · 1 line
2.47.3
Quoted 15 lines · Ian Bridges
On
acl_xattrshares, 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.
Quoted 4 lines
Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")Fixes f44158485826 ("cifsd: add file operations")Signed-off-by Ian Bridges <[email protected]>
Applied it to #ksmbd-for-next.
Thanks.