affs: fix a memory leak in affs_remount
authorNavid Emamdoost <navid.emamdoost@gmail.com>
Wed, 2 Oct 2019 21:52:37 +0000 (16:52 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Jan 2020 18:48:50 +0000 (19:48 +0100)
commit 450c3d4166837c496ebce03650c08800991f2150 upstream.

In affs_remount if data is provided it is duplicated into new_opts.  The
allocated memory for new_opts is only released if parse_options fails.

There's a bit of history behind new_options, originally there was
save/replace options on the VFS layer so the 'data' passed must not
change (thus strdup), this got cleaned up in later patches. But not
completely.

There's no reason to do the strdup in cases where the filesystem does
not need to reuse the 'data' again, because strsep would modify it
directly.

Fixes: c8f33d0bec99 ("affs: kstrdup() memory handling")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/affs/super.c

index cc463ae..3812f7b 100644 (file)
@@ -561,14 +561,9 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        int                      root_block;
        unsigned long            mount_flags;
        int                      res = 0;
-       char                    *new_opts;
        char                     volume[32];
        char                    *prefix = NULL;
 
-       new_opts = kstrdup(data, GFP_KERNEL);
-       if (data && !new_opts)
-               return -ENOMEM;
-
        pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
 
        sync_filesystem(sb);
@@ -579,7 +574,6 @@ affs_remount(struct super_block *sb, int *flags, char *data)
                           &blocksize, &prefix, volume,
                           &mount_flags)) {
                kfree(prefix);
-               kfree(new_opts);
                return -EINVAL;
        }