[PATCH v7 10/14] nvme-auth: allow to specify the key by key serial
Hannes Reinecke
hare at suse.de
Fri Nov 27 01:13:33 PST 2026
On 11/26/26 3:26 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] nvme-auth: missing key type validation in
> nvme_auth_extract_key()
> - [Low] nvme-auth: key_serial truncation to key_serial_t in
> nvme_auth_extract_key()
> --
>
> commit 7d31006b6164c1d407e94a069e4daf6dec180cf1
> Author: Hannes Reinecke <hare at kernel.org>
>
> nvme-auth: allow to specify the key by key serial
>
> This commit updates nvme_auth_extract_key() to parse a numeric key serial
> and look up the key via key_lookup() before falling back to key description
> lookup or key generation.
>
>> diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
>> index 15e72fe8868af..e336c698437dc 100644
>> --- a/drivers/nvme/common/auth.c
>> +++ b/drivers/nvme/common/auth.c
>> @@ -148,7 +148,7 @@ EXPORT_SYMBOL_GPL(nvme_auth_hmac_hash_len);
>> * @generated: indicate whether a key has been generated
>> *
>> * Extracts or generates a key from @input.
>> - * @input can either be a key description or raw key data; in
>> + * @input can be a key serial, a key description or raw key data; in
>> * the latter case a key is generated from @input and
>> * @generated is set to 'true'.
>> *
>> @@ -158,7 +158,18 @@ struct key *nvme_auth_extract_key(const char *input, size_t input_len,
>> bool *generated)
>> {
>> struct key *key;
>> -
>> + unsigned long key_serial;
>> + int err;
>> +
>> + /* Check if @input is a key serial */
>> + err = kstrtoul(input, 0, &key_serial);
>> + if (!err) {
>> + key = key_lookup(key_serial);
>
> [Severity: Low]
> Can kstrtoul() silently truncate 64-bit values when key_serial is passed to
> key_lookup()? key_serial_t is int32_t and valid serials are positive, so a
> numeric string larger than INT_MAX on 64-bit platforms is narrowed to its
> lower 32 bits instead of being rejected. Parsing with kstrtos32() and
> checking key_serial > 0 would avoid this.
>
Fixed with the next version.
>> + if (!IS_ERR(key)) {
>> + *generated = false;
>> + return key;
>> + }
>> + }
>
> [Severity: High]
> Can key_lookup() return a key that is not a positively instantiated
> nvme_dhchap_psk_key_type key?
>
> Unlike nvme_dhchap_psk_lookup(), key_lookup() searches the global serial
> tree without checking key->type or instantiation state. When
> nvme_auth_transform_key() later runs, it unconditionally calls user_read()
> and nvme_dhchap_psk_hash(), which read key->payload.rcu_data0 as a struct
> user_key_payload and access 6 bytes past upayload->datalen:
>
> drivers/nvme/common/keyring.c:nvme_dhchap_psk_hash() {
> ...
> upayload = user_key_payload_locked(key);
> hmac = upayload->data[upayload->datalen + 5];
> return hmac;
> }
>
> Passing the serial of an uninstantiated key, a keyring, or another key type
> (such as user, logon, or NVMe TLS PSK, where user_preparse() only allocates
> upayload->datalen bytes) causes a NULL pointer dereference, type confusion,
> or a 6-byte slab out-of-bounds read.
>
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