[PATCH v7 06/14] nvme-auth: switch to use 'struct key'
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Thu Nov 26 06:33:18 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvme-keyring: nvme_dhchap_psk_create() overwrites
key_create() error codes
--
commit d2027ac3b70964c8a70b1644b2224565f8d1e622
Author: Hannes Reinecke <hare at kernel.org>
nvme-auth: switch to use 'struct key'
This commit replaces struct nvme_dhchap_key with the kernel keyring's
struct key using the "dhchap" key type for storing and transforming
DH-HMAC-CHAP keys.
> diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c
> index 0fc6b4825c2dd..dc0a4fb9296f1 100644
> --- a/drivers/nvme/common/keyring.c
> +++ b/drivers/nvme/common/keyring.c
> @@ -464,6 +464,91 @@ static struct key_type nvme_dhchap_psk_key_type = {
> .read = nvme_dhchap_psk_read,
> };
>
> +/**
> + * nvme_dhchap_psk_create - Create DH-HMAC-CHAP key
> + * @data: Key data
> + * @data_len: Length of @data
> + *
> + * Creates a new DH-HMAC-CHAP key with a random UUID as the key identity.
> + * Returns the new key or an error pointer on failure.
> + */
> +struct key *nvme_dhchap_psk_create(const char *data, size_t data_len)
> +{
> + key_perm_t keyperm =
> + KEY_POS_SEARCH | KEY_POS_VIEW | KEY_POS_READ |
> + KEY_POS_WRITE | KEY_POS_LINK | KEY_POS_SETATTR |
> + KEY_USR_SEARCH | KEY_USR_VIEW | KEY_USR_READ;
> + char *identity;
> + key_ref_t keyref;
> + struct key *key;
> + uuid_t key_uuid;
> +
> + if (data == NULL || !data_len)
> + return ERR_PTR(-EINVAL);
> +
> + generate_random_uuid(key_uuid.b);
> + identity = kasprintf(GFP_KERNEL, "%pU", &key_uuid);
> + if (!identity)
> + return ERR_PTR(-ENOMEM);
> +
> + pr_debug("generate dhchap psk '%s'\n", identity);
> + keyref = key_create(make_key_ref(nvme_keyring, true),
> + "dhchap", identity, data, data_len,
> + keyperm, KEY_ALLOC_NOT_IN_QUOTA |
> + KEY_ALLOC_BUILT_IN |
> + KEY_ALLOC_BYPASS_RESTRICTION);
> + if (IS_ERR(keyref)) {
> + pr_warn("refresh dhchap psk '%s' failed, error %ld\n",
> + identity, PTR_ERR(keyref));
> + kfree(identity);
> + return ERR_PTR(-ENOKEY);
> + }
[Severity: Medium]
Should this return ERR_CAST(keyref) instead of ERR_PTR(-ENOKEY)?
When key_create() fails in nvme_dhchap_psk_preparse(), such as returning
-EINVAL for a malformed secret or -EKEYREJECTED for a CRC mismatch,
discarding PTR_ERR(keyref) causes nvme_auth_extract_key() callers like
dhchap_secret_store() to report -ENOKEY to userspace instead of the
underlying error code.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-dhchap-keyring-v4-v7-0-ee438ffea527@kernel.org?part=6
More information about the Linux-nvme
mailing list