Skip to contentSkip to conversation

blk-mq: don't add non-pt request with ->end_io to batch

PATCH Applied Ming Lei 2 participants 2 messages Oct 27, 2022

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blk-mq: don't add non-pt request with ->end_io to batch

dm-rq implements ->end_io callback for request issued to underlying queue, and it isn't passthrough request.

Commit ab3e1d3bbab9 ("block: allow end_io based requests in the completion batch handling") doesn't clear rq->bio and rq->__data_len for request with ->end_io in blk_mq_end_request_batch(), and this way is actually dangerous, but so far it is only for nvme passthrough request.

dm-rq needs to clean up remained bios in case of partial completion, and req->bio is required, then use-after-free is triggered, so the underlying clone request can't be completed in blk_mq_end_request_batch.

Fix panic by not adding such request into batch list, and the issue can be triggered simply by exposing nvme pci to dm-mpath simply.

Fixes ab3e1d3bbab9 ("block: allow end_io based requests in the completion batch handling")
Cc Mike Snitzer <[email protected]>
---
 include/linux/blk-mq.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/blk-mq.h +2 -1
index ba18e9bdb799..d6119c5d1069 100644
@@ -853,7 +853,8 @@ static inline bool blk_mq_add_to_batch(struct request *req,
 				       struct io_comp_batch *iob, int ioerror,
 				       void (*complete)(struct io_comp_batch *))
 {
-	if (!iob || (req->rq_flags & RQF_ELV) || ioerror)
+	if (!iob || (req->rq_flags & RQF_ELV) || ioerror ||
+			(req->end_io && !blk_rq_is_passthrough(req)))
 		return false;
 
 	if (!iob->complete)
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Ming Lei

dm-rq implements ->end_io callback for request issued to underlying queue, and it isn't passthrough request.

Commit ab3e1d3bbab9 ("block: allow end_io based requests in the completion batch handling") doesn't clear rq->bio and rq->__data_len for request with ->end_io in blk_mq_end_request_batch(), and this way is actually dangerous, but so far it is only for nvme passthrough request.

[...]

Applied, thanks!

[1/1] blk-mq: don't add non-pt request with ->end_io to batch
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe