public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: "yukuai (C)" <yukuai3@huawei.com>
To: Bart Van Assche <bvanassche@acm.org>, <axboe@kernel.dk>,
	<ming.lei@redhat.com>
Cc: <yi.zhang@huawei.com>, <yuyufen@huawei.com>,
	<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] block: fix access of uninitialized pointer address in bt_for_each()
Date: Sat, 18 Apr 2020 11:24:53 +0800	[thread overview]
Message-ID: <f74ca075-7d29-a944-b49b-7b432f2a60c9@huawei.com> (raw)
In-Reply-To: <340bed9b-e14d-5a22-1601-8fb7aad4ce7f@acm.org>

on 2020/4/17 22:26, Bart Van Assche wrote:

> The alloc/free info refers to a data structure owned by the pipe
> implementation. The use-after-free report refers to a data structure
> owned by the block layer. How can that report make sense?

Indeed, I'm comfused here, too.

>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index 7ed16ed13976..48b74d0085c7 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -485,6 +485,7 @@ static void __blk_mq_free_request(struct request *rq)
>>   	struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
>>   	const int sched_tag = rq->internal_tag;
>>   
>> +	hctx->tags->rqs[rq->tag] = NULL;
>>   	if (rq->tag != -1)
>>   		blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag);
>>   	if (sched_tag != -1)
> 
> Can the above change trigger the following assignment?
> 
> hctx->tags->rqs[-1] = NULL?

My bad, should be inside 'if'.

> static inline void *kcalloc_node(size_t n, size_t size, gfp_t flags,
>                                   int node)
> {
> 	return kmalloc_array_node(n, size, flags | __GFP_ZERO, node);
> }
> 
> I think this means that kcalloc_node() already zeroes the allocated
> memory and hence that changing kcalloc() into kzalloc() is not necessary.

You are right.

>> @@ -196,6 +196,7 @@ static inline void blk_mq_put_driver_tag_hctx(struct blk_mq_hw_ctx *hctx,
>>   	if (rq->tag == -1 || rq->internal_tag == -1)
>>   		return;
>>   
>> +	hctx->tags->rqs[rq->tag] = NULL;
>>   	__blk_mq_put_driver_tag(hctx, rq);
>>   }
>>   
>> @@ -207,6 +208,7 @@ static inline void blk_mq_put_driver_tag(struct request *rq)
>>   		return;
>>   
>>   	hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu);
>> +	hctx->tags->rqs[rq->tag] = NULL;
>>   	__blk_mq_put_driver_tag(hctx, rq);
>>   }
> 
> I don't think the above changes are sufficient to fix the
> use-after-free. Has it been considered to free the memory that backs
> tags->bitmap_tags only after an RCU grace period has expired? See also
> blk_mq_free_tags().

As you pointed out, kcalloc_node() already zeroes out the memory. What I 
don't understand is that how could 'slab-out-of-bounds in bt_for_each' 
triggered instead UAF.

Thanks!
Yu Kuai



  reply	other threads:[~2020-04-18  3:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-17 12:51 [RFC] block: fix access of uninitialized pointer address in bt_for_each() yu kuai
2020-04-17 14:26 ` Bart Van Assche
2020-04-18  3:24   ` yukuai (C) [this message]
2020-04-18  9:42   ` yukuai (C)
2020-04-18 15:26     ` Bart Van Assche
2020-04-18  2:11 ` Ming Lei

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=f74ca075-7d29-a944-b49b-7b432f2a60c9@huawei.com \
    --to=yukuai3@huawei.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=yi.zhang@huawei.com \
    --cc=yuyufen@huawei.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