ksmbd: drop the get_write argument that every caller sets
Subsystems (2)
PATCH 1/1 ksmbd: drop the get_write argument that every caller sets
Commit 020ad4a0d0ba ("ksmbd: protect SET_INFO metadata updates against filesystem freezing") and commit 3c463ed5bb47 ("ksmbd: protect CREATE metadata updates against filesystem freezing") made every server caller of set_info_sec() and ksmbd_vfs_set_sd_xattr() pass get_write as true. Only the two KUnit tests pass false, and they store on a shmem file, where taking write access works as well.
Remove the argument from both functions. set_info_sec() now always takes write access around the POSIX ACL and attribute update, and ksmbd_vfs_set_sd_xattr() always asks ksmbd_vfs_setxattr() to take it. Nothing changes for clients.
---
The argument no longer selects anything a server caller needs. It only leaves a way to store a security descriptor without freeze protection, which is the gap the two commits above closed. Without the argument, every store through these two functions is protected. set_info_sec() also drops one of four bool arguments in a row, so its call sites are easier to read. The lower helpers such as ksmbd_vfs_setxattr() keep their get_write argument, because some of their callers pass false.
Tested on ksmbd-for-next c710c654b8a3 with KASAN. The stored security descriptors and security queries are the same as without the patch for SET_INFO, the CREATE security descriptor context, inheritance and the default descriptor. The ksmbd KUnit tests pass with GCC and clang. smbtorture results match the base.
This patch was developed with LLM assistance.
fs/smb/server/smb2pdu.c | 8 +++----- fs/smb/server/smbacl.c | 18 +++++++----------- fs/smb/server/smbacl.h | 2 +- fs/smb/server/tests/smbacl_kunit.c | 6 ++---- fs/smb/server/vfs.c | 5 ++--- fs/smb/server/vfs.h | 3 +-- 6 files changed, 16 insertions(+), 26 deletions(-)
fs/smb/server/smb2pdu.c +3 -5
@@ -3954,8 +3954,7 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work,/* parse_sec_desc() refuses a length shorter than the SD header */ pntsd =smb2_context_data (context);return set_info_sec (work->conn, work->tcon, path, pntsd, -le32_to_cpu (context->DataLength), true, true, - true, true); +le32_to_cpu (context->DataLength), true, true, true); } static int ksmbd_acls_fattr(struct smb_fattr *fattr,
@@ -5276,8 +5275,7 @@ int smb2_open(struct ksmbd_work *work) idmap, &path, pntsd, - pntsd_size, - true); + pntsd_size);kvfree (pntsd);if (rc) pr_err("failed to store ntacl in xattr : %d\n",
@@ -9419,7 +9417,7 @@ static int smb2_set_info_sec(struct ksmbd_file *fp, int addition_info,return -EACCES ;return set_info_sec (fp->conn, fp->tcon, &fp->filp->f_path, pntsd, - buf_len, false, true, + buf_len, false, fp->conn->dialect ==SMB311_PROT_ID && fp->is_posix_ctxt, addition_info &DACL_SECINFO ); }
fs/smb/server/smbacl.c +7 -11
@@ -1443,7 +1443,7 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, pntsd_size +=sizeof (struct smb_acl ) + nt_size; } -ksmbd_vfs_set_sd_xattr (conn, idmap, path, pntsd, pntsd_size, true); +ksmbd_vfs_set_sd_xattr (conn, idmap, path, pntsd, pntsd_size);kfree (pntsd); }
@@ -1905,7 +1905,7 @@ static unsigned int smb_parent_derived_rights(struct ksmbd_conn *conn,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, +bool type_check,bool posix_open,bool dacl_requested) {int rc;
@@ -1948,11 +1948,9 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, (fattr.cf_mode &0777 );ksmbd_vfs_remove_acl_xattrs (idmap, path); -if (get_write) { - rc =mnt_want_write (path->mnt); -if (rc) - goto out; - } + rc =mnt_want_write (path->mnt); +if (rc) + goto out;/* Update posix acls */ if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && fattr.cf_dacls) {
@@ -1975,8 +1973,7 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,inode_lock (inode); rc =notify_change (idmap, path->dentry, &newattrs,NULL );inode_unlock (inode); -if (get_write) -mnt_drop_write (path->mnt); +mnt_drop_write (path->mnt);if (rc) goto out;
@@ -1987,8 +1984,7 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,if (test_share_config_flag (tcon->share_conf,KSMBD_SHARE_FLAG_ACL_XATTR )) {/* Update WinACL in xattr */ ksmbd_vfs_remove_sd_xattrs (idmap, path); -ksmbd_vfs_set_sd_xattr (conn, idmap, path, pntsd, ntsd_len, - get_write); +ksmbd_vfs_set_sd_xattr (conn, idmap, path, pntsd, ntsd_len); } out:
fs/smb/server/smbacl.h +1 -1
@@ -106,7 +106,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, bool authenticated, bool strict);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, +bool type_check,bool posix_open,bool dacl_requested);void id_to_sid (unsigned int cid,uint sidtype,struct smb_sid *ssid);void ksmbd_init_domain (u32 *sub_auth);
fs/smb/server/tests/smbacl_kunit.c +2 -4
@@ -222,8 +222,7 @@ static void ksmbd_smb_check_perm_dacl_boundary_test(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, file); rc =ksmbd_vfs_set_sd_xattr (NULL ,mnt_idmap (file->f_path.mnt), - &file->f_path, pntsd, ntsd_size, - false); + &file->f_path, pntsd, ntsd_size);KUNIT_EXPECT_EQ (test,0 , rc);if (rc) goto out;
@@ -264,8 +263,7 @@ ksmbd_smb_check_perm_dacl_maximal_boundary_test(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, file); rc =ksmbd_vfs_set_sd_xattr (NULL ,mnt_idmap (file->f_path.mnt), - &file->f_path, pntsd, ntsd_size, - false); + &file->f_path, pntsd, ntsd_size);KUNIT_EXPECT_EQ (test,0 , rc);if (rc) goto out;
fs/smb/server/vfs.c +2 -3
@@ -1685,8 +1685,7 @@ static struct xattr_smb_acl *ksmbd_vfs_make_xattr_posix_acl(const struct mnt_idmint ksmbd_vfs_set_sd_xattr (struct ksmbd_conn *conn,const struct mnt_idmap *idmap,const struct path *path, -struct smb_ntsd *pntsd,int len, -bool get_write) +struct smb_ntsd *pntsd,int len) {int rc;struct ndr sd_ndr = {0 }, acl_ndr = {0 };
@@ -1743,7 +1742,7 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn, rc =ksmbd_vfs_setxattr (idmap, path,XATTR_NAME_SD , sd_ndr.data, - sd_ndr.offset,0 , get_write); + sd_ndr.offset,0 , true);if (rc <0 )pr_err ("Failed to store XATTR ntacl :%d\n" , rc);
fs/smb/server/vfs.h +1 -2
@@ -164,8 +164,7 @@ int ksmbd_vfs_remove_sd_xattrs(const struct mnt_idmap *idmap, const struct pathint ksmbd_vfs_set_sd_xattr (struct ksmbd_conn *conn,const struct mnt_idmap *idmap,const struct path *path, -struct smb_ntsd *pntsd,int len, -bool get_write); +struct smb_ntsd *pntsd,int len); int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, const struct mnt_idmap *idmap, struct dentry *dentry,
Signature · 1 line
2.47.3
Quoted 8 lines · Ian Bridges
Commit
020ad4a0d0ba("ksmbd: protectSET_INFOmetadata updates against filesystem freezing") and commit3c463ed5bb47("ksmbd: protect CREATE metadata updates against filesystem freezing") made every server caller ofset_info_sec()andksmbd_vfs_set_sd_xattr()passget_writeas true. Only the two KUnit tests pass false, and they store on a shmem file, where taking write access works as well.
Quoted 6 lines
Remove the argument from both functions.
set_info_sec()now always takes write access around the POSIX ACL and attribute update, andksmbd_vfs_set_sd_xattr()always asksksmbd_vfs_setxattr()to take it. Nothing changes for clients.Signed-off-by Ian Bridges <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!