ext4: fix NULL pointer dereference from orig_data in fill_super and remount.
PATCH 1/1 ext4: fix NULL pointer dereference from orig_data in fill_super and remount.
Fix NULL pointer dereference from orig_data in fill_super and remount.
--- fs/ext4/super.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
fs/ext4/super.c +10 -2
@@ -3102,7 +3102,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)__releases (kernel_lock)__acquires (kernel_lock ) { -char *orig_data =kstrdup (data,GFP_KERNEL );struct buffer_head *bh;struct ext4_super_block *es =NULL ;struct ext4_sb_info *sbi;
@@ -3124,6 +3123,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)int err;unsigned int journal_ioprio =DEFAULT_JOURNAL_IOPRIO ;ext4_group_t first_not_zeroed; + +char *orig_data =kstrdup (data,GFP_KERNEL ); +if (!orig_data) +return ret; sbi =kzalloc (sizeof (*sbi),GFP_KERNEL );if (!sbi)
@@ -4398,6 +4401,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)int i;#endif char *orig_data =kstrdup (data,GFP_KERNEL ); +if (!orig_data) { + err = -ENOMEM ; + goto failed_alloc_orig; + }/* Store the original options */ lock_super (sb);
@@ -4562,6 +4569,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)return 0 ; restore_opts: +kfree (orig_data); +failed_alloc_orig: sb->s_flags = old_sb_flags; sbi->s_mount_opt = old_opts.s_mount_opt; sbi->s_mount_opt2 = old_opts.s_mount_opt2;
@@ -4580,7 +4589,6 @@ restore_opts: }#endif unlock_super (sb); -kfree (orig_data);return err; }
Signature · 1 line
1.7.4.4
Quoted 31 lines · Namjae Jeon
Fix NULL pointer dereference from
orig_datainfill_superand remount.Signed-off-by Namjae Jeon <[email protected]>--- fs/ext4/super.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)fs/ext4/super.c +4
-1@@ -3102,7 +3102,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)__releases (kernel_lock)__acquires (kernel_lock ) { -char *orig_data =kstrdup (data,GFP_KERNEL );struct buffer_head *bh;struct ext4_super_block *es =NULL ;struct ext4_sb_info *sbi;@@ -3124,6 +3123,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)int err;unsigned int journal_ioprio =DEFAULT_JOURNAL_IOPRIO ;ext4_group_t first_not_zeroed; + +char *orig_data =kstrdup (data,GFP_KERNEL ); +if (!orig_data) +return ret; sbi =kzalloc (sizeof (*sbi),GFP_KERNEL );if (!sbi)
fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 4406
Quoted 6 lines
fs/ext4/super.c +3
-0@@ -4398,6 +4401,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)int i;#endif char *orig_data =kstrdup (data,GFP_KERNEL ); +if (!orig_data) { + err = -ENOMEM ; + goto failed_alloc_orig;
I didn't quite get why 'failed_alloc_orig' is needed here. Why can't we just return -ENOMEM? Anyway we haven't yet clobbered any opts at this point, right?
See my comments below.
fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 4576
Quoted 13 lines
fs/ext4/super.c +3
-0+ }/* Store the original options */ lock_super (sb);@@ -4562,6 +4569,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)return 0 ; restore_opts: +kfree (orig_data); +failed_alloc_orig: sb->s_flags = old_sb_flags; sbi->s_mount_opt = old_opts.s_mount_opt; sbi->s_mount_opt2 = old_opts.s_mount_opt2;
This would put garbage values in sb->... and sbi->... when we jump to 'failed_alloc_orig' upon 'orig_data' allocation failure, because the old_* variables were still uninitialized at that point.
fs/ext4/super.c restore_opts: · line 4594
Quoted 8 lines
fs/ext4/super.c +0
-1@@ -4580,7 +4589,6 @@ restore_opts: }#endif unlock_super (sb); -kfree (orig_data);return err; }
Thanks,
Srivatsa S. Bhat
2011/11/7 Srivatsa S. Bhat <[email protected]>:
Quoted 63 lines · Namjae Jeon
Quoted 31 lines
Fix NULL pointer dereference from
orig_datainfill_superand remount.Signed-off-by Namjae Jeon <[email protected]>---
fs/ext4/super.c | 12 ++++++++++--1 files changed, 10 insertions(+), 2 deletions(-)fs/ext4/super.c +4
-1@@ -3102,7 +3102,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) __releases(kernel_lock) __acquires(kernel_lock) { - char *orig_data = kstrdup(data, GFP_KERNEL); struct buffer_head *bh; struct ext4_super_block *es = NULL; struct ext4_sb_info *sbi;@@ -3124,6 +3123,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) int err; unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; ext4_group_t first_not_zeroed; + + char *orig_data = kstrdup(data, GFP_KERNEL); + if (!orig_data) + return ret; sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi)fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 4406
Quoted 6 lines
fs/ext4/super.c +3
-0@@ -4398,6 +4401,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) int i; #endif char *orig_data = kstrdup(data, GFP_KERNEL); + if (!orig_data) { + err = -ENOMEM; + goto failed_alloc_orig;I didn't quite get why '
failed_alloc_orig' is needed here. Why can't we just return-ENOMEM? Anyway we haven't yet clobbered any opts at this point, right?See my comments below.
Quoted 7 lines
fs/ext4/super.c +1
-0+ } /* Store the original options */ lock_super(sb);@@ -4562,6 +4569,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) return 0;Quoted 6 lines
restore_opts:
+kfree(orig_data);
+failed_alloc_orig:
sb->s_flags=old_sb_flags;
sbi->s_mount_opt= old_opts.s_mount_opt;
sbi->s_mount_opt2= old_opts.s_mount_opt2;This would put garbage values in sb->... and sbi->... when we jump to '
failed_alloc_orig' upon 'orig_data' allocation failure, because the old_* variables were still uninitialized at that point.
Quoted 11 lines
fs/ext4/super.c restore_opts: · line 4594
Quoted 8 lines
fs/ext4/super.c +0
-1@@ -4580,7 +4589,6 @@ restore_opts: } #endif unlock_super(sb); - kfree(orig_data); return err; }Thanks,
Srivatsa S. Bhat
Hi.
Thanks for your review. It's my mistake.
I will post patch v2 after modifing again.
Quoted 2 lines
Quoted 75 lines · NamJae Jeon
2011/11/7 Srivatsa S. Bhat <[email protected]>:
Quoted 63 lines · Namjae Jeon
Quoted 31 lines
Fix NULL pointer dereference from
orig_datainfill_superand remount.Signed-off-by Namjae Jeon <[email protected]>--- fs/ext4/super.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)fs/ext4/super.c +4
-1@@ -3102,7 +3102,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)__releases (kernel_lock)__acquires (kernel_lock ) { -char *orig_data =kstrdup (data,GFP_KERNEL );struct buffer_head *bh;struct ext4_super_block *es =NULL ;struct ext4_sb_info *sbi;@@ -3124,6 +3123,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)int err;unsigned int journal_ioprio =DEFAULT_JOURNAL_IOPRIO ;ext4_group_t first_not_zeroed; + +char *orig_data =kstrdup (data,GFP_KERNEL ); +if (!orig_data) +return ret; sbi =kzalloc (sizeof (*sbi),GFP_KERNEL );if (!sbi)fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 4406
Quoted 6 lines
fs/ext4/super.c +3
-0@@ -4398,6 +4401,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)int i;#endif char *orig_data =kstrdup (data,GFP_KERNEL ); +if (!orig_data) { + err = -ENOMEM ; + goto failed_alloc_orig;I didn't quite get why '
failed_alloc_orig' is needed here. Why can't we just return-ENOMEM? Anyway we haven't yet clobbered any opts at this point, right?See my comments below.
fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 4576
Quoted 13 lines
fs/ext4/super.c +3
-0+ }/* Store the original options */ lock_super (sb);@@ -4562,6 +4569,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)return 0 ; restore_opts: +kfree (orig_data); +failed_alloc_orig: sb->s_flags = old_sb_flags; sbi->s_mount_opt = old_opts.s_mount_opt; sbi->s_mount_opt2 = old_opts.s_mount_opt2;This would put garbage values in sb->... and sbi->... when we jump to '
failed_alloc_orig' upon 'orig_data' allocation failure, because the old_* variables were still uninitialized at that point.Quoted 11 lines
fs/ext4/super.c restore_opts: · line 4594
Quoted 8 lines
fs/ext4/super.c +0
-1@@ -4580,7 +4589,6 @@ restore_opts: }#endif unlock_super (sb); -kfree (orig_data);return err; }Thanks,
Srivatsa S. Bhat
Quoted 3 lines
Hi.
Thanks for your review. It's my mistake.
I will post patch v2 after modifing again.
Sure. And please CC [email protected] for ext4 related patches.
Thanks,
Srivatsa S. Bhat