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>] [day] [month] [year] [list]
Message-Id: <20211209064425.123950-1-niejianglei2021@163.com>
Date:   Thu,  9 Dec 2021 14:44:25 +0800
From:   Jianglei Nie <niejianglei2021@....com>
To:     jejb@...ux.ibm.com, martin.petersen@...cle.com,
        niejianglei2021@....com
Cc:     linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] scsi: csiostor: Fix memory leak in csio_wr_eq_destroy()

Line 715 (#1) calls mempool_alloc() to allocate an element
from a specific memory pool. When some errors occur, line 727 (#2)
frees this memory pool but line 731 (#3) does not free it, which will
lead to a memory leak.

We can fix it by calling mempool_free() when the cbfn is not equal to
NULL and before the function returns 0 in line 732 (#3).

705 static int
706 csio_wr_eq_destroy(struct csio_hw *hw, void *priv, int eq_idx,
707 		   void (*cbfn) (struct csio_hw *, struct csio_mb *))
708 {
710 	struct csio_mb  *mbp;

715 	mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
	// #1: allocate memory pool
716 	if (!mbp)
717 		return -ENOMEM;

725 	rv = csio_mb_issue(hw, mbp);
726 	if (rv != 0) {
727		mempool_free(mbp, hw->mb_mempool);
		// #2: free memory pool
728		return rv;
729 	}

731 	if (cbfn != NULL)
732 		return 0; // #3: missing free

734 	return csio_wr_eq_destroy_rsp(hw, mbp, eq_idx);
735 }

Signed-off-by: Jianglei Nie <niejianglei2021@....com>
---
 drivers/scsi/csiostor/csio_wr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/csiostor/csio_wr.c b/drivers/scsi/csiostor/csio_wr.c
index fe0355c964bc..7dcc4fda0483 100644
--- a/drivers/scsi/csiostor/csio_wr.c
+++ b/drivers/scsi/csiostor/csio_wr.c
@@ -728,8 +728,10 @@ csio_wr_eq_destroy(struct csio_hw *hw, void *priv, int eq_idx,
 		return rv;
 	}
 
-	if (cbfn != NULL)
+	if (cbfn != NULL) {
+		mempool_free(mbp, hw->mb_mempool);
 		return 0;
+	}
 
 	return csio_wr_eq_destroy_rsp(hw, mbp, eq_idx);
 }
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