public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/dasd: fix error checks in dasd_copy_pair_store()
@ 2024-05-27 13:50 Carlos López
  2024-07-01 10:58 ` Stefan Haberland
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos López @ 2024-05-27 13:50 UTC (permalink / raw)
  To: linux-s390
  Cc: Carlos López, Stefan Haberland, Jan Hoeppner, Heiko Carstens,
	Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
	Sven Schnelle, Jens Axboe, open list

dasd_add_busid() can return an error via ERR_PTR() if an allocation
fails. However, two callsites in dasd_copy_pair_store() do not check
the result, potentially resulting in a NULL pointer dereference. Fix
this by checking the result with IS_ERR() and returning the error up
the stack.

Fixes: a91ff09d39f9b ("s390/dasd: add copy pair setup")
Signed-off-by: Carlos López <clopez@suse.de>
---
 drivers/s390/block/dasd_devmap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index 0316c20823ee..6adaeb985dde 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -2248,13 +2248,19 @@ static ssize_t dasd_copy_pair_store(struct device *dev,
 
 	/* allocate primary devmap if needed */
 	prim_devmap = dasd_find_busid(prim_busid);
-	if (IS_ERR(prim_devmap))
+	if (IS_ERR(prim_devmap)) {
 		prim_devmap = dasd_add_busid(prim_busid, DASD_FEATURE_DEFAULT);
+		if (IS_ERR(prim_devmap))
+			return PTR_ERR(prim_devmap);
+	}
 
 	/* allocate secondary devmap if needed */
 	sec_devmap = dasd_find_busid(sec_busid);
-	if (IS_ERR(sec_devmap))
+	if (IS_ERR(sec_devmap)) {
 		sec_devmap = dasd_add_busid(sec_busid, DASD_FEATURE_DEFAULT);
+		if (IS_ERR(sec_devmap))
+			return PTR_ERR(sec_devmap);
+	}
 
 	/* setting copy relation is only allowed for offline secondary */
 	if (sec_devmap->device)
-- 
2.35.3


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

* Re: [PATCH] s390/dasd: fix error checks in dasd_copy_pair_store()
  2024-05-27 13:50 [PATCH] s390/dasd: fix error checks in dasd_copy_pair_store() Carlos López
@ 2024-07-01 10:58 ` Stefan Haberland
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Haberland @ 2024-07-01 10:58 UTC (permalink / raw)
  To: Carlos López, linux-s390
  Cc: Jan Hoeppner, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, Jens Axboe, open list

Am 27.05.24 um 15:50 schrieb Carlos López:
> dasd_add_busid() can return an error via ERR_PTR() if an allocation
> fails. However, two callsites in dasd_copy_pair_store() do not check
> the result, potentially resulting in a NULL pointer dereference. Fix
> this by checking the result with IS_ERR() and returning the error up
> the stack.
>
> Fixes: a91ff09d39f9b ("s390/dasd: add copy pair setup")
> Signed-off-by: Carlos López <clopez@suse.de>
> ---

Applied, thanks.


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

end of thread, other threads:[~2024-07-01 10:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27 13:50 [PATCH] s390/dasd: fix error checks in dasd_copy_pair_store() Carlos López
2024-07-01 10:58 ` Stefan Haberland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox