[PATCH v7 06/14] nvme-auth: switch to use 'struct key'
Hannes Reinecke
hare at suse.de
Thu Nov 26 23:23:06 PST 2026
On 11/26/26 3:33 PM, sashiko-bot at kernel.org wrote:
> 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.
>
Fixed with the next version.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
More information about the Linux-nvme
mailing list