From nobody Tue Nov 23 23:12:51 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8A50B18A16E4; Tue, 23 Nov 2021 23:12:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzKg86FT4z3vbM; Tue, 23 Nov 2021 23:12:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 16C831F0CB; Tue, 23 Nov 2021 23:12:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ANNCppd037639; Tue, 23 Nov 2021 23:12:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ANNCpfp037638; Tue, 23 Nov 2021 23:12:51 GMT (envelope-from git) Date: Tue, 23 Nov 2021 23:12:51 GMT Message-Id: <202111232312.1ANNCpfp037638@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 9811763b417a - stable/13 - iscsi: Validate DataSN values in Data-In PDUs in the initiator. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9811763b417a36ca66c8512bbe09fcaec4407514 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637709173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m6HK26YYXXsgcl/vwWb2O13Mz4FstyTTxvacUtQaHSg=; b=MFBYC3faeJC5uu7iD262qtVJFakeBhyn41A1XJc5hu3V9/a5mBrxVdCSJkomymwzjxcIYG 8l4WaphN7/5otIPW+xZV/E3bKq5nRI7bGRz6j7yo8LKcOIqY8g+2BZ4Lmqb2kuXnNbRkXZ hawkwAJAJVk1ex9YhkQdBOzromRNj/7/9vE6YakjcazmjdBG1sEa1Bz9KLAA30vp7S0K/j P3eFpUarcpNFnTqZxx0cls7X/O0ZzKp6lIPvwdvEnQY0q7vl5ef2mlcHfEXhG9r6lDMmRa BWou04rSZiopQxtFxDg8MxgF6X8HzQp/wqAq2UxeGuinuEcaIIYXHDpokR2PAw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637709173; a=rsa-sha256; cv=none; b=DlAcubFW8xt6+WiOinaB3f46tFnbyFVdsX/hwdnjzupTcxyRR6lxCZ0I0FV2kxmUpOQtbN KJ51Fq3lhz+aRZOIzM2R+ay+BJUkY2PVbIKwrtEUeS7KYwhuD8RVN6GfaMhSqqoiBeWlcS +Yxvx3Wf16+mhuA2g0R4xOZT34OI3nyzpZrpVaEZ9jivUSbUar+UmWFt+xfNlY7WVFf5Ns FzWuVLzQiNGspSUo3nJZ4OPQHFsJg3DOtIFpmEQGGUwxqnD2FqkMbFEz1xDwM+otdJ5X9L iSPz9Xu6dGIgu0D0NoNQX1lHOb4AvT2lCLwzipmN1/pOBHht0eKaBhR4LMm4Lw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=9811763b417a36ca66c8512bbe09fcaec4407514 commit 9811763b417a36ca66c8512bbe09fcaec4407514 Author: John Baldwin AuthorDate: 2021-08-24 21:58:34 +0000 Commit: John Baldwin CommitDate: 2021-11-23 23:11:44 +0000 iscsi: Validate DataSN values in Data-In PDUs in the initiator. As is done in the target, require that DataSN values are consecutive and in-order. If an out of order Data-In PDU is received, force a session reconnect. In addition, when a SCSI Response PDU is received, verify that the ExpDataSN field matches the count of Data-In PDUs received for this command. If not, force a session reconnect. Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D31594 (cherry picked from commit 4f0f5bf99591ad9907822082270523ac919e3b8c) --- sys/dev/iscsi/iscsi.c | 21 ++++++++++++++++++++- sys/dev/iscsi/iscsi.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c index f60904bb3de0..093ba51d265e 100644 --- a/sys/dev/iscsi/iscsi.c +++ b/sys/dev/iscsi/iscsi.c @@ -892,6 +892,15 @@ iscsi_pdu_handle_scsi_response(struct icl_pdu *response) } ccb = io->io_ccb; + if (ntohl(bhssr->bhssr_expdatasn) != io->io_datasn) { + ISCSI_SESSION_WARN(is, + "ExpDataSN mismatch in SCSI Response (%u vs %u)", + ntohl(bhssr->bhssr_expdatasn), io->io_datasn); + icl_pdu_free(response); + iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); + return; + } /* * With iSER, after getting good response we can be sure @@ -1047,6 +1056,17 @@ iscsi_pdu_handle_data_in(struct icl_pdu *response) return; } + if (io->io_datasn != ntohl(bhsdi->bhsdi_datasn)) { + ISCSI_SESSION_WARN(is, "received Data-In PDU with " + "DataSN %u, while expected %u; dropping connection", + ntohl(bhsdi->bhsdi_datasn), io->io_datasn); + icl_pdu_free(response); + iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); + return; + } + io->io_datasn += response->ip_additional_pdus + 1; + data_segment_len = icl_pdu_data_segment_length(response); if (data_segment_len == 0) { /* @@ -1096,7 +1116,6 @@ iscsi_pdu_handle_data_in(struct icl_pdu *response) icl_pdu_get_data(response, 0, csio->data_ptr + oreceived, data_segment_len); /* - * XXX: Check DataSN. * XXX: Check F. */ if ((bhsdi->bhsdi_flags & BHSDI_FLAGS_S) == 0) { diff --git a/sys/dev/iscsi/iscsi.h b/sys/dev/iscsi/iscsi.h index fe1cc64f88db..871fc6fc90e9 100644 --- a/sys/dev/iscsi/iscsi.h +++ b/sys/dev/iscsi/iscsi.h @@ -44,6 +44,7 @@ struct iscsi_outstanding { TAILQ_ENTRY(iscsi_outstanding) io_next; union ccb *io_ccb; size_t io_received; + uint32_t io_datasn; uint32_t io_initiator_task_tag; uint32_t io_referenced_task_tag; void *io_icl_prv;