iscsi-target: Always send a response before terminating iSCSI connection
authorRoland Dreier <roland@purestorage.com>
Tue, 6 Nov 2012 02:02:42 +0000 (18:02 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 11 Jun 2014 19:04:20 +0000 (12:04 -0700)
commit 1c5c12c666fda27c7c494b34934a0a0631a48130 upstream.

There are some cases, for example when the initiator sends an
out-of-bounds ErrorRecoveryLevel value, where the iSCSI target
terminates the connection without sending back any error.  Audit the
login path and add appropriate iscsit_tx_login_rsp() calls to make
sure this doesn't happen.

Signed-off-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Rui Xiang <rui.xiang@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/target/iscsi/iscsi_target_login.c
drivers/target/iscsi/iscsi_target_nego.c

index 3cb7a4f5b98851ca30e878f46e4909025116ee8d..bc7d08fc8bbd86ee0719bf90b85fe30c62913bbb 100644 (file)
@@ -131,13 +131,13 @@ int iscsi_check_for_session_reinstatement(struct iscsi_conn *conn)
 
        initiatorname_param = iscsi_find_param_from_key(
                        INITIATORNAME, conn->param_list);
-       if (!initiatorname_param)
-               return -1;
-
        sessiontype_param = iscsi_find_param_from_key(
                        SESSIONTYPE, conn->param_list);
-       if (!sessiontype_param)
+       if (!initiatorname_param || !sessiontype_param) {
+               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
+                       ISCSI_LOGIN_STATUS_MISSING_FIELDS);
                return -1;
+       }
 
        sessiontype = (strncmp(sessiontype_param->value, NORMAL, 6)) ? 1 : 0;
 
index 60470ee98fe20fb1aab8ea8a8f70f40899e42360..89f89092b5f23f9c394ab1dea7e2ad04d2cd5690 100644 (file)
@@ -628,8 +628,11 @@ static int iscsi_target_handle_csg_one(struct iscsi_conn *conn, struct iscsi_log
                        login->req_buf,
                        payload_length,
                        conn->param_list);
-       if (ret < 0)
+       if (ret < 0) {
+               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
+                               ISCSI_LOGIN_STATUS_INIT_ERR);
                return -1;
+       }
 
        if (login->first_request)
                if (iscsi_target_check_first_request(conn, login) < 0)
@@ -644,8 +647,11 @@ static int iscsi_target_handle_csg_one(struct iscsi_conn *conn, struct iscsi_log
                        login->rsp_buf,
                        &login->rsp_length,
                        conn->param_list);
-       if (ret < 0)
+       if (ret < 0) {
+               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
+                               ISCSI_LOGIN_STATUS_INIT_ERR);
                return -1;
+       }
 
        if (!login->auth_complete &&
             ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication) {