backport patch to fix some memory leak issues

0022-init-fix-memory-leak-in-iscsi_create_context.patch
0023-iscsi-command-Fix-leak-in-iscsi_send_data_out.patch
a391176a6d
2674070fb8

Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
This commit is contained in:
Wenchao Hao 2023-03-22 10:46:36 +08:00
parent 8f7a9b725f
commit cfbc7ef4da
3 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,31 @@
From a391176a6dece09454672c6522778d6513e90fb4 Mon Sep 17 00:00:00 2001
From: zhenwei pi <pizhenwei@bytedance.com>
Date: Tue, 25 Feb 2020 22:35:54 +0800
Subject: [PATCH] init: fix memory leak in iscsi_create_context
iscsi instance is allocated in iscsi_create_context, after we return
NULL, nobody could handle it anymore.
Currently we can't hit this logic, anyway we still fix this.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
lib/init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/init.c b/lib/init.c
index 13098f0..f3e2e13 100644
--- a/lib/init.c
+++ b/lib/init.c
@@ -218,7 +218,7 @@ iscsi_create_context(const char *initiator_name)
/* initalize transport of context */
if (iscsi_init_transport(iscsi, TCP_TRANSPORT)) {
- iscsi_set_error(iscsi, "Failed allocating transport");
+ free(iscsi);
return NULL;
}
--
2.35.3

View File

@ -0,0 +1,34 @@
From 2674070fb80ad7527589a1fbd576ee074d26ed72 Mon Sep 17 00:00:00 2001
From: Raphael Norwitz <raphael.norwitz@nutanix.com>
Date: Tue, 1 Mar 2022 18:03:48 -0500
Subject: [PATCH] iscsi-command: Fix leak in iscsi_send_data_out
In iscsi_send_data_out() a PDU is allocated, but there is no error
handling logic to free it if the PDU cannot be queued.
iscsi_allocate_pdu() may allocate memory for the PDU. This memory may be
leaked if iscsi_queue_pdu() fails since there is no call to free it.
Orignally there was a free() call but it was removed as a part of a
cleanup adding checks for NULL pdu callbacks.
Fixes: 423b82efa4bd ("pdu: check callback for NULL everywhere")
Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
---
lib/iscsi-command.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/iscsi-command.c b/lib/iscsi-command.c
index a4df637..9a240ab 100644
--- a/lib/iscsi-command.c
+++ b/lib/iscsi-command.c
@@ -131,6 +131,7 @@ iscsi_send_data_out(struct iscsi_context *iscsi, struct iscsi_pdu *cmd_pdu,
if (iscsi_queue_pdu(iscsi, pdu) != 0) {
iscsi_set_error(iscsi, "Out-of-memory: failed to queue iscsi "
"scsi pdu.");
+ iscsi->drv->free_pdu(iscsi, pdu);
goto error;
}
--
2.35.3

View File

@ -1,6 +1,6 @@
Name: libiscsi
Version: 1.19.0
Release: 9
Release: 10
Summary: Client-side library to implement the iSCSI protocol
Recommends: %{name}-utils
License: LGPLv2+ and GPLv2+
@ -27,6 +27,8 @@ Patch18: 0018-iscsi-swp-handle-setting-of-debug_level-correctly.patch
Patch19: 0019-fix-iscsi-ls-parameter-parse.patch
Patch20: 0020-Check-return-value-of-scsi_malloc-in-order-to.patch
Patch21: 0021-Fix-segmentation-fault-problem.patch
Patch22: 0022-init-fix-memory-leak-in-iscsi_create_context.patch
Patch23: 0023-iscsi-command-Fix-leak-in-iscsi_send_data_out.patch
Source: https://github.com/sahlberg/%{name}/archive/%{version}.tar.gz
@ -128,6 +130,9 @@ This package contains utilities of %{name} to connect to iSCSI targets
%{_bindir}/iscsi-test-cu
%changelog
* Wed Mar 22 2023 Wenchao Hao <haowenchao2@huawei.com> - 1.19.0-10
- DESC: backport patch to fix some memory leak issues
* Wed Jun 15 2022 Ruijun Ge <geruijun@huawei.com> - 1.19.0-9
- DESC: backport patch to solve segmentation fault problem