Skip to content

Commit 1ead221

Browse files
neilbrownbrauner
authored andcommitted
smb/server: use end_removing_noperm for for target of smb2_create_link()
Sometimes smb2_create_link() needs to remove the target before creating the link. It uses ksmbd_vfs_kern_locked(), and is the only user of that interface. To match the new naming, that function is changed to ksmbd_vfs_kern_start_removing(), and related functions or flags are also renamed. The lock actually happens in ksmbd_vfs_path_lookup() and that is changed to use start_removing_noperm() - permission to perform lookup in the parent was already checked in vfs_path_parent_lookup(). Signed-off-by: NeilBrown <neil@brown.name> Link: https://patch.msgid.link/20251113002050.676694-8-neilb@ownmail.net Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent c9ba789 commit 1ead221

3 files changed

Lines changed: 19 additions & 22 deletions

File tree

fs/smb/server/smb2pdu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6084,8 +6084,8 @@ static int smb2_create_link(struct ksmbd_work *work,
60846084
}
60856085

60866086
ksmbd_debug(SMB, "target name is %s\n", target_name);
6087-
rc = ksmbd_vfs_kern_path_locked(work, link_name, LOOKUP_NO_SYMLINKS,
6088-
&path, 0);
6087+
rc = ksmbd_vfs_kern_path_start_removing(work, link_name, LOOKUP_NO_SYMLINKS,
6088+
&path, 0);
60896089
if (rc) {
60906090
if (rc != -ENOENT)
60916091
goto out;
@@ -6103,7 +6103,7 @@ static int smb2_create_link(struct ksmbd_work *work,
61036103
ksmbd_debug(SMB, "link already exists\n");
61046104
goto out;
61056105
}
6106-
ksmbd_vfs_kern_path_unlock(&path);
6106+
ksmbd_vfs_kern_path_end_removing(&path);
61076107
}
61086108
rc = ksmbd_vfs_link(work, target_name, link_name);
61096109
if (rc)

fs/smb/server/vfs.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int ksmbd_vfs_lock_parent(struct dentry *parent, struct dentry *child)
6969

7070
static int ksmbd_vfs_path_lookup(struct ksmbd_share_config *share_conf,
7171
char *pathname, unsigned int flags,
72-
struct path *path, bool do_lock)
72+
struct path *path, bool for_remove)
7373
{
7474
struct qstr last;
7575
struct filename *filename __free(putname) = NULL;
@@ -99,22 +99,20 @@ static int ksmbd_vfs_path_lookup(struct ksmbd_share_config *share_conf,
9999
return -ENOENT;
100100
}
101101

102-
if (do_lock) {
102+
if (for_remove) {
103103
err = mnt_want_write(path->mnt);
104104
if (err) {
105105
path_put(path);
106106
return -ENOENT;
107107
}
108108

109-
inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT);
110-
d = lookup_one_qstr_excl(&last, path->dentry, 0);
109+
d = start_removing_noperm(path->dentry, &last);
111110

112111
if (!IS_ERR(d)) {
113112
dput(path->dentry);
114113
path->dentry = d;
115114
return 0;
116115
}
117-
inode_unlock(path->dentry->d_inode);
118116
mnt_drop_write(path->mnt);
119117
path_put(path);
120118
return -ENOENT;
@@ -1207,15 +1205,15 @@ static int ksmbd_vfs_lookup_in_dir(const struct path *dir, char *name,
12071205
static
12081206
int __ksmbd_vfs_kern_path(struct ksmbd_work *work, char *filepath,
12091207
unsigned int flags,
1210-
struct path *path, bool caseless, bool do_lock)
1208+
struct path *path, bool caseless, bool for_remove)
12111209
{
12121210
struct ksmbd_share_config *share_conf = work->tcon->share_conf;
12131211
struct path parent_path;
12141212
size_t path_len, remain_len;
12151213
int err;
12161214

12171215
retry:
1218-
err = ksmbd_vfs_path_lookup(share_conf, filepath, flags, path, do_lock);
1216+
err = ksmbd_vfs_path_lookup(share_conf, filepath, flags, path, for_remove);
12191217
if (!err || !caseless)
12201218
return err;
12211219

@@ -1286,7 +1284,7 @@ int ksmbd_vfs_kern_path(struct ksmbd_work *work, char *filepath,
12861284
}
12871285

12881286
/**
1289-
* ksmbd_vfs_kern_path_locked() - lookup a file and get path info
1287+
* ksmbd_vfs_kern_path_start_remove() - lookup a file and get path info prior to removal
12901288
* @work: work
12911289
* @filepath: file path that is relative to share
12921290
* @flags: lookup flags
@@ -1298,20 +1296,19 @@ int ksmbd_vfs_kern_path(struct ksmbd_work *work, char *filepath,
12981296
* filesystem will have been gained.
12991297
* Return: 0 on if file was found, otherwise error
13001298
*/
1301-
int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *filepath,
1302-
unsigned int flags,
1303-
struct path *path, bool caseless)
1299+
int ksmbd_vfs_kern_path_start_removing(struct ksmbd_work *work, char *filepath,
1300+
unsigned int flags,
1301+
struct path *path, bool caseless)
13041302
{
13051303
return __ksmbd_vfs_kern_path(work, filepath, flags, path,
13061304
caseless, true);
13071305
}
13081306

1309-
void ksmbd_vfs_kern_path_unlock(const struct path *path)
1307+
void ksmbd_vfs_kern_path_end_removing(const struct path *path)
13101308
{
1311-
/* While lock is still held, ->d_parent is safe */
1312-
inode_unlock(d_inode(path->dentry->d_parent));
1309+
end_removing(path->dentry);
13131310
mnt_drop_write(path->mnt);
1314-
path_put(path);
1311+
mntput(path->mnt);
13151312
}
13161313

13171314
struct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work,

fs/smb/server/vfs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ int ksmbd_vfs_remove_xattr(struct mnt_idmap *idmap,
120120
int ksmbd_vfs_kern_path(struct ksmbd_work *work, char *name,
121121
unsigned int flags,
122122
struct path *path, bool caseless);
123-
int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
124-
unsigned int flags,
125-
struct path *path, bool caseless);
126-
void ksmbd_vfs_kern_path_unlock(const struct path *path);
123+
int ksmbd_vfs_kern_path_start_removing(struct ksmbd_work *work, char *name,
124+
unsigned int flags,
125+
struct path *path, bool caseless);
126+
void ksmbd_vfs_kern_path_end_removing(const struct path *path);
127127
struct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work,
128128
const char *name,
129129
unsigned int flags,

0 commit comments

Comments
 (0)