linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md: fix potential NULL pointer dereference in md_super_write
@ 2025-05-23  9:11 Ye Chey
  0 siblings, 0 replies; 3+ messages in thread
From: Ye Chey @ 2025-05-23  9:11 UTC (permalink / raw)
  To: song, yukuai3; +Cc: linux-raid, linux-kernel, Ye Chey

The bio_alloc_bioset() call in md_super_write() could fail under memory
pressure and return NULL. Add a check to handle this case gracefully by
returning early, preventing a potential NULL pointer dereference.

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

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 9daa78c5f..492cbc1c7 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1002,6 +1002,9 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
 			      REQ_OP_WRITE | REQ_SYNC | REQ_IDLE | REQ_META
 				  | REQ_PREFLUSH | REQ_FUA,
 			      GFP_NOIO, &mddev->sync_set);
+	if (!bio) {
+		return;
+	}
 
 	atomic_inc(&rdev->nr_pending);
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] md: fix potential NULL pointer dereference in md_super_write
@ 2025-05-23  9:35 Ye Chey
  2025-05-23  9:59 ` Yu Kuai
  0 siblings, 1 reply; 3+ messages in thread
From: Ye Chey @ 2025-05-23  9:35 UTC (permalink / raw)
  To: song, yukuai3; +Cc: linux-raid, linux-kernel, Ye Chey

The bio_alloc_bioset() call in md_super_write() could fail under memory
pressure and return NULL. Add a check to handle this case gracefully by
returning early, preventing a potential NULL pointer dereference.

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

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 9daa78c5f..a0e2d90d4 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1002,6 +1002,8 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
 			      REQ_OP_WRITE | REQ_SYNC | REQ_IDLE | REQ_META
 				  | REQ_PREFLUSH | REQ_FUA,
 			      GFP_NOIO, &mddev->sync_set);
+	if (!bio)
+		return;
 
 	atomic_inc(&rdev->nr_pending);
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] md: fix potential NULL pointer dereference in md_super_write
  2025-05-23  9:35 [PATCH] md: fix potential NULL pointer dereference in md_super_write Ye Chey
@ 2025-05-23  9:59 ` Yu Kuai
  0 siblings, 0 replies; 3+ messages in thread
From: Yu Kuai @ 2025-05-23  9:59 UTC (permalink / raw)
  To: Ye Chey, song; +Cc: linux-raid, linux-kernel, yukuai (C)

Hi,

在 2025/05/23 17:35, Ye Chey 写道:
> The bio_alloc_bioset() call in md_super_write() could fail under memory
> pressure and return NULL. Add a check to handle this case gracefully by
> returning early, preventing a potential NULL pointer dereference.

NAK, if you read the comments of bio_alloc_bioset(), you'll know there
are cases bio_alloc_bioset() will never return NULL.

Thanks,
Kuai

> 
> Signed-off-by: Ye Chey <yechey@ai-sast.com>
> ---
>   drivers/md/md.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 9daa78c5f..a0e2d90d4 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1002,6 +1002,8 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
>   			      REQ_OP_WRITE | REQ_SYNC | REQ_IDLE | REQ_META
>   				  | REQ_PREFLUSH | REQ_FUA,
>   			      GFP_NOIO, &mddev->sync_set);
> +	if (!bio)
> +		return;
>   
>   	atomic_inc(&rdev->nr_pending);
>   
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-23  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23  9:35 [PATCH] md: fix potential NULL pointer dereference in md_super_write Ye Chey
2025-05-23  9:59 ` Yu Kuai
  -- strict thread matches above, loose matches on Subject: below --
2025-05-23  9:11 Ye Chey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).