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 D687FC3DA70 for ; Fri, 19 Jul 2024 08:39:23 +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=sAepxMPxWpRLrJB02nZ6PdLR5kzlIwfxsuW6o8Ne7pY=; b=A5aKujq1lHamKGvJmxINCDFVF1 CyjTGGJdSNjgVD8CQT89qqkai5HcYJS9kmujalZ+y0LEifXCLLkN7xSBbgwBOL+TTqANItikt7pRF 1NsSQUkSbppZ864ycd8O+eIoJZXomJrmAqoVXH6VhgYrbH2L/+cncr2tEf6mwQVo6+oDm9Z7Rfk55 RNMeNvd4IPTOPytAsiHZZfyAQ0MR2jtRn5Lr9efCo4DwKVL3tdY5ruNYltbsA3EV/QAQImVIfRyX2 +xv3dQMR6XFxLGGvBCIUqwKoPX58vuPbBckYEQ+bg/An2peOtoIQU7X3I4fz84ZAhwqOw1wUScD2J 7OWmoutg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUj99-000000026FD-24Pf; Fri, 19 Jul 2024 08:39:23 +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 1sUj96-000000026DT-12Jm for linux-nvme@lists.infradead.org; Fri, 19 Jul 2024 08:39:21 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6DC9A61C5B; Fri, 19 Jul 2024 08:39:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 015F5C32782; Fri, 19 Jul 2024 08:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721378359; bh=QP57Fa7s0v/z3YLBxb7yEnSNuLfnPiIHZjZ9gbfyrn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+MHJaPWYJAtay/nT8ovr+2/lH/LBLZtgVIwsnMUchklmAxigGzzYQCOuUhMGkD8h hiH4CHDRTDuOb4bvnciKko3PF7/wfPt/c1VP+0S96exK0ikn2pIWJj4AuKFsJET+oI skL1dBhHipSBY949RPe0lJrmjW06nzfvHMMsUPLDpbzBu7RE5i5H//YGamRFafc/xY 1bs8ujjg2XalIK5DeZ8oJYqrd5vPH/VxXDnwfEXwfkDDpXgcpa3/QryWqi/DwuC3Ym UVTsqnn1BF24ESgzFDb9iemfJHxEkNb4hdwthGum4CATcUUIO1XBHxebNwj9HrJiwX Q9a0DUSnYcv3g== From: Hannes Reinecke To: Christoph Hellwig Cc: Keith Busch , Sagi Grimberg , linux-nvme@lists.infradead.org, Hannes Reinecke Subject: [PATCH 3/9] nvme-tcp: check for invalidated or revoked key Date: Fri, 19 Jul 2024 10:38:55 +0200 Message-Id: <20240719083901.35399-4-hare@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240719083901.35399-1-hare@kernel.org> References: <20240719083901.35399-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-20240719_013920_435637_F4F4394E X-CRM114-Status: GOOD ( 14.08 ) 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 Reviewed-by: Sagi Grimberg --- drivers/nvme/common/keyring.c | 22 ++++++++++++++++++++++ drivers/nvme/host/fabrics.c | 2 +- drivers/nvme/host/tcp.c | 2 +- include/linux/nvme-keyring.h | 6 +++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c index 05e89307c8aa..ed5167f942d8 100644 --- a/drivers/nvme/common/keyring.c +++ b/drivers/nvme/common/keyring.c @@ -20,6 +20,28 @@ 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 f5f545fa0103..432efcbf9e2f 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -665,7 +665,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 92ad5b8cc1b4..5885aa452aa1 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 e10333d78dbb..19d2b256180f 100644 --- a/include/linux/nvme-keyring.h +++ b/include/linux/nvme-keyring.h @@ -12,7 +12,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 inline key_serial_t nvme_tls_psk_default(struct key *keyring, @@ -24,5 +24,9 @@ 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