[PATCH] ksmbd: drop the get_write argument that every caller sets
From: Ian Bridges
Date: Mon Nov 16 2026 - 16:26:15 EST
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.
Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
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(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index b74dafe6a307..29750970f8da 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -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);
}
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 9aac87ff3b4a..a87c22fa9a6e 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -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:
diff --git a/fs/smb/server/smbacl.h b/fs/smb/server/smbacl.h
index 6bb64fef02cd..b51a8c6c1d4e 100644
--- a/fs/smb/server/smbacl.h
+++ b/fs/smb/server/smbacl.h
@@ -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);
diff --git a/fs/smb/server/tests/smbacl_kunit.c b/fs/smb/server/tests/smbacl_kunit.c
index bf28439a7696..39c9f8bb1ea7 100644
--- a/fs/smb/server/tests/smbacl_kunit.c
+++ b/fs/smb/server/tests/smbacl_kunit.c
@@ -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;
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 7c3edbe6cb77..8cb91315ac66 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -1685,8 +1685,7 @@ static struct xattr_smb_acl *ksmbd_vfs_make_xattr_posix_acl(const struct mnt_idm
int 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);
diff --git a/fs/smb/server/vfs.h b/fs/smb/server/vfs.h
index 21b0d29a3db0..8568184ff05b 100644
--- a/fs/smb/server/vfs.h
+++ b/fs/smb/server/vfs.h
@@ -164,8 +164,7 @@ int ksmbd_vfs_remove_sd_xattrs(const struct mnt_idmap *idmap, const struct path
int 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,
--
2.47.3