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: 7ad54b98fc ("cifs: use origin fullpath for automounts")
Cc: <stable@vger.kernel.org> # 6.2+
Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
Paulo Alcantara 2023-04-16 15:38:28 -03:00 коммит произвёл Steve French
Родитель 6a8f57ae2e
Коммит d5a863a153
2 изменённых файлов: 18 добавлений и 6 удалений

Просмотреть файл

@ -171,8 +171,6 @@ static struct vfsmount *cifs_dfs_do_automount(struct path *path)
mnt = ERR_CAST(full_path); mnt = ERR_CAST(full_path);
goto out; goto out;
} }
convert_delimiter(full_path, '/');
cifs_dbg(FYI, "%s: full_path: %s\n", __func__, full_path); cifs_dbg(FYI, "%s: full_path: %s\n", __func__, full_path);
tmp = *cur_ctx; tmp = *cur_ctx;

Просмотреть файл

@ -34,19 +34,33 @@ static inline int dfs_get_referral(struct cifs_mount_ctx *mnt_ctx, const char *p
cifs_remap(cifs_sb), path, ref, tl); cifs_remap(cifs_sb), path, ref, tl);
} }
/* Return DFS full path out of a dentry set for automount */
static inline char *dfs_get_automount_devname(struct dentry *dentry, void *page) static inline char *dfs_get_automount_devname(struct dentry *dentry, void *page)
{ {
struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb); struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
struct TCP_Server_Info *server = tcon->ses->server; struct TCP_Server_Info *server = tcon->ses->server;
size_t len;
char *s;
if (unlikely(!server->origin_fullpath)) if (unlikely(!server->origin_fullpath))
return ERR_PTR(-EREMOTE); return ERR_PTR(-EREMOTE);
return __build_path_from_dentry_optional_prefix(dentry, page, s = dentry_path_raw(dentry, page, PATH_MAX);
server->origin_fullpath, if (IS_ERR(s))
strlen(server->origin_fullpath), return s;
true); /* for root, we want "" */
if (!s[1])
s++;
len = strlen(server->origin_fullpath);
if (s < (char *)page + len)
return ERR_PTR(-ENAMETOOLONG);
s -= len;
memcpy(s, server->origin_fullpath, len);
convert_delimiter(s, '/');
return s;
} }
static inline void dfs_put_root_smb_sessions(struct list_head *head) static inline void dfs_put_root_smb_sessions(struct list_head *head)