Skip to contentSkip to conversation

target/iscsi: Detect conn_cmd_list corruption early

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 35 lines · Bart Van Assche

Certain behavior of the initiator can cause the target driver to send both a reject and a SCSI response. If that happens two target_put_sess_cmd() calls will occur without the command having been removed from conn_cmd_list. In other words, conn_cmd_list will get corrupted once the freed memory is reused. Although the Linux kernel can detect list corruption if list debugging is enabled, in this case the context in which list corruption is detected is not related to the context that caused list corruption. Hence add WARN_ON() statements that report the context that is causing list corruption.

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_util.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/target/iscsi/iscsi_target_util.c +2 -0
index 1e36f83b5961..70c6b9bfc04e 100644
@@ -694,6 +694,8 @@ void iscsit_release_cmd(struct iscsi_cmd *cmd)
 	struct iscsi_session *sess;
 	struct se_cmd *se_cmd = &cmd->se_cmd;
 
+	WARN_ON(!list_empty(&cmd->i_conn_node));
+
 	if (cmd->conn)
 		sess = cmd->conn->sess;
 	else

drivers/target/iscsi/iscsi_target_util.c void __iscsit_free_cmd(struct iscsi_cmd *cmd, bool check_queues) · line 725

Quoted 8 lines
drivers/target/iscsi/iscsi_target_util.c +2 -0
@@ -716,6 +718,8 @@ void __iscsit_free_cmd(struct iscsi_cmd *cmd, bool check_queues)
 {
 	struct iscsi_conn *conn = cmd->conn;
 
+	WARN_ON(!list_empty(&cmd->i_conn_node));
+
 	if (cmd->data_direction = DMA_TO_DEVICE) {
 		iscsit_stop_dataout_timer(cmd);
 		iscsit_free_r2ts_from_list(cmd);

Well, I would rather fix the target code itself...

But anyway:

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)