lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu,  8 Feb 2024 12:36:57 +0300
From: Fedor Pchelkin <pchelkin@...ras.ru>
To: James Smart <james.smart@...adcom.com>,
	"Martin K. Petersen" <martin.petersen@...cle.com>
Cc: Fedor Pchelkin <pchelkin@...ras.ru>,
	Ram Vegesna <ram.vegesna@...adcom.com>,
	"James E.J. Bottomley" <jejb@...ux.ibm.com>,
	Daniel Wagner <dwagner@...e.de>,
	Hannes Reinecke <hare@...e.de>,
	linux-scsi@...r.kernel.org,
	target-devel@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Alexey Khoroshilov <khoroshilov@...ras.ru>,
	lvc-project@...uxtesting.org,
	stable@...r.kernel.org
Subject: [PATCH] scsi: elx: efct: adjust error handling inside efct_hw_setup_io

IO and WQE buffers are allocated once per HW and can be reused later. If
WQE buffers allocation fails then the whole allocation is marked as failed
but already created IO array internal objects are not freed. hw->io is
freed but not nullified in that specific case - it may become a problem
later as efct_hw_setup_io() is supposed to be reusable for the same HW.

While at it, use kcalloc instead of kmalloc_array/memset-zero combination
and get rid of some needless NULL assignments: nullifying hw->io[i]
elements just before freeing hw->io is not really useful.

Found by Linux Verification Center (linuxtesting.org).

Fixes: 4df84e846624 ("scsi: elx: efct: Driver initialization routines")
Cc: stable@...r.kernel.org
Signed-off-by: Fedor Pchelkin <pchelkin@...ras.ru>
---
 drivers/scsi/elx/efct/efct_hw.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/elx/efct/efct_hw.c b/drivers/scsi/elx/efct/efct_hw.c
index 5a5525054d71..e5486e6949f9 100644
--- a/drivers/scsi/elx/efct/efct_hw.c
+++ b/drivers/scsi/elx/efct/efct_hw.c
@@ -487,12 +487,10 @@ efct_hw_setup_io(struct efct_hw *hw)
 	struct efct *efct = hw->os;
 
 	if (!hw->io) {
-		hw->io = kmalloc_array(hw->config.n_io, sizeof(io), GFP_KERNEL);
+		hw->io = kcalloc(hw->config.n_io, sizeof(io), GFP_KERNEL);
 		if (!hw->io)
 			return -ENOMEM;
 
-		memset(hw->io, 0, hw->config.n_io * sizeof(io));
-
 		for (i = 0; i < hw->config.n_io; i++) {
 			hw->io[i] = kzalloc(sizeof(*io), GFP_KERNEL);
 			if (!hw->io[i])
@@ -502,10 +500,8 @@ efct_hw_setup_io(struct efct_hw *hw)
 		/* Create WQE buffs for IO */
 		hw->wqe_buffs = kzalloc((hw->config.n_io * hw->sli.wqe_size),
 					GFP_KERNEL);
-		if (!hw->wqe_buffs) {
-			kfree(hw->io);
-			return -ENOMEM;
-		}
+		if (!hw->wqe_buffs)
+			goto error;
 
 	} else {
 		/* re-use existing IOs, including SGLs */
@@ -586,10 +582,8 @@ efct_hw_setup_io(struct efct_hw *hw)
 
 	return 0;
 error:
-	for (i = 0; i < hw->config.n_io && hw->io[i]; i++) {
+	for (i = 0; i < hw->config.n_io && hw->io[i]; i++)
 		kfree(hw->io[i]);
-		hw->io[i] = NULL;
-	}
 
 	kfree(hw->io);
 	hw->io = NULL;
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