[PATCH v6 3/9] nvme-auth: switch to use 'struct key'
Hannes Reinecke
hare at suse.de
Mon Nov 23 23:43:34 PST 2026
On 11/23/26 6:32 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] nvme-auth: memory leak of transformed_data in
> nvme_auth_transform_key()
> --
>
> commit 4697c9583f14fbc14890cc4dbfaed8c9987d382a
> Author: Hannes Reinecke <hare at kernel.org>
>
> nvme-auth: switch to use 'struct key'
>
> This commit switches NVMe DH-HMAC-CHAP key storage and handling from
> struct nvme_dhchap_key to struct key using the dhchap key type.
>
>> diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
>> index 308af3d7c7383..158c9cb886c15 100644
>> --- a/drivers/nvme/common/auth.c
>> +++ b/drivers/nvme/common/auth.c
> [ ... ]
>> @@ -317,11 +261,13 @@ static int nvme_auth_hash(u8 hmac_id, const u8 *data, size_t data_len, u8 *out)
>> return -EINVAL;
>> }
>>
>> -int nvme_auth_transform_key(const struct nvme_dhchap_key *key, const char *nqn,
>> +int nvme_auth_transform_key(struct key *key, const char *nqn,
>> u8 **transformed_secret)
>> {
> [ ... ]
>> + transformed_len = nvme_auth_hmac_hash_len(key_hash);
>> + transformed_data = kzalloc(transformed_len, GFP_KERNEL);
>> + if (!transformed_data) {
>> + ret = -ENOMEM;
>> + goto out_free_data;
>> + }
>> +
>> + ret = nvme_auth_hmac_init(&hmac, key_hash, key_data, key_len);
>> + if (ret)
>> + goto out_free_data;
>> nvme_auth_hmac_update(&hmac, nqn, strlen(nqn));
>> nvme_auth_hmac_update(&hmac, "NVMe-over-Fabrics", 17);
>> - nvme_auth_hmac_final(&hmac, key_data);
>> - *transformed_secret = key_data;
>> - return transformed_len;
>> + nvme_auth_hmac_final(&hmac, transformed_data);
>> + *transformed_secret = transformed_data;
>> + ret = transformed_len;
>> +out_free_data:
>> + kfree_sensitive(key_data);
>> + return ret;
>> }
>
> [Severity: Medium]
> Does this leak transformed_data when nvme_auth_hmac_init() fails and jumps
> to out_free_data?
>
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