Skip to content

Commit 5e2fd17

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: fix mount when dns_resolver key is not available
There was a wrong assumption that with CONFIG_CIFS_DFS_UPCALL=y there would always be a dns_resolver key set up so we could unconditionally upcall to resolve UNC hostname rather than using the value provided by mount(2). Only require it when performing automount of junctions within a DFS share so users that don't have dns_resolver key still can mount their regular shares with server hostname resolved by mount.cifs(8). Fixes: 348a04a ("smb: client: get rid of dfs code dep in namespace.c") Cc: [email protected] Tested-by: Eduard Bachmakov <[email protected]> Reported-by: Eduard Bachmakov <[email protected]> Closes: https://lore.kernel.org/all/CADCRUiNvZuiUZ0VGZZO9HRyPyw6x92kiA7o7Q4tsX5FkZqUkKg@mail.gmail.com/ Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 5923d66 commit 5e2fd17

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

fs/smb/client/dfs.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,23 @@ static int __dfs_mount_share(struct cifs_mount_ctx *mnt_ctx)
263263
return rc;
264264
}
265265

266-
/* Resolve UNC hostname in @ctx->source and set ip addr in @ctx->dstaddr */
266+
/*
267+
* If @ctx->dfs_automount, then update @ctx->dstaddr earlier with the DFS root
268+
* server from where we'll start following any referrals. Otherwise rely on the
269+
* value provided by mount(2) as the user might not have dns_resolver key set up
270+
* and therefore failing to upcall to resolve UNC hostname under @ctx->source.
271+
*/
267272
static int update_fs_context_dstaddr(struct smb3_fs_context *ctx)
268273
{
269274
struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr;
270-
int rc;
275+
int rc = 0;
271276

272-
rc = dns_resolve_server_name_to_ip(ctx->source, addr, NULL);
273-
if (!rc)
274-
cifs_set_port(addr, ctx->port);
277+
if (!ctx->nodfs && ctx->dfs_automount) {
278+
rc = dns_resolve_server_name_to_ip(ctx->source, addr, NULL);
279+
if (!rc)
280+
cifs_set_port(addr, ctx->port);
281+
ctx->dfs_automount = false;
282+
}
275283
return rc;
276284
}
277285

fs/smb/client/fs_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ struct smb3_fs_context {
268268
bool witness:1; /* use witness protocol */
269269
char *leaf_fullpath;
270270
struct cifs_ses *dfs_root_ses;
271+
bool dfs_automount:1; /* set for dfs automount only */
271272
};
272273

273274
extern const struct fs_parameter_spec smb3_fs_parameters[];

fs/smb/client/namespace.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ cifs_build_devname(char *nodename, const char *prepath)
117117
return dev;
118118
}
119119

120+
static bool is_dfs_mount(struct dentry *dentry)
121+
{
122+
struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
123+
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
124+
bool ret;
125+
126+
spin_lock(&tcon->tc_lock);
127+
ret = !!tcon->origin_fullpath;
128+
spin_unlock(&tcon->tc_lock);
129+
return ret;
130+
}
131+
120132
/* Return full path out of a dentry set for automount */
121133
static char *automount_fullpath(struct dentry *dentry, void *page)
122134
{
@@ -212,8 +224,9 @@ static struct vfsmount *cifs_do_automount(struct path *path)
212224
ctx->source = NULL;
213225
goto out;
214226
}
215-
cifs_dbg(FYI, "%s: ctx: source=%s UNC=%s prepath=%s\n",
216-
__func__, ctx->source, ctx->UNC, ctx->prepath);
227+
ctx->dfs_automount = is_dfs_mount(mntpt);
228+
cifs_dbg(FYI, "%s: ctx: source=%s UNC=%s prepath=%s dfs_automount=%d\n",
229+
__func__, ctx->source, ctx->UNC, ctx->prepath, ctx->dfs_automount);
217230

218231
mnt = fc_mount(fc);
219232
out:

0 commit comments

Comments
 (0)