Skip to content

Commit d5a863a

Browse files
Paulo Alcantarasmfrench
authored andcommitted
cifs: avoid dup prefix path in dfs_get_automount_devname()
@server->origin_fullpath already contains the tree name + optional prefix, so avoid calling __build_path_from_dentry_optional_prefix() as it might end up duplicating prefix path from @cifs_sb->prepath into final full path. Instead, generate DFS full path by simply merging @server->origin_fullpath with dentry's path. This fixes the following case mount.cifs //root/dfs/dir /mnt/ -o ... ls /mnt/link where cifs_dfs_do_automount() will call smb3_parse_devname() with @devname set to "//root/dfs/dir/link" instead of "//root/dfs/dir/dir/link". Fixes: 7ad54b9 ("cifs: use origin fullpath for automounts") Cc: <[email protected]> # 6.2+ Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 6a8f57a commit d5a863a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

fs/cifs/cifs_dfs_ref.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ static struct vfsmount *cifs_dfs_do_automount(struct path *path)
171171
mnt = ERR_CAST(full_path);
172172
goto out;
173173
}
174-
175-
convert_delimiter(full_path, '/');
176174
cifs_dbg(FYI, "%s: full_path: %s\n", __func__, full_path);
177175

178176
tmp = *cur_ctx;

fs/cifs/dfs.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,33 @@ static inline int dfs_get_referral(struct cifs_mount_ctx *mnt_ctx, const char *p
3434
cifs_remap(cifs_sb), path, ref, tl);
3535
}
3636

37+
/* Return DFS full path out of a dentry set for automount */
3738
static inline char *dfs_get_automount_devname(struct dentry *dentry, void *page)
3839
{
3940
struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
4041
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
4142
struct TCP_Server_Info *server = tcon->ses->server;
43+
size_t len;
44+
char *s;
4245

4346
if (unlikely(!server->origin_fullpath))
4447
return ERR_PTR(-EREMOTE);
4548

46-
return __build_path_from_dentry_optional_prefix(dentry, page,
47-
server->origin_fullpath,
48-
strlen(server->origin_fullpath),
49-
true);
49+
s = dentry_path_raw(dentry, page, PATH_MAX);
50+
if (IS_ERR(s))
51+
return s;
52+
/* for root, we want "" */
53+
if (!s[1])
54+
s++;
55+
56+
len = strlen(server->origin_fullpath);
57+
if (s < (char *)page + len)
58+
return ERR_PTR(-ENAMETOOLONG);
59+
60+
s -= len;
61+
memcpy(s, server->origin_fullpath, len);
62+
convert_delimiter(s, '/');
63+
return s;
5064
}
5165

5266
static inline void dfs_put_root_smb_sessions(struct list_head *head)

0 commit comments

Comments
 (0)