From: "Jun'ichi Nomura" <j-nomura@ce.jp.nec.com>
To: Vivek Goyal <vgoyal@redhat.com>, Tejun Heo <tj@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Fix use-after-free of q->root_blkg and q->root_rl.blkg
Date: Thu, 18 Oct 2012 11:56:34 +0900 [thread overview]
Message-ID: <507F6FE2.3030303@ce.jp.nec.com> (raw)
In-Reply-To: <20121017134704.GB31663@redhat.com>
On 10/17/12 22:47, Vivek Goyal wrote:
> On Wed, Oct 17, 2012 at 09:02:22AM +0900, Jun'ichi Nomura wrote:
>> On 10/17/12 08:20, Tejun Heo wrote:
>>>>>> - if (ent == &q->root_blkg->q_node)
>>>>>> + if (q->root_blkg && ent == &q->root_blkg->q_node)
>>>>>
>>>>> Can we fix it little differently. Little earlier in the code, we check for
>>>>> if q->blkg_list is empty, then all the groups are gone, and there are
>>>>> no more request lists hence and return NULL.
>>>>>
>>>>> Current code:
>>>>> if (rl == &q->root_rl) {
>>>>> ent = &q->blkg_list;
>>>>>
>>>>> Modified code:
>>>>> if (rl == &q->root_rl) {
>>>>> ent = &q->blkg_list;
>>>>> /* There are no more block groups, hence no request lists */
>>>>> if (list_empty(ent))
>>>>> return NULL;
>>>>> }
>>>
>>> Do we need this at all? q->root_blkg being NULL is completely fine
>>> there and the comparison would work as expected, no?
>>
>> Hmm?
>>
>> If list_empty(ent) and q->root_blkg == NULL,
>>
>>> /* walk to the next list_head, skip root blkcg */
>>> ent = ent->next;
>>
>> ent is &q->blkg_list again.
>>
>>> if (ent == &q->root_blkg->q_node)
>>
>> So ent is not &q->root_blkg->q_node.
>
> If q->root_blkg is NULL, will it not lead to NULL pointer dereference.
> (q->root_blkg->q_node).
It's not dereferenced.
>>> ent = ent->next;
>>> if (ent == &q->blkg_list)
>>> return NULL;
>>
>> And we return NULL here.
>>
>> Ah, yes. You are correct.
>> We can do without the above hunk.
>
> I would rather prefer to check for this boundary condition early and
> return instead of letting it fall through all these conditions and
> then figure out yes we have no next rl. IMO, code becomes easier to
> understand if nothing else. Otherwise one needs a step by step
> explanation as above to show that case of q->root_blkg is covered.
I have same opinion as yours that it's good for readability.
--
Jun'ichi Nomura, NEC Corporation
next prev parent reply other threads:[~2012-10-18 2:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-10 5:11 Jun'ichi Nomura
2012-10-10 15:59 ` Vivek Goyal
2012-10-11 1:31 ` Jun'ichi Nomura
2012-10-11 18:55 ` Vivek Goyal
2012-10-16 23:20 ` Tejun Heo
2012-10-17 0:02 ` Jun'ichi Nomura
2012-10-17 8:45 ` [PATCH] blkcg: " Jun'ichi Nomura
2012-10-18 21:21 ` Tejun Heo
2012-10-22 18:43 ` Jens Axboe
2012-10-17 13:47 ` [PATCH] " Vivek Goyal
2012-10-18 2:56 ` Jun'ichi Nomura [this message]
2012-10-18 13:31 ` Vivek Goyal
2012-10-18 21:20 ` Tejun Heo
2012-10-19 14:53 ` Vivek Goyal
2012-10-22 0:55 ` Jun'ichi Nomura
2012-10-22 1:15 ` [PATCH] blkcg: stop iteration early if root_rl is the only request list Jun'ichi Nomura
2012-10-22 15:31 ` Vivek Goyal
2012-10-22 18:43 ` Jens Axboe
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=507F6FE2.3030303@ce.jp.nec.com \
--to=j-nomura@ce.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=vgoyal@redhat.com \
/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
Powered by JetHome