Skip to contentSkip to conversation

smb: client: convert DFS target node name from cache charset on mount

PATCH In review Fredric Cover 2 participants 5 messages Nov 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smb: client: convert DFS target node name from cache charset on mount

parse_dfs_target() converts @path_consumed to the mount charset using dfs_consumed_to_local(), but @ref->node_name from the DFS referral cache is still encoded in UTF-8 (cache_cp).

In dfs_parse_target_referral(), passing @ref->node_name directly to cifs_build_devname() and smb3_parse_devname() copies UTF-8 bytes into ctx->UNC and ctx->prepath (and mixes encodings when @prepath from @full_path is also non-empty). On mounts using a non-UTF-8 iocharset such as iso8859-1, subsequent path checks re-encode these strings to UTF-16LE using local_nls, corrupting non-ASCII characters on the wire and causing initial mount to fail with -ENOENT.

Convert @ref->node_name from cache_cp to ctx->local_nls with dfs_cache_local_path() before building the device name so ctx->UNC and ctx->prepath stay in the mount charset.

Tested against Samba with iocharset=iso8859-1 and iocharset=utf8 for both DFS link referrals with a non-ASCII target subpath and mounts with an additional non-ASCII prepath, including reconnects.

Fixes c870a8e70e68 ("cifs: handle different charsets in dfs cache")
Cc [email protected] # depends on: smb: client: convert DFS prefix from cache charset on reconnect

---
Note: Applies on top of "smb: client: convert DFS prefix from cache charset on reconnect".

---
 fs/smb/client/dfs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/client/dfs.c +7 -1
index efef00c33321..6b212e49cf92 100644
@@ -25,6 +25,7 @@ int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_para
 {
 	int rc;
 	const char *prepath = NULL;
+	char *node_name = NULL;
 	char *path;
 
 	if (!full_path || !*full_path || !ref || !ctx)
@@ -40,7 +41,12 @@ int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_para
 			prepath++;
 	}
 
-	path = cifs_build_devname(ref->node_name, prepath);
+	node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
+	if (IS_ERR(node_name))
+		return PTR_ERR(node_name);
+
+	path = cifs_build_devname(node_name, prepath);
+	kfree(node_name);
 	if (IS_ERR(path))
 		return PTR_ERR(path);
 
Signature · 1 line
2.53.0
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Fredric,

kernel test robot noticed the following build warnings:

[auto build test WARNING on manguebit/cifs-next]
[also build test WARNING on manguebit/cifs-fixes linus/master v7.4-rc3 next-20261120] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Fredric-Cover/smb-client-convert-DFS-target-node-name-from-cache-charset-on-mount/20261122-045840
base:   https://git.manguebit.org/linux.git cifs-next
patch link:    https://lore.kernel.org/r/20261122045841.99012-1-fredric.cover.lkernel%40gmail.com
patch subject: [PATCH] smb: client: convert DFS target node name from cache charset on mount
config: xtensa-randconfig-1000-20261122 (https://download.01.org/0day-ci/archive/20261122/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

fs/smb/client/dfs.c: In function 'dfs_parse_target_referral':
fs/smb/client/dfs.c:44:14: error: implicit declaration of function 'dfs_cache_local_path'; did you mean 'dfs_cache_canonical_path'? [-Werror=implicit-function-declaration]

     node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
                 ^~~~~~~~~~~~~~~~~~~~
                 dfs_cache_canonical_path
>> fs/smb/client/dfs.c:44:12: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
               ^

cc1: some warnings being treated as errors

vim +44 fs/smb/client/dfs.c

    13	
    14	/**
    15	 * dfs_parse_target_referral - set fs context for dfs target referral
    16	 *
    17	 * @full_path: full path in UNC format.
    18	 * @ref: dfs referral pointer.
    19	 * @ctx: smb3 fs context pointer.
    20	 *
    21	 * Return zero if dfs referral was parsed correctly, otherwise non-zero.
    22	 */
    23	int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref,
    24				      struct smb3_fs_context *ctx)
    25	{
    26		int rc;
    27		const char *prepath = NULL;
    28		char *node_name = NULL;
    29		char *path;
    30	
    31		if (!full_path || !*full_path || !ref || !ctx)
    32			return -EINVAL;
    33	
    34		if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0))
    35			return -EINVAL;
    36	
    37		if ((size_t)ref->path_consumed < strlen(full_path)) {
    38			prepath = full_path + ref->path_consumed;
    39			/* skip initial delimiter */
    40			if (*prepath == '/' || *prepath == '\\')
    41				prepath++;
    42		}
    43	
  > 44		node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
    45		if (IS_ERR(node_name))
    46			return PTR_ERR(node_name);
    47	
    48		path = cifs_build_devname(node_name, prepath);
    49		kfree(node_name);
    50		if (IS_ERR(path))
    51			return PTR_ERR(path);
    52	
    53		rc = smb3_parse_devname(path, ctx);
    54		if (rc)
    55			goto out;
    56	
    57		rc = dns_resolve_unc(DFS_DOM(ctx), path,
    58				     (struct sockaddr *)&ctx->dstaddr);
    59	out:
    60		kfree(path);
    61		return rc;
    62	}
    63	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Fredric Cover
