nvme-tcp: check for invalidated or revoked key
authorHannes Reinecke <hare@kernel.org>
Mon, 22 Jul 2024 12:02:20 +0000 (14:02 +0200)
committerKeith Busch <kbusch@kernel.org>
Thu, 22 Aug 2024 20:25:07 +0000 (13:25 -0700)
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>
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 a3caef75aa0a8374069a3f324f75ef8db8d384fb..883aaab2d83e32b0f04f481102594b97334f6ab0 100644 (file)
@@ -109,6 +109,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 f5f545fa0103547444f5531434b9bdea3e3a521e..432efcbf9e2f5f7be9edcd3364434d421f88c29f 100644 (file)
@@ -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
index b40e95bee84955e64447f57f7f3255177465e7ff..89c44413c59394e57d315c9f1cbc9a333dff74af 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 */