]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvme-tcp: check for invalidated or revoked key
authorHannes Reinecke <hare@kernel.org>
Mon, 22 Jul 2024 12:02:20 +0000 (14:02 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:00:18 +0000 (12:00 +0200)
[ Upstream commit 5bc46b49c828a6dfaab80b71ecb63fe76a1096d2 ]

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 <hare@kernel.org>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/common/keyring.c
drivers/nvme/host/Kconfig
drivers/nvme/host/fabrics.c
drivers/nvme/host/tcp.c
include/linux/nvme-keyring.h

index 05e89307c8aa34876d4dc734307aa9c786949c11..ed5167f942d89bf2a6806f28af946bf4041b7eb0 100644 (file)
@@ -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);
index b309c8be720f47c8d8a38e62d29f565e1e90358d..854eb26ac3db95ad6c6f9767626cfdf3847f2c0b 100644 (file)
@@ -110,6 +110,7 @@ config NVME_HOST_AUTH
        bool "NVMe over Fabrics In-Band Authentication in host side"
        depends on NVME_CORE
        select NVME_AUTH
+       select NVME_KEYRING if NVME_TCP_TLS
        help
          This provides support for NVMe over Fabrics In-Band Authentication in
          host side.
index b5a4b5fd573e0d6c330d977de1cae1fd92c276e0..3e3db6a6524e0473fc8e12bedd7def4288ace676 100644 (file)
@@ -650,7 +650,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
index f55160969180778a334794a9e789535ae05de5dd..8c79af3ed1f23e8b8d75de5ac4dfe18af8947c60 100644 (file)
@@ -1596,7 +1596,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);
index e10333d78dbbe539f3011a85d5e221d102560c99..19d2b256180fd7f9d0e9d9d2759df2c9d3d19f7e 100644 (file)
@@ -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 */