Re: [PATCH 1/8] nvme-auth: modify nvme_auth_transform_key() to return status

Maurizio Lombardi
2026-03-17T13:09:18Z

On Tue Mar 17, 2026 at 2:00 PM CET, Hannes Reinecke wrote:
> In preparation for converting the DH-HMAC-CHAP code to use the
> kernel keyring modify nvme_auth_transform_key() to return a status
> and provide the transformed data as argument on the command line as
> raw data.
>
> Signed-off-by: Hannes Reinecke <hare@kernel.org>
> ---
> drivers/nvme/common/auth.c | 38 ++++++++++++++++----------------
> drivers/nvme/host/auth.c | 44 ++++++++++++++++++++------------------
> drivers/nvme/target/auth.c | 37 ++++++++++++++++++--------------
> include/linux/nvme-auth.h | 4 ++--
> 4 files changed, 65 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
> index 2d325fb93083..772af9b6dccd 100644
> --- a/drivers/nvme/common/auth.c
> +++ b/drivers/nvme/common/auth.c
> @@ -317,37 +317,37 @@ static int nvme_auth_hash(u8 hmac_id, const u8 *data, size_t data_len, u8 *out)
> return -EINVAL;
> }
>
> -struct nvme_dhchap_key *nvme_auth_transform_key(
> - const struct nvme_dhchap_key *key, const char *nqn)
> +int nvme_auth_transform_key(const struct nvme_dhchap_key *key, const char *nqn,
> + u8 **transformed_secret)
> {
> struct nvme_auth_hmac_ctx hmac;
> - struct nvme_dhchap_key *transformed_key;
> - int ret, key_len;
> + u8 *transformed_data;
> + u8 *key_data;
> + size_t transformed_len;
> + int ret;
>
> if (!key) {
> pr_warn("No key specified\n");
> - return ERR_PTR(-ENOKEY);
> + return -ENOKEY;
> }
> if (key->hash == 0) {
> - key_len = nvme_auth_key_struct_size(key->len);
> - transformed_key = kmemdup(key, key_len, GFP_KERNEL);
> - if (!transformed_key)
> - return ERR_PTR(-ENOMEM);
> - return transformed_key;
> + key_data = kzalloc(key->len, GFP_KERNEL);
> + memcpy(key_data, key->key, key->len);

Nit: unchecked kzalloc() return value

Maurizio