Skip to contentSkip to conversation

target/iscsi: Fix a race condition in iscsit_add_reject_from_cmd()

PATCH Hannes Reinecke 1 participant 1 message Nov 2, 2017 SCSI target

lore
Share & tools
lore

Hannes Reinecke

author Reviewed-by
#0 lore raw
Quoted 26 lines · Bart Van Assche

Avoid that cmd->se_cmd.se_tfo is read after a command has already been freed.

Cc Nicholas Bellinger <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/target/iscsi/iscsi_target.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target.c +1 -0
index 91fbada7cdc2..541f66a875fc 100644
@@ -833,6 +833,7 @@ static int iscsit_add_reject_from_cmd(
 	unsigned char *buf)
 {
 	struct iscsi_conn *conn;
+	const bool do_put = cmd->se_cmd.se_tfo != NULL;
 
 	if (!cmd->conn) {
 		pr_err("cmd->conn is NULL for ITT: 0x%08x\n",

drivers/target/iscsi/iscsi_target.c static int iscsit_add_reject_from_cmd( · line 870

Quoted 8 lines
drivers/target/iscsi/iscsi_target.c +1 -1
@@ -863,7 +864,7 @@ static int iscsit_add_reject_from_cmd(
 	 * Perform the kref_put now if se_cmd has already been setup by
 	 * scsit_setup_scsi_cmd()
 	 */
-	if (cmd->se_cmd.se_tfo != NULL) {
+	if (do_put) {
 		pr_debug("iscsi reject: calling target_put_sess_cmd >>>>>>\n");
 		target_put_sess_cmd(&cmd->se_cmd);
 	}

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		               zSeries & Storage
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)