affs: fix remount failure when there are no options changed
authorMikulas Patocka <mikulas@twibright.com>
Tue, 24 May 2016 20:48:33 +0000 (22:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Jun 2016 01:14:32 +0000 (18:14 -0700)
commit 01d6e08711bf90bc4d7ead14a93a0cbd73b1896a upstream.

Commit c8f33d0bec99 ("affs: kstrdup() memory handling") checks if the
kstrdup function returns NULL due to out-of-memory condition.

However, if we are remounting a filesystem with no change to
filesystem-specific options, the parameter data is NULL.  In this case,
kstrdup returns NULL (because it was passed NULL parameter), although no
out of memory condition exists.  The mount syscall then fails with
ENOMEM.

This patch fixes the bug.  We fail with ENOMEM only if data is non-NULL.

The patch also changes the call to replace_mount_options - if we didn't
pass any filesystem-specific options, we don't call
replace_mount_options (thus we don't erase existing reported options).

Fixes: c8f33d0bec99 ("affs: kstrdup() memory handling")
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/affs/super.c

index 5b50c4ca43a7dde6ce48049f365a9988da23449b..f90c535703cec8c5965ff73d487ce3ec6350061d 100644 (file)
@@ -528,7 +528,7 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        char                    *prefix = NULL;
 
        new_opts = kstrdup(data, GFP_KERNEL);
-       if (!new_opts)
+       if (data && !new_opts)
                return -ENOMEM;
 
        pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
@@ -546,7 +546,8 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        }
 
        flush_delayed_work(&sbi->sb_work);
-       replace_mount_options(sb, new_opts);
+       if (new_opts)
+               replace_mount_options(sb, new_opts);
 
        sbi->s_flags = mount_flags;
        sbi->s_mode  = mode;