From fa059c8f1302a091f47ea0fff46a2471f308b699 Mon Sep 17 00:00:00 2001 From: Wenchao Hao Date: Wed, 22 Mar 2023 10:46:36 +0800 Subject: [PATCH] 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 https://github.com/sahlberg/libiscsi/commit/a391176a6dece09454672c6522778d6513e90fb4 https://github.com/sahlberg/libiscsi/commit/2674070fb80ad7527589a1fbd576ee074d26ed72 Signed-off-by: Wenchao Hao (cherry picked from commit cfbc7ef4da33be679f02c5a44754673f86134eea) --- ...-memory-leak-in-iscsi_create_context.patch | 31 +++++++++++++++++ ...mand-Fix-leak-in-iscsi_send_data_out.patch | 34 +++++++++++++++++++ libiscsi.spec | 7 +++- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 0022-init-fix-memory-leak-in-iscsi_create_context.patch create mode 100644 0023-iscsi-command-Fix-leak-in-iscsi_send_data_out.patch diff --git a/0022-init-fix-memory-leak-in-iscsi_create_context.patch b/0022-init-fix-memory-leak-in-iscsi_create_context.patch new file mode 100644 index 0000000..1f7a588 --- /dev/null +++ b/0022-init-fix-memory-leak-in-iscsi_create_context.patch @@ -0,0 +1,31 @@ +From a391176a6dece09454672c6522778d6513e90fb4 Mon Sep 17 00:00:00 2001 +From: zhenwei pi +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 +--- + 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 + diff --git a/0023-iscsi-command-Fix-leak-in-iscsi_send_data_out.patch b/0023-iscsi-command-Fix-leak-in-iscsi_send_data_out.patch new file mode 100644 index 0000000..5f52145 --- /dev/null +++ b/0023-iscsi-command-Fix-leak-in-iscsi_send_data_out.patch @@ -0,0 +1,34 @@ +From 2674070fb80ad7527589a1fbd576ee074d26ed72 Mon Sep 17 00:00:00 2001 +From: Raphael Norwitz +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 +--- + 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 + diff --git a/libiscsi.spec b/libiscsi.spec index 74bd6c1..0d58965 100644 --- a/libiscsi.spec +++ b/libiscsi.spec @@ -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 - 1.19.0-10 +- DESC: backport patch to fix some memory leak issues + * Wed Jun 15 2022 Ruijun Ge - 1.19.0-9 - DESC: backport patch to solve segmentation fault problem -- Gitee