linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Ming Lei <ming.lei@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
	Hannes Reinecke <hare@suse.de>,
	John Garry <john.garry@huawei.com>,
	David Jeffery <djeffery@redhat.com>
Subject: Re: [PATCH V5 2/4] blk-mq: grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter
Date: Thu, 6 May 2021 07:54:40 +0100	[thread overview]
Message-ID: <20210506065440.GC328487@infradead.org> (raw)
In-Reply-To: <20210505145855.174127-3-ming.lei@redhat.com>

On Wed, May 05, 2021 at 10:58:53PM +0800, Ming Lei wrote:
> Grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter(), and
> this way will prevent the request from being re-used when ->fn is
> running. The approach is same as what we do during handling timeout.
> 
> Fix request UAF related with completion race or queue releasing:

I guess UAF is supposed to mean use-after-free?  Please just spell that
out.

> +	rq = blk_mq_find_and_get_req(tags, bitnr);
>  	/*
>  	 * We can hit rq == NULL here, because the tagging functions
>  	 * test and set the bit before assigning ->rqs[].
>  	 */
> +	if (!rq)
> +		return true;

Nit: I'd find this much earier to follow if the blk_mq_find_and_get_req
and thus assignment to rq was after the block comment.

>  	struct blk_mq_tags *tags = iter_data->tags;
>  	bool reserved = iter_data->flags & BT_TAG_ITER_RESERVED;
>  	struct request *rq;
> +	bool ret = true;
> +	bool iter_static_rqs = !!(iter_data->flags & BT_TAG_ITER_STATIC_RQS);
>  
>  	if (!reserved)
>  		bitnr += tags->nr_reserved_tags;
> @@ -272,16 +288,19 @@ static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
>  	 * We can hit rq == NULL here, because the tagging functions
>  	 * test and set the bit before assigning ->rqs[].
>  	 */
> +	if (iter_static_rqs)

I think this local variable just obsfucates what is going on here.

Otherwise this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

  reply	other threads:[~2021-05-06  6:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 14:58 [PATCH V5 0/4] blk-mq: fix request UAF related with iterating over tagset requests Ming Lei
2021-05-05 14:58 ` [PATCH V5 1/4] block: avoid double io accounting for flush request Ming Lei
2021-05-06  6:44   ` Christoph Hellwig
2021-05-05 14:58 ` [PATCH V5 2/4] blk-mq: grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter Ming Lei
2021-05-06  6:54   ` Christoph Hellwig [this message]
2021-05-06  7:30     ` Ming Lei
2021-05-05 14:58 ` [PATCH V5 3/4] blk-mq: clear stale request in tags->rq[] before freeing one request pool Ming Lei
2021-05-06  7:12   ` Christoph Hellwig
2021-05-06  7:34     ` Ming Lei
2021-05-06 12:18       ` Christoph Hellwig
2021-05-06 13:38         ` Ming Lei
2021-05-07  6:57           ` Christoph Hellwig
2021-05-07  7:30             ` Ming Lei
2021-05-06 14:51         ` Bart Van Assche
2021-05-07  0:11           ` Ming Lei
2021-05-07  1:10             ` Bart Van Assche
2021-05-07  2:05               ` Ming Lei
2021-05-07  3:16                 ` Bart Van Assche
2021-05-07  6:31                   ` Ming Lei
2021-05-07  6:52                     ` Christoph Hellwig
2021-05-08  2:02                       ` Bart Van Assche
2021-05-06 15:02   ` Bart Van Assche
2021-05-07  0:13     ` Ming Lei
2021-05-07  1:11   ` Bart Van Assche
2021-05-07  2:06     ` Ming Lei
2021-05-05 14:58 ` [PATCH V5 4/4] blk-mq: clearing flush request reference in tags->rqs[] 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=20210506065440.GC328487@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=djeffery@redhat.com \
    --cc=hare@suse.de \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@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;
as well as URLs for NNTP newsgroup(s).