From: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
To: NamJae Jeon <linkinjeon@gmail.com>
Cc: tytso@mit.edu, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: Re: [PATCH] ext4: fix NULL pointer dereference from orig_data in fill_super and remount.
Date: Mon, 07 Nov 2011 04:50:34 +0530 [thread overview]
Message-ID: <4EB71642.8070502@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAKYAXd87ry6D4xsBwkXC4at6kDZgHu=_Qa+0kdhEsN=RSMk1ag@mail.gmail.com>
On 11/07/2011 04:43 AM, NamJae Jeon wrote:
> 2011/11/7 Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>:
>> 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@gmail.com>
>>> ---
>>> 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.
Sure. And please CC linux-ext4@vger.kernel.org for ext4 related patches.
Thanks,
Srivatsa S. Bhat
parent reply other threads:[~2011-11-06 23:20 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <CAKYAXd87ry6D4xsBwkXC4at6kDZgHu=_Qa+0kdhEsN=RSMk1ag@mail.gmail.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EB71642.8070502@linux.vnet.ibm.com \
--to=srivatsa.bhat@linux.vnet.ibm.com \
--cc=linkinjeon@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).