All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: mark flush request as IDLE when it is really finished
@ 2020-11-13 13:44 Ming Lei
  2020-11-13 21:24 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2020-11-13 13:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Ming Lei, Yi Zhang

For avoiding use-after-free on flush request, we call its .end_io() from
both timeout code path and __blk_mq_end_request().

When flush request's ref doesn't drop to zero, it is still used, we
can't mark it as IDLE, so fix it by marking IDLE when its refcount drops
to zero really.

Fixes: 65ff5cd04551 ("blk-mq: mark flush request as IDLE in flush_end_io()")
Cc: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-flush.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/block/blk-flush.c b/block/blk-flush.c
index c64f049226f6..23124d60cffe 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -224,13 +224,18 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
 	/* release the tag's ownership to the req cloned from */
 	spin_lock_irqsave(&fq->mq_flush_lock, flags);
 
-	WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
 	if (!refcount_dec_and_test(&flush_rq->ref)) {
 		fq->rq_status = error;
 		spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
 		return;
 	}
 
+	/*
+	 * Flush request has to be marked as IDLE when it is really ended
+	 * because its .end_io() is called from timeout code path too for
+	 * avoiding use-after-free.
+	 */
+	WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
 	if (fq->rq_status != BLK_STS_OK)
 		error = fq->rq_status;
 
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block: mark flush request as IDLE when it is really finished
  2020-11-13 13:44 [PATCH] block: mark flush request as IDLE when it is really finished Ming Lei
@ 2020-11-13 21:24 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-11-13 21:24 UTC (permalink / raw)
  To: Ming Lei; +Cc: linux-block, Yi Zhang

On 11/13/20 6:44 AM, Ming Lei wrote:
> For avoiding use-after-free on flush request, we call its .end_io() from
> both timeout code path and __blk_mq_end_request().
> 
> When flush request's ref doesn't drop to zero, it is still used, we
> can't mark it as IDLE, so fix it by marking IDLE when its refcount drops
> to zero really.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-13 21:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 13:44 [PATCH] block: mark flush request as IDLE when it is really finished Ming Lei
2020-11-13 21:24 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.