[PATCH] drbd: fix potential NULL pointer dereference in drbd_md_sync_page_io

Ye Chey posted 1 patch 6 months, 3 weeks ago
drivers/block/drbd/drbd_actlog.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] drbd: fix potential NULL pointer dereference in drbd_md_sync_page_io
Posted by Ye Chey 6 months, 3 weeks ago
Under memory pressure, bio_alloc_bioset() may fail and return NULL. Add a
check to handle this case gracefully by returning -ENOMEM instead of
dereferencing a NULL pointer.

Signed-off-by: Ye Chey <yechey@ai-sast.com>
---
 drivers/block/drbd/drbd_actlog.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c
index 742b2908f..68b925b49 100644
--- a/drivers/block/drbd/drbd_actlog.c
+++ b/drivers/block/drbd/drbd_actlog.c
@@ -141,6 +141,10 @@ static int _drbd_md_sync_page_io(struct drbd_device *device,
 
 	bio = bio_alloc_bioset(bdev->md_bdev, 1, op | op_flags, GFP_NOIO,
 			       &drbd_md_io_bio_set);
+	if (!bio) {
+		err = -ENOMEM;
+		goto out;
+	}
 	bio->bi_iter.bi_sector = sector;
 	err = -EIO;
 	if (bio_add_page(bio, device->md_io.page, size, 0) != size)
-- 
2.44.0
Re: [PATCH] drbd: fix potential NULL pointer dereference in drbd_md_sync_page_io
Posted by Christoph Hellwig 6 months, 3 weeks ago
On Fri, May 23, 2025 at 04:55:29PM +0800, Ye Chey wrote:
> Under memory pressure, bio_alloc_bioset() may fail and return NULL.

No, not with the GFP_ flag passed here.