Re: [PATCH] ext4: fix NULL pointer dereference from orig_data infill_super and remount.

From: NamJae Jeon
Date: Sun Nov 06 2011 - 18:13:13 EST


2011/11/7 Srivatsa S. Bhat <srivatsa.bhat@xxxxxxxxxxxxxxxxxx>:
> On 11/06/2011 08:49 PM, Namjae Jeon wrote:
>> Fix NULL pointer dereference from orig_data in fill_super and remount.
>>
>> Signed-off-by: Namjae Jeon <linkinjeon@xxxxxxxxx>
>> ---
>> Âfs/ext4/super.c | Â 12 ++++++++++--
>> Â1 files changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index 9953d80..3770d3f 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -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;
>
> 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.
>
>> + Â Â }
>>
>> Â Â Â /* 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.
>
>> @@ -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.
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/