[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250523091417.2825-1-yechey@ai-sast.com>
Date: Fri, 23 May 2025 17:14:17 +0800
From: Ye Chey <yechey@...sast.com>
To: brauner@...nel.org,
djwong@...nel.org
Cc: linux-xfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org,
Ye Chey <yechey@...sast.com>
Subject: [PATCH] iomap: fix potential NULL pointer dereference in iomap_alloc_ioend
Under memory pressure, bio_alloc_bioset() may fail and return NULL. Add
a check to prevent NULL pointer dereference in iomap_alloc_ioend().
This could happen when the system is under memory pressure and the
allocation of the bio structure fails.
Signed-off-by: Ye Chey <yechey@...sast.com>
---
fs/iomap/buffered-io.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 5b08bd417..d243b191e 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1618,6 +1618,8 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
bio = bio_alloc_bioset(wpc->iomap.bdev, BIO_MAX_VECS,
REQ_OP_WRITE | wbc_to_write_flags(wbc),
GFP_NOFS, &iomap_ioend_bioset);
+ if (!bio)
+ return NULL;
bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos);
bio->bi_end_io = iomap_writepage_end_bio;
bio->bi_write_hint = inode->i_write_hint;
--
2.44.0
Powered by blists - more mailing lists