[PATCH v6 3/9] nvme-auth: switch to use 'struct key'
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 23 09:32:59 PST 2026
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?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v6-0-5082a49715ab@kernel.org?part=3
More information about the Linux-nvme
mailing list