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 B928BC04FFE for ; Wed, 8 May 2024 10:23:59 +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=4SkfdpW/5qI8irvrJt+sLDKxCO0FHArrOfuJpAmsQck=; b=mx1+/zPpiqxosmuVemBi5jhhFt Th0B0vIOucBlgaEjm1bfN1ga5HY6X1JfmPTAbrvR79smG7Dr5iSZlD7cNaqhL8Z7rO23cmM8xHhNe 8D4OQ1SZczc+23g/55pFT9Pp9wXVAB8sbQz+v3CBkuZFcoBi0hcpFRpJuhp1PZMIiXOD1FroyQvWi yOXtT2se4buRnJ/Tp9xlL0hOH7kmQ9TQuc4ep+yTEXxNXUrrRIVEPB2X7XlM31EXww9gdZBaNOhL1 YZAn1EU5I5SV9hCF3C2ovgAjZuoRlsyIYIfyFhQCKSouhoAkers0bqo0t0rfNabM4Gq73kA/lQ0zP l7nmWBfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4eSs-0000000EyJV-40vh; Wed, 08 May 2024 10:23:59 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4eSX-0000000Ey3A-20D0 for linux-nvme@lists.infradead.org; Wed, 08 May 2024 10:23:41 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EC82961B6F; Wed, 8 May 2024 10:23:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62697C4AF18; Wed, 8 May 2024 10:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715163816; bh=eFB/oHfFRpLCsmx64TOsCIXjlwEVRVqw8bcPyc9+or0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ph1fTzq1Sr2YAGpB4GF3Lm09engVPyQcjanYHH94MyNwbuW8O5FXD59cFrjc53CKL LhzuJPjP7z3KWsOFDuVrhJQPABnzKMfs4SC45jHVoYv3yinITY/IOCa3NssMGCm50b gsABXS58XcFmmVN8gZ7/NgggXAekw5g0oB0XAHzmiarPzmjAGawh+gS19Jwi03jc7t xcQl8iUiGZFP1NVArR9Y9k4lez+hY3yquE47EfZSOtSrJJqeMUm9WW2WTTSbISokk/ MRyVGOj+ymvYx4VcOvu+hOy0xfkjXFkieCmKmuk/yP0ZAsSS70a0D6vwHIh1N44MUD x9fsRnWz0wvMQ== From: Hannes Reinecke To: Christoph Hellwig Cc: Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org, Hannes Reinecke Subject: [PATCH 08/19] nvme-tcp: check for invalidated or revoked key Date: Wed, 8 May 2024 12:22:54 +0200 Message-Id: <20240508102305.108949-9-hare@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240508102305.108949-1-hare@kernel.org> References: <20240508102305.108949-1-hare@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_032337_801602_54E57A35 X-CRM114-Status: GOOD ( 14.17 ) 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 key_lookup() will always return a key, even if that key is revoked or invalidated. So check for invalid keys before continuing. Signed-off-by: Hannes Reinecke --- drivers/nvme/common/keyring.c | 21 +++++++++++++++++++++ drivers/nvme/host/fabrics.c | 2 +- drivers/nvme/host/tcp.c | 2 +- include/linux/nvme-keyring.h | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c index 845efabf8266..9e847c3ee820 100644 --- a/drivers/nvme/common/keyring.c +++ b/drivers/nvme/common/keyring.c @@ -20,6 +20,27 @@ key_serial_t nvme_keyring_id(void) } EXPORT_SYMBOL_GPL(nvme_keyring_id); +static bool nvme_tls_psk_revoked(struct key *psk) +{ + return (test_bit(KEY_FLAG_REVOKED, &psk->flags) || + test_bit(KEY_FLAG_INVALIDATED, &psk->flags)); +} + +struct key *nvme_tls_key_lookup(key_serial_t key_id) +{ + struct key *key = key_lookup(key_id); + if (IS_ERR(key)) { + pr_err("key id %08x not found\n", key_id); + return key; + } + if (nvme_tls_psk_revoked(key)) { + pr_err("key id %08x revoked\n", key_id); + return ERR_PTR(-EKEYREVOKED); + } + return key; +} +EXPORT_SYMBOL_GPL(nvme_tls_key_lookup); + static void nvme_tls_psk_describe(const struct key *key, struct seq_file *m) { seq_puts(m, key->description); diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index 0166f8a3a3eb..03004ef57a10 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -638,7 +638,7 @@ static struct key *nvmf_parse_key(int key_id) return ERR_PTR(-EINVAL); } - key = key_lookup(key_id); + key = nvme_tls_key_lookup(key_id); if (IS_ERR(key)) pr_err("key id %08x not found\n", key_id); else diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 62e06f042957..7a29d47dea28 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1590,7 +1590,7 @@ static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid) goto out_complete; } - tls_key = key_lookup(pskid); + tls_key = nvme_tls_key_lookup(pskid); if (IS_ERR(tls_key)) { dev_warn(ctrl->ctrl.device, "queue %d: Invalid key %x\n", qid, pskid); diff --git a/include/linux/nvme-keyring.h b/include/linux/nvme-keyring.h index d2b8a0783ad7..ae9bac51291e 100644 --- a/include/linux/nvme-keyring.h +++ b/include/linux/nvme-keyring.h @@ -14,7 +14,7 @@ key_serial_t nvme_tls_psk_default(struct key *keyring, const char *hostnqn, const char *subnqn); key_serial_t nvme_keyring_id(void); - +struct key *nvme_tls_key_lookup(key_serial_t key_id); #else static struct key *nvme_tls_psk_refresh(struct key *keyring, char *hostnqn, char *subnqn, @@ -31,5 +31,6 @@ static inline key_serial_t nvme_keyring_id(void) { return 0; } +static inline struct key *nvme_tls_key_lookup(key_serial_t key_id) { return ERR_PTR(-ENOTSUPP); } #endif /* !CONFIG_NVME_KEYRING */ #endif /* _NVME_KEYRING_H */ -- 2.35.3