Skip to contentSkip to conversation

block: fix NULL pointer dereferenced within __blk_rq_map_sg

PATCH Applied Ming Lei 3 participants 3 messages Feb 17, 2025 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH v2 1/1 block: fix NULL pointer dereferenced within __blk_rq_map_sg

The block layer internal flush request may not have bio attached, so the request iterator has to be initialized from valid req->bio, otherwise NULL pointer dereferenced is triggered.

Cc Christoph Hellwig <[email protected]>
Fixes b7175e24d6ac ("block: add a dma mapping iterator")

---
V2:
- fix commit log and comment

 block/blk-merge.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
block/blk-merge.c +4 -1
index b55c52a42303..143834087d55 100644
@@ -556,11 +556,14 @@ int __blk_rq_map_sg(struct request_queue *q, struct request *rq,
 {
 	struct req_iterator iter = {
 		.bio	= rq->bio,
-		.iter	= rq->bio->bi_iter,
 	};
 	struct phys_vec vec;
 	int nsegs = 0;
 
+	/* the internal flush request may not have bio attached */
+	if (iter.bio)
+		iter.iter = iter.bio->bi_iter;
+
 	while (blk_map_iter_next(rq, &iter, &vec)) {
 		*last_sg = blk_next_sg(last_sg, sglist);
 		sg_set_page(*last_sg, phys_to_page(vec.paddr), vec.len,
Signature · 1 line
2.47.1
maintainer Applied
#2 lore raw
In reply to Ming Lei
Quoted 5 lines · Ming Lei

The block layer internal flush request may not have bio attached, so the request iterator has to be initialized from valid req->bio, otherwise NULL pointer dereferenced is triggered.

Applied, thanks!

[1/1] block: fix NULL pointer dereferenced within __blk_rq_map_sg

      commit: dd8b0582e25e36bba483c60338741c0ba5bc426c

Best regards,

Signature · 1 line
Jens Axboe