[RHEL7,COMMIT] ms/iscsi-target: fix memory leak in iscsit_setup_text_cmd()

Submitted by Konstantin Khorenko on April 2, 2018, 2:28 p.m.

Details

Message ID 201804021428.w32ESUh0024680@finist_ce7.work
State New
Series "target: backport bug fixes from the upstream kernel"
Headers show

Commit Message

Konstantin Khorenko April 2, 2018, 2:28 p.m.
The commit is pushed to "branch-rh7-3.10.0-693.21.1.vz7.46.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.21.1.vz7.46.2
------>
commit 36ec28ad5177e3c5cbfa8a86f625d4f0760c85c5
Author: Varun Prakash <varun@chelsio.com>
Date:   Mon Apr 2 17:28:30 2018 +0300

    ms/iscsi-target: fix memory leak in iscsit_setup_text_cmd()
    
    ML: ea8dc5b4cd2195ee582cae28afa4164c6dea1738
    
    On receiving text request iscsi-target allocates buffer for
    payload in iscsit_handle_text_cmd() and assigns buffer pointer
    to cmd->text_in_ptr, this buffer is currently freed in
    iscsit_release_cmd(), if iscsi-target sets 'C' bit in text
    response then it will receive another text request from the
    initiator with ttt != 0xffffffff in this case iscsi-target
    will find cmd using itt and call iscsit_setup_text_cmd()
    which will set cmd->text_in_ptr to NULL without freeing
    previously allocated buffer.
    
    This patch fixes this issue by calling kfree(cmd->text_in_ptr)
    in iscsit_setup_text_cmd() before assigning NULL to it.
    
    For the first text request cmd->text_in_ptr is NULL as
    cmd is memset to 0 in iscsit_allocate_cmd().
    
    Signed-off-by: Varun Prakash <varun@chelsio.com>
    Cc: <stable@vger.kernel.org> # 4.0+
    Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
    Signed-off-by: Andrei Vagin <avagin@openvz.org>
---
 drivers/target/iscsi/iscsi_target.c | 1 +
 1 file changed, 1 insertion(+)

Patch hide | download patch | download mbox

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index ea8573e9e129..aeba04aee4bb 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -2164,6 +2164,7 @@  iscsit_setup_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
 	cmd->cmd_sn		= be32_to_cpu(hdr->cmdsn);
 	cmd->exp_stat_sn	= be32_to_cpu(hdr->exp_statsn);
 	cmd->data_direction	= DMA_NONE;
+	kfree(cmd->text_in_ptr);
 	cmd->text_in_ptr	= NULL;
 
 	return 0;