From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53DDD322E for ; Wed, 29 Mar 2023 14:00:01 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D72A71FDF9; Wed, 29 Mar 2023 13:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680098389; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bwtZAIqMizlxRHNHYlOozFR+iuDe8mlNfS85V5xMYoE=; b=psmP7owC2L9KbyZhdyCjbAkgUQrh0MM3xx/AZCy8lP1j38ekYtEHgOoqVQX57QAN23J4vi e4YnaRvSxEQBYg1NB6Y3W0VRytexyNgDVlL+akHfx0vWl6g5oULx6gWkhYjpmiopCH2TYW Q9Wjnq7Wc98RlqdNTHk/yDmKBvcSFmU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680098389; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bwtZAIqMizlxRHNHYlOozFR+iuDe8mlNfS85V5xMYoE=; b=or5tdVFXMNw5FRVb1XSVX+Cuqvcq2L9+r4DKZJKyYRugl27jKOz6MYk6S/wFNzc8euskJl PDn4PifeTOnhLYDA== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id C5FE42C17E; Wed, 29 Mar 2023 13:59:49 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id C3BAD51BF388; Wed, 29 Mar 2023 15:59:49 +0200 (CEST) From: Hannes Reinecke To: Christoph Hellwig Cc: Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org, Chuck Lever , kernel-tls-handshake@lists.linux.dev, Hannes Reinecke Subject: [PATCH 11/18] nvme-tcp: control message handling for recvmsg() Date: Wed, 29 Mar 2023 15:59:31 +0200 Message-Id: <20230329135938.46905-12-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230329135938.46905-1-hare@suse.de> References: <20230329135938.46905-1-hare@suse.de> Precedence: bulk X-Mailing-List: kernel-tls-handshake@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit kTLS is sending TLS ALERT messages as control messages for recvmsg(). As we can't do anything sensible with it just abort the connection and let the userspace agent to a re-negotiation. Signed-off-by: Hannes Reinecke --- drivers/nvme/host/tcp.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 54d27873227a..2e15fa83b725 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1377,6 +1377,11 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) { struct nvme_tcp_icreq_pdu *icreq; struct nvme_tcp_icresp_pdu *icresp; +#ifdef CONFIG_NVME_TLS + char cbuf[CMSG_LEN(sizeof(char))] = {}; + struct cmsghdr *cmsg; + unsigned char ctype; +#endif struct msghdr msg = {}; struct kvec iov; bool ctrl_hdgst, ctrl_ddgst; @@ -1414,11 +1419,27 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) memset(&msg, 0, sizeof(msg)); iov.iov_base = icresp; iov.iov_len = sizeof(*icresp); +#ifdef CONFIG_NVME_TLS + msg.msg_control = cbuf; + msg.msg_controllen = sizeof(cbuf); +#endif ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, iov.iov_len, msg.msg_flags); if (ret < 0) goto free_icresp; - +#ifdef CONFIG_NVME_TLS + cmsg = (struct cmsghdr *)cbuf; + if (CMSG_OK(&msg, cmsg) && + cmsg->cmsg_level == SOL_TLS && + cmsg->cmsg_type == TLS_GET_RECORD_TYPE) { + ctype = *((unsigned char *)CMSG_DATA(cmsg)); + if (ctype != TLS_RECORD_TYPE_DATA) { + pr_err("queue %d: unhandled TLS record %d\n", + nvme_tcp_queue_id(queue), ctype); + return -ENOTCONN; + } + } +#endif ret = -EINVAL; if (icresp->hdr.type != nvme_tcp_icresp) { pr_err("queue %d: bad type returned %d\n", -- 2.35.3