Skip to content

Commit f08b3f4

Browse files
namjaejeongregkh
authored andcommitted
ksmbd: use opener credentials for delete-on-close
commit 52e2f21 upstream. Delete-on-close can be completed by deferred or durable handle teardown, where no request work is available. Both the base-file unlink and the ADS xattr removal consequently run with the ksmbd worker credentials and can bypass filesystem permission checks. Run both operations with the credentials captured in struct file when the handle was opened. This preserves the authenticated user's fsuid, fsgid, supplementary groups and capability restrictions at final close. Cc: stable@vger.kernel.org Reported-by: Musaab Khan <musaab.khan@protonmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2b9d2a3 commit f08b3f4

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

fs/smb/server/vfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,13 +1084,15 @@ int ksmbd_vfs_remove_xattr(struct mnt_idmap *idmap,
10841084

10851085
int ksmbd_vfs_unlink(struct file *filp)
10861086
{
1087+
const struct cred *saved_cred;
10871088
int err = 0;
10881089
struct dentry *dir, *dentry = filp->f_path.dentry;
10891090
struct mnt_idmap *idmap = file_mnt_idmap(filp);
10901091

1092+
saved_cred = override_creds(filp->f_cred);
10911093
err = mnt_want_write(filp->f_path.mnt);
10921094
if (err)
1093-
return err;
1095+
goto out_revert;
10941096

10951097
dir = dget_parent(dentry);
10961098
err = ksmbd_vfs_lock_parent(dir, dentry);
@@ -1110,7 +1112,8 @@ int ksmbd_vfs_unlink(struct file *filp)
11101112
out:
11111113
dput(dir);
11121114
mnt_drop_write(filp->f_path.mnt);
1113-
1115+
out_revert:
1116+
revert_creds(saved_cred);
11141117
return err;
11151118
}
11161119

fs/smb/server/vfs_cache.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ static void __ksmbd_inode_close(struct ksmbd_file *fp)
292292
up_write(&ci->m_lock);
293293

294294
if (remove_stream_xattr) {
295+
const struct cred *saved_cred;
296+
297+
saved_cred = override_creds(filp->f_cred);
295298
err = ksmbd_vfs_remove_xattr(file_mnt_idmap(filp),
296299
&filp->f_path,
297300
fp->stream.name,
298301
true);
302+
revert_creds(saved_cred);
299303
if (err)
300304
pr_err("remove xattr failed : %s\n",
301305
fp->stream.name);

0 commit comments

Comments
 (0)