kernel test robot noticed the following build errors:

Hi Fredric,

kernel test robot noticed the following build errors:

[auto build test ERROR on manguebit/cifs-next]
[also build test ERROR on manguebit/cifs-fixes linus/master v7.4-rc3 next-20261120] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Fredric-Cover/smb-client-convert-DFS-target-node-name-from-cache-charset-on-mount/20261122-045840
base:   https://git.manguebit.org/linux.git cifs-next
patch link:    https://lore.kernel.org/r/20261122045841.99012-1-fredric.cover.lkernel%40gmail.com
patch subject: [PATCH] smb: client: convert DFS target node name from cache charset on mount
config: s390-defconfig (https://download.01.org/0day-ci/archive/20261122/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> fs/smb/client/dfs.c:44:14: error: call to undeclared function 'dfs_cache_local_path'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      44 |         node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
         |                     ^
   fs/smb/client/dfs.c:44:14: note: did you mean 'dfs_cache_canonical_path'?
   fs/smb/client/dfs_cache.h:54:7: note: 'dfs_cache_canonical_path' declared here
      54 | char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp,
         |       ^
>> fs/smb/client/dfs.c:44:12: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
      44 |         node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
         |                   ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2 errors generated.

vim +/dfs_cache_local_path +44 fs/smb/client/dfs.c

    13	
    14	/**
    15	 * dfs_parse_target_referral - set fs context for dfs target referral
    16	 *
    17	 * @full_path: full path in UNC format.
    18	 * @ref: dfs referral pointer.
    19	 * @ctx: smb3 fs context pointer.
    20	 *
    21	 * Return zero if dfs referral was parsed correctly, otherwise non-zero.
    22	 */
    23	int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref,
    24				      struct smb3_fs_context *ctx)
    25	{
    26		int rc;
    27		const char *prepath = NULL;
    28		char *node_name = NULL;
    29		char *path;
    30	
    31		if (!full_path || !*full_path || !ref || !ctx)
    32			return -EINVAL;
    33	
    34		if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0))
    35			return -EINVAL;
    36	
    37		if ((size_t)ref->path_consumed < strlen(full_path)) {
    38			prepath = full_path + ref->path_consumed;
    39			/* skip initial delimiter */
    40			if (*prepath == '/' || *prepath == '\\')
    41				prepath++;
    42		}
    43	
  > 44		node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
    45		if (IS_ERR(node_name))
    46			return PTR_ERR(node_name);
    47	
    48		path = cifs_build_devname(node_name, prepath);
    49		kfree(node_name);
    50		if (IS_ERR(path))
    51			return PTR_ERR(path);
    52	
    53		rc = smb3_parse_devname(path, ctx);
    54		if (rc)
    55			goto out;
    56	
    57		rc = dns_resolve_unc(DFS_DOM(ctx), path,
    58				     (struct sockaddr *)&ctx->dstaddr);
    59	out:
    60		kfree(path);
    61		return rc;
    62	}
    63	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Fredric Cover
kernel test robot noticed the following build errors:

Hi Fredric,

kernel test robot noticed the following build errors:

[auto build test ERROR on manguebit/cifs-next]
[also build test ERROR on manguebit/cifs-fixes linus/master v7.4-rc3 next-20261120] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Fredric-Cover/smb-client-convert-DFS-target-node-name-from-cache-charset-on-mount/20261122-045840
base:   https://git.manguebit.org/linux.git cifs-next
patch link:    https://lore.kernel.org/r/20261122045841.99012-1-fredric.cover.lkernel%40gmail.com
patch subject: [PATCH] smb: client: convert DFS target node name from cache charset on mount
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261122/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

fs/smb/client/dfs.c: In function 'dfs_parse_target_referral':

>> fs/smb/client/dfs.c:44:21: error: implicit declaration of function 'dfs_cache_local_path'; did you mean 'dfs_cache_canonical_path'? [-Wimplicit-function-declaration]
      44 |         node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
         |                     ^~~~~~~~~~~~~~~~~~~~
         |                     dfs_cache_canonical_path
>> fs/smb/client/dfs.c:44:19: error: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
      44 |         node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
         |                   ^

