From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6453DC00528 for ; Thu, 3 Aug 2023 10:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LDukVeTcAcyShCFS4ee6afRX8c+3sxfriXRpHY74zEU=; b=BIO4CPbw3yDF9Ob5flxf8SmdEC 0mvWAMHKehQIqhT0E+aSJcSrYXh7RRBKSw6K+Nl6a/5Aq4V6ZImIMIqutthf4dU1GrYtSmZ92YW0W RjDsNAhIWeMjEI+G5aDN7zwaAnVWS+aSg5Fyc9NhMVGAYjJMpvT/HGlsKB/cxJvbu6D3937LGe7gF ppX5HUljnXmgrgpVV/yLOx6jeKYyux+J4jKGNe4bC9CCHH/cU0nG2NDL+/O5j4kaA2bYP7Piy7TOU +EyR5HifgZrQ0dT1Xs8oHbwXz4bj6g+fElvcoxz6Ou85t5rvgcM6wxvViQSFIlN6u3Q6cV7NLFuBu Uc2dxYBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRVxM-007XIC-1U; Thu, 03 Aug 2023 10:53:24 +0000 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRVxB-007X7p-1l for linux-nvme@lists.infradead.org; Thu, 03 Aug 2023 10:53:17 +0000 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 597452199E; Thu, 3 Aug 2023 10:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691059989; 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=LDukVeTcAcyShCFS4ee6afRX8c+3sxfriXRpHY74zEU=; b=pDQRkAEqbSbkn173zj4CfJs0NNvb9Y90mnP0z3yDPT3HRrAM6jQJcHAG0wq9K3xI8y1W9F h9Q7SvTvxsOcmG192TNE5O2yfzjYU4c+C+l+g4Eia4RpwWSvH3D8Amg1730tvj5aY6Po2N ZDprVzpgBsunoliE1/XEHDV5/xFYDRw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691059989; 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=LDukVeTcAcyShCFS4ee6afRX8c+3sxfriXRpHY74zEU=; b=l9WH5q//355dAWo6hAXmc2tXstAR2jnLbCe2DRHrfUos9/se20VNmzI0/wUyoO/5WjZEYf 28cRLlrwjuZZaCDA== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 4CC5F2C14B; Thu, 3 Aug 2023 10:53:09 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 4667051CA7C9; Thu, 3 Aug 2023 12:53:09 +0200 (CEST) From: Hannes Reinecke To: Christoph Hellwig Cc: Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org, Hannes Reinecke Subject: [PATCH 05/14] nvme-keyring: implement nvme_tls_psk_default() Date: Thu, 3 Aug 2023 12:50:53 +0200 Message-Id: <20230803105102.30949-6-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230803105102.30949-1-hare@suse.de> References: <20230803105102.30949-1-hare@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230803_035314_255824_BE5CB4BC X-CRM114-Status: GOOD ( 13.61 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org Implement a function to select the preferred PSK for TLS. Signed-off-by: Hannes Reinecke --- drivers/nvme/common/keyring.c | 48 +++++++++++++++++++++++++++++++++++ include/linux/nvme-keyring.h | 8 ++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c index 494dd365052e..f8d9a208397b 100644 --- a/drivers/nvme/common/keyring.c +++ b/drivers/nvme/common/keyring.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -103,6 +104,53 @@ static struct key *nvme_tls_psk_lookup(struct key *keyring, return key_ref_to_ptr(keyref); } +/* + * NVMe PSK priority list + * + * 'Retained' PSKs (ie 'generated == false') + * should be preferred to 'generated' PSKs, + * and SHA-384 should be preferred to SHA-256. + */ +struct nvme_tls_psk_priority_list { + bool generated; + enum nvme_tcp_tls_cipher cipher; +} nvme_tls_psk_prio[] = { + { .generated = false, + .cipher = NVME_TCP_TLS_CIPHER_SHA384, }, + { .generated = false, + .cipher = NVME_TCP_TLS_CIPHER_SHA256, }, + { .generated = true, + .cipher = NVME_TCP_TLS_CIPHER_SHA384, }, + { .generated = true, + .cipher = NVME_TCP_TLS_CIPHER_SHA256, }, +}; + +/* + * nvme_tls_psk_default - Return the preferred PSK to use for TLS ClientHello + */ +key_serial_t nvme_tls_psk_default(struct key *keyring, + const char *hostnqn, const char *subnqn) +{ + struct key *tls_key; + key_serial_t tls_key_id; + int prio; + + for (prio = 0; prio < ARRAY_SIZE(nvme_tls_psk_prio); prio++) { + bool generated = nvme_tls_psk_prio[prio].generated; + enum nvme_tcp_tls_cipher cipher = nvme_tls_psk_prio[prio].cipher; + + tls_key = nvme_tls_psk_lookup(keyring, hostnqn, subnqn, + cipher, generated); + if (!IS_ERR(tls_key)) { + tls_key_id = tls_key->serial; + key_put(tls_key); + return tls_key_id; + } + } + return 0; +} +EXPORT_SYMBOL_GPL(nvme_tls_psk_default); + int nvme_keyring_init(void) { int err; diff --git a/include/linux/nvme-keyring.h b/include/linux/nvme-keyring.h index 32bd264a71e6..4efea9dd967c 100644 --- a/include/linux/nvme-keyring.h +++ b/include/linux/nvme-keyring.h @@ -8,12 +8,20 @@ #ifdef CONFIG_NVME_KEYRING +key_serial_t nvme_tls_psk_default(struct key *keyring, + const char *hostnqn, const char *subnqn); + key_serial_t nvme_keyring_id(void); int nvme_keyring_init(void); void nvme_keyring_exit(void); #else +static inline key_serial_t nvme_tls_psk_default(struct key *keyring, + const char *hostnqn, const char *subnqn) +{ + return 0; +} static inline key_serial_t nvme_keyring_id(void) { return 0; -- 2.35.3