From patchwork Wed Aug 16 12:05:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13355094 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D131AFBFA for ; Wed, 16 Aug 2023 12:06:26 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05298212F for ; Wed, 16 Aug 2023 05:06:25 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B730D1F74D; Wed, 16 Aug 2023 12:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692187583; 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; bh=DZ1ncX8MD+/Gp3qJN8kGvC8a+Gt4kiciWaOpWvSDF9Y=; b=DrqEu7nD1hBw7snZvH0QlGUJUUBMINaIewQFhHohzo0ikO9wMfPlu2BaePevyvYZrsG7en 06H6cGVyo7Sx44uKm0DPfIoYrOkhVKbaSAUwreyRaQJh9bM5bis4d5TZ3v8K4W/yB1ItcN MOTVweWrnF8s6HH9A4ihnBbNBssjHHI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692187583; 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; bh=DZ1ncX8MD+/Gp3qJN8kGvC8a+Gt4kiciWaOpWvSDF9Y=; b=7vtCcX2LM+W0qGf5FkuqmajUeSBSGNWp1psxGAz2dq/P1slKkUAaL0PL1p2rAfK69WhCDd UMojEjPKvypc46BQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 8DBAE2C143; Wed, 16 Aug 2023 12:06:23 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 78AE551CB21C; Wed, 16 Aug 2023 14:06:23 +0200 (CEST) From: Hannes Reinecke To: Christoph Hellwig Cc: Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org, Jakub Kicinski , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, Hannes Reinecke Subject: [PATCHv10 00/18] nvme: In-kernel TLS support for TCP Date: Wed, 16 Aug 2023 14:05:50 +0200 Message-Id: <20230816120608.37135-1-hare@suse.de> X-Mailer: git-send-email 2.35.3 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Hi all, with the merge of Chuck Levers handshake upcall mechanism and my tls_read_sock() implementation finally merged with net-next it's now time to restart on the actual issue, namely implementing in-kernel TLS support for nvme-tcp. The patchset is based on the recent net-next git tree; everything after commit ba4a734e1aa0 ("net/tls: avoid TCP window full during ->read_sock()") should work. You might want to add the patch 'nvmet-tcp: use 'spin_lock_bh' for state_lock()' before applying this patchset; otherwise results might be ... interesting. It also requires the 'tlshd' userspace daemon (https://github.com/oracle/ktls-utils) for the actual TLS handshake. Changes for nvme-cli are already included in the upstream repository. Theory of operation: A dedicated '.nvme' keyring is created to hold the pre-shared keys (PSKs) for the TLS handshake. Keys will have to be provisioned before TLS handshake is attempted; that can be done with the 'nvme gen-tls-key' command for nvme-cli (patches are already merged upstream). After connection to the remote TCP port the client side will use the 'best' PSK (as inferred from the NVMe TCP spec) or the PSK specified by the '--tls_key' option to nvme-cli and call the TLS userspace daemon to initiate a TLS handshake. The server side will then invoke the TLS userspace daemon to run the TLS handshake. If the TLS handshake succeeds the userspace daemon will be activating kTLS on the socket, and control is passed back to the kernel. This implementation currently does not implement the so-called 'secure concatenation' mode from NVMe-TCP; a TPAR is still pending with fixes for it, so I'll wait until it's published before posting patches for that. Patchset can be found at: git.kernel.org/pub/scm/linux/kernel/git/hare/nvme.git branch tls.v15 For testing I'm using this script, running on a nvme target with NQN 'nqn.test' and using 127.0.0.1 as a port; the port has to set 'addr_tsas' to 'tls1.3': modprobe nvmet-tcp nvmetcli restore modprobe nvme-tcp ./nvme gen-tls-key --subsysnqn=nqn.test -i ./nvme gen-tls-key --subsysnqn=nqn.2014-08.org.nvmexpress.discovery -i tlshd -c /etc/tlshd.conf and then one can do a simple: # nvme connect -t tcp -a 127.0.0.1 -s 4420 -n nqn.test --tls to start the connection. As usual, comments and reviews are welcome. Changes to v9: - Close race between done() and timeout() - Add logging message for icreq/icresp failure - Sparse fixes - Restrict TREQ setting to 'not required' or 'required' when TLS is enabled Changes to v8: - Simplify reference counting as suggested by Sagi - Implement nvmf_parse_key() to simplify options parsing - Add patch to peek at icreq to figure out whether TLS should be started Changes to v7: - Include reviews from Simon - Do not call sock_release() when sock_alloc_file() fails Changes to v6: - More reviews from Sagi - Fixup non-tls connections - Fixup nvme options handling - Add reference counting to nvmet-tcp queues Changes to v5: - Include reviews from Sagi - Split off nvmet tsas/treq handling - Sanitize sock_file handling Changes to v4: - Split off network patches into a separate patchset - Handle TLS Alert notifications Changes to v3: - Really handle MSG_EOR for TLS - Fixup MSG_SENDPAGE_NOTLAST handling - Conditionally disable fabric option Changes to v2: - Included reviews from Sagi - Removed MSG_SENDPAGE_NOTLAST - Improved MSG_EOR handling for TLS - Add config options NVME_TCP_TLS and NVME_TARGET_TCP_TLS Changes to the original RFC: - Add a CONFIG_NVME_TLS config option - Use a single PSK for the TLS handshake - Make TLS connections mandatory - Do not peek messages for the server - Simplify data_ready callback - Implement read_sock() for TLS Hannes Reinecke (18): nvme-keyring: register '.nvme' keyring nvme-keyring: define a 'psk' keytype nvme: add TCP TSAS definitions nvme-tcp: add definitions for TLS cipher suites nvme-keyring: implement nvme_tls_psk_default() security/keys: export key_lookup() nvme-tcp: allocate socket file nvme-tcp: enable TLS handshake upcall nvme-tcp: control message handling for recvmsg() nvme-tcp: improve icreq/icresp logging nvme-fabrics: parse options 'keyring' and 'tls_key' nvmet: make TCP sectype settable via configfs nvmet-tcp: make nvmet_tcp_alloc_queue() a void function nvmet-tcp: allocate socket file nvmet: Set 'TREQ' to 'required' when TLS is enabled nvmet-tcp: enable TLS handshake upcall nvmet-tcp: control messages for recvmsg() nvmet-tcp: peek icreq before starting TLS drivers/nvme/common/Kconfig | 4 + drivers/nvme/common/Makefile | 3 +- drivers/nvme/common/keyring.c | 182 ++++++++++++++++++ drivers/nvme/host/Kconfig | 15 ++ drivers/nvme/host/core.c | 12 +- drivers/nvme/host/fabrics.c | 64 ++++++- drivers/nvme/host/fabrics.h | 9 + drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/sysfs.c | 21 +++ drivers/nvme/host/tcp.c | 184 +++++++++++++++++-- drivers/nvme/target/Kconfig | 15 ++ drivers/nvme/target/configfs.c | 128 ++++++++++++- drivers/nvme/target/nvmet.h | 11 ++ drivers/nvme/target/tcp.c | 326 ++++++++++++++++++++++++++++++--- include/linux/key.h | 1 + include/linux/nvme-keyring.h | 36 ++++ include/linux/nvme-tcp.h | 6 + include/linux/nvme.h | 10 + security/keys/key.c | 1 + 19 files changed, 980 insertions(+), 49 deletions(-) create mode 100644 drivers/nvme/common/keyring.c create mode 100644 include/linux/nvme-keyring.h