vim +44 fs/smb/client/dfs.c

    13	
    14	/**
    15	 * dfs_parse_target_referral - set fs context for dfs target referral
    16	 *
    17	 * @full_path: full path in UNC format.
    18	 * @ref: dfs referral pointer.
    19	 * @ctx: smb3 fs context pointer.
    20	 *
    21	 * Return zero if dfs referral was parsed correctly, otherwise non-zero.
    22	 */
    23	int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref,
    24				      struct smb3_fs_context *ctx)
    25	{
    26		int rc;
    27		const char *prepath = NULL;
    28		char *node_name = NULL;
    29		char *path;
    30	
    31		if (!full_path || !*full_path || !ref || !ctx)
    32			return -EINVAL;
    33	
    34		if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0))
    35			return -EINVAL;
    36	
    37		if ((size_t)ref->path_consumed < strlen(full_path)) {
    38			prepath = full_path + ref->path_consumed;
    39			/* skip initial delimiter */
    40			if (*prepath == '/' || *prepath == '\\')
    41				prepath++;
    42		}
    43	
  > 44		node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
    45		if (IS_ERR(node_name))
    46			return PTR_ERR(node_name);
    47	
    48		path = cifs_build_devname(node_name, prepath);
    49		kfree(node_name);
    50		if (IS_ERR(path))
    51			return PTR_ERR(path);
    52	
    53		rc = smb3_parse_devname(path, ctx);
    54		if (rc)
    55			goto out;
    56	
    57		rc = dns_resolve_unc(DFS_DOM(ctx), path,
    58				     (struct sockaddr *)&ctx->dstaddr);
    59	out:
    60		kfree(path);
    61		return rc;
    62	}
    63	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Paulo and list,
Please ignore these build errors. They are due to the dependency on my other patch. If you would like, I can put them both in a series to avoid errors like this.

Thanks,
Fredric

Quoted 93 lines · kernel test robot

Hi Fredric,

kernel test robot noticed the following build errors:

[auto build test ERROR on manguebit/cifs-next]
[also build test ERROR on manguebit/cifs-fixes linus/master v7.4-rc3 next-20261120] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Fredric-Cover/smb-client-convert-DFS-target-node-name-from-cache-charset-on-mount/20261122-045840
base:   https://git.manguebit.org/linux.git cifs-next
patch link:    https://lore.kernel.org/r/20261122045841.99012-1-fredric.cover.lkernel%40gmail.com
patch subject: [PATCH] smb: client: convert DFS target node name from cache charset on mount
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261122/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

fs/smb/client/dfs.c: In function 'dfs_parse_target_referral':

Quoted 1 line
Quoted 1 line

fs/smb/client/dfs.c:44:21: error: implicit declaration of function 'dfs_cache_local_path'; did you mean 'dfs_cache_canonical_path'? [-Wimplicit-function-declaration]

      44 |         node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
         |                     ^~~~~~~~~~~~~~~~~~~~
         |                     dfs_cache_canonical_path
Quoted 1 line
Quoted 1 line

fs/smb/client/dfs.c:44:19: error: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]

      44 |         node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);
         |                   ^

vim +44 fs/smb/client/dfs.c

    13
    14  /**
    15   * dfs_parse_target_referral - set fs context for dfs target referral
    16   *
    17   * @full_path: full path in UNC format.
    18   * @ref: dfs referral pointer.
    19   * @ctx: smb3 fs context pointer.
    20   *
    21   * Return zero if dfs referral was parsed correctly, otherwise non-zero.
    22   */
    23  int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref,
    24                                struct smb3_fs_context *ctx)
    25  {
    26          int rc;
    27          const char *prepath = NULL;
    28          char *node_name = NULL;
    29          char *path;
    30
    31          if (!full_path || !*full_path || !ref || !ctx)
    32                  return -EINVAL;
    33
    34          if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0))
    35                  return -EINVAL;
    36
    37          if ((size_t)ref->path_consumed < strlen(full_path)) {
    38                  prepath = full_path + ref->path_consumed;
    39                  /* skip initial delimiter */
    40                  if (*prepath == '/' || *prepath == '\\')
    41                          prepath++;
    42          }
    43
Quoted 1 line

44 node_name = dfs_cache_local_path(ref->node_name, ctx->local_nls);

    45          if (IS_ERR(node_name))
    46                  return PTR_ERR(node_name);
    47
    48          path = cifs_build_devname(node_name, prepath);
    49          kfree(node_name);
    50          if (IS_ERR(path))
    51                  return PTR_ERR(path);
    52
    53          rc = smb3_parse_devname(path, ctx);
    54          if (rc)
    55                  goto out;
    56
    57          rc = dns_resolve_unc(DFS_DOM(ctx), path,
    58                               (struct sockaddr *)&ctx->dstaddr);
    59  out:
    60          kfree(path);
    61          return rc;
    62  }
    63

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki