]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
cifs: fix regression when mounting shares with prefix paths
authorPaulo Alcantara <pc@cjr.nz>
Mon, 3 May 2021 14:55:26 +0000 (11:55 -0300)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 19 May 2021 08:31:56 +0000 (10:31 +0200)
BugLink: https://bugs.launchpad.net/bugs/1928857
commit 5c1acf3fe05ce443edba5e2110c9e581765f66a8 upstream.

The commit 315db9a05b7a ("cifs: fix leak in cifs_smb3_do_mount() ctx")
revealed an existing bug when mounting shares that contain a prefix
path or DFS links.

cifs_setup_volume_info() requires the @devname to contain the full
path (UNC + prefix) to update the fs context with the new UNC and
prepath values, however we were passing only the UNC
path (old_ctx->UNC) in @device thus discarding any prefix paths.

Instead of concatenating both old_ctx->{UNC,prepath} and pass it in
@devname, just keep the dup'ed values of UNC and prepath in
cifs_sb->ctx after calling smb3_fs_context_dup(), and fix
smb3_parse_devname() to correctly parse and not leak the new UNC and
prefix paths.

Cc: <stable@vger.kernel.org> # v5.11+
Fixes: 315db9a05b7a ("cifs: fix leak in cifs_smb3_do_mount() ctx")
Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Acked-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
fs/cifs/cifsfs.c
fs/cifs/connect.c
fs/cifs/fs_context.c

index 30417968fdadf2e846d9feabdf62053bcb97e0d4..1cb803a55f3a5e90b96b28f90f0844a02a0ee155 100644 (file)
@@ -823,13 +823,7 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
                goto out;
        }
 
-       /* cifs_setup_volume_info->smb3_parse_devname() redups UNC & prepath */
-       kfree(cifs_sb->ctx->UNC);
-       cifs_sb->ctx->UNC = NULL;
-       kfree(cifs_sb->ctx->prepath);
-       cifs_sb->ctx->prepath = NULL;
-
-       rc = cifs_setup_volume_info(cifs_sb->ctx, NULL, old_ctx->UNC);
+       rc = cifs_setup_volume_info(cifs_sb->ctx, NULL, NULL);
        if (rc) {
                root = ERR_PTR(rc);
                goto out;
index 832b8b5b44370c3611e361938ae90a1b3c4cf168..ee8faaa9e69aff4b2dc4c30489d0cca3eaf53bd5 100644 (file)
@@ -3150,17 +3150,29 @@ out:
 int
 cifs_setup_volume_info(struct smb3_fs_context *ctx, const char *mntopts, const char *devname)
 {
-       int rc = 0;
+       int rc;
 
-       smb3_parse_devname(devname, ctx);
+       if (devname) {
+               cifs_dbg(FYI, "%s: devname=%s\n", __func__, devname);
+               rc = smb3_parse_devname(devname, ctx);
+               if (rc) {
+                       cifs_dbg(VFS, "%s: failed to parse %s: %d\n", __func__, devname, rc);
+                       return rc;
+               }
+       }
 
        if (mntopts) {
                char *ip;
 
-               cifs_dbg(FYI, "%s: mntopts=%s\n", __func__, mntopts);
                rc = smb3_parse_opt(mntopts, "ip", &ip);
-               if (!rc && !cifs_convert_address((struct sockaddr *)&ctx->dstaddr, ip,
-                                                strlen(ip))) {
+               if (rc) {
+                       cifs_dbg(VFS, "%s: failed to parse ip options: %d\n", __func__, rc);
+                       return rc;
+               }
+
+               rc = cifs_convert_address((struct sockaddr *)&ctx->dstaddr, ip, strlen(ip));
+               kfree(ip);
+               if (!rc) {
                        cifs_dbg(VFS, "%s: failed to convert ip address\n", __func__);
                        return -EINVAL;
                }
@@ -3180,7 +3192,7 @@ cifs_setup_volume_info(struct smb3_fs_context *ctx, const char *mntopts, const c
                return -EINVAL;
        }
 
-       return rc;
+       return 0;
 }
 
 static int
index 3a26ad47b220c3abc4d9269fced094d1f730134a..73f14a13d37b261e1468e759bf56b931eefb6c22 100644 (file)
@@ -473,6 +473,7 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
 
        /* move "pos" up to delimiter or NULL */
        pos += len;
+       kfree(ctx->UNC);
        ctx->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
        if (!ctx->UNC)
                return -ENOMEM;
@@ -483,6 +484,9 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
        if (*pos == '/' || *pos == '\\')
                pos++;
 
+       kfree(ctx->prepath);
+       ctx->prepath = NULL;
+
        /* If pos is NULL then no prepath */
        if (!*pos)
                return 0;