Skip to content

Commit 2d87d45

Browse files
Ming Leiaxboe
authored andcommitted
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 ab3e1d3 ("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: ab3e1d3 ("block: allow end_io based requests in the completion batch handling") Cc: [email protected] Cc: Mike Snitzer <[email protected]> Reported-by: Changhui Zhong <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 7f21735 commit 2d87d45

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

include/linux/blk-mq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,8 @@ static inline bool blk_mq_add_to_batch(struct request *req,
853853
struct io_comp_batch *iob, int ioerror,
854854
void (*complete)(struct io_comp_batch *))
855855
{
856-
if (!iob || (req->rq_flags & RQF_ELV) || ioerror)
856+
if (!iob || (req->rq_flags & RQF_ELV) || ioerror ||
857+
(req->end_io && !blk_rq_is_passthrough(req)))
857858
return false;
858859

859860
if (!iob->complete)

0 commit comments

Comments
 (0)