* [PATCH V2] block: fix NULL pointer dereferenced within __blk_rq_map_sg
@ 2025-02-17 3:16 Ming Lei
2025-02-17 6:56 ` Christoph Hellwig
2025-02-17 16:04 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Ming Lei @ 2025-02-17 3:16 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei, Christoph Hellwig, Cheyenne Wills
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 <hch@lst.de>
Reported-and-tested-by: Cheyenne Wills <cheyenne.wills@gmail.com>
Fixes: b7175e24d6ac ("block: add a dma mapping iterator")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
V2:
- fix commit log and comment
block/blk-merge.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index b55c52a42303..143834087d55 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -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,
--
2.47.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH V2] block: fix NULL pointer dereferenced within __blk_rq_map_sg
2025-02-17 3:16 [PATCH V2] block: fix NULL pointer dereferenced within __blk_rq_map_sg Ming Lei
@ 2025-02-17 6:56 ` Christoph Hellwig
2025-02-17 16:04 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2025-02-17 6:56 UTC (permalink / raw)
To: Ming Lei; +Cc: Jens Axboe, linux-block, Christoph Hellwig, Cheyenne Wills
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] block: fix NULL pointer dereferenced within __blk_rq_map_sg
2025-02-17 3:16 [PATCH V2] block: fix NULL pointer dereferenced within __blk_rq_map_sg Ming Lei
2025-02-17 6:56 ` Christoph Hellwig
@ 2025-02-17 16:04 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-02-17 16:04 UTC (permalink / raw)
To: linux-block, Ming Lei; +Cc: Christoph Hellwig, Cheyenne Wills
On Mon, 17 Feb 2025 11:16:26 +0800, Ming Lei wrote:
> 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,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-17 16:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-17 3:16 [PATCH V2] block: fix NULL pointer dereferenced within __blk_rq_map_sg Ming Lei
2025-02-17 6:56 ` Christoph Hellwig
2025-02-17 16:04 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox