]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: Fix optional-arg mount options
authorEric Sandeen <sandeen@redhat.com>
Tue, 16 Feb 2010 01:17:55 +0000 (20:17 -0500)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 13 Aug 2010 20:20:18 +0000 (13:20 -0700)
commit 15121c18a22ae483279f76dc9e554334b800d0f7 upstream.

We have 2 mount options, "barrier" and "auto_da_alloc" which may or
may not take a 1/0 argument.  This causes the ext4 superblock mount
code to subtract uninitialized pointers and pass the result to
kmalloc, which results in very noisy failures.

Per Ted's suggestion, initialize the args struct so that
we know whether match_token() found an argument for the
option, and skip match_int() if not.

Also, return error (0) from parse_options if we thought
we found an argument, but match_int() Fails.

Reported-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Acked-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/ext4/super.c

index e820b936e1d0d980219feebc538e05098b82d6d3..f27e045df7a6e502c9d6d92389a8062eeb8a0e24 100644 (file)
@@ -1218,6 +1218,11 @@ static int parse_options(char *options, struct super_block *sb,
                if (!*p)
                        continue;
 
+               /*
+                * Initialize args struct so we know whether arg was
+                * found; some options take optional arguments.
+                */
+               args[0].to = args[0].from = 0;
                token = match_token(p, tokens, args);
                switch (token) {
                case Opt_bsd_df:
@@ -1503,10 +1508,11 @@ set_qf_format:
                        clear_opt(sbi->s_mount_opt, BARRIER);
                        break;
                case Opt_barrier:
-                       if (match_int(&args[0], &option)) {
-                               set_opt(sbi->s_mount_opt, BARRIER);
-                               break;
-                       }
+                       if (args[0].from) {
+                               if (match_int(&args[0], &option))
+                                       return 0;
+                       } else
+                               option = 1;     /* No argument, default to 1 */
                        if (option)
                                set_opt(sbi->s_mount_opt, BARRIER);
                        else
@@ -1579,10 +1585,11 @@ set_qf_format:
                        set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC);
                        break;
                case Opt_auto_da_alloc:
-                       if (match_int(&args[0], &option)) {
-                               clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC);
-                               break;
-                       }
+                       if (args[0].from) {
+                               if (match_int(&args[0], &option))
+                                       return 0;
+                       } else
+                               option = 1;     /* No argument, default to 1 */
                        if (option)
                                clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC);
                        else