Skip to contentSkip to conversation

block: mark flush request as IDLE when it is really finished

PATCH Applied Ming Lei 2 participants 2 messages Nov 13, 2020 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: mark flush request as IDLE when it is really finished

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 <[email protected]>
---
 block/blk-flush.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block/blk-flush.c +6 -1
index c64f049226f6..23124d60cffe 100644
@@ -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;
 
Signature · 1 line
2.25.4
maintainer Applied
#1 lore raw
Quoted 6 lines · Ming Lei

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.

Signature · 1 line
Jens Axboe