From: Hannes Reinecke <hare@suse.de>
To: sashiko-reviews@lists.linux.dev, Hannes Reinecke <hare@kernel.org>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v4 1/9] nvme-auth: modify nvme_auth_transform_key() to return status
Date: Fri, 20 Nov 2026 12:42:01 +0100 [thread overview]
Message-ID: <68297149-c8d3-4dee-997e-5821698b4e23@suse.de> (raw)
In-Reply-To: <sashiko-outbox-225021@kernel.org>
On 11/20/26 12:19 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] nvme-auth: NULL pointer dereference in
> nvme_auth_transform_key()
> - [Low] nvme-auth: unused variable transformed_data in
> nvme_auth_transform_key()
> - [Low] nvme-auth: missing memzero_explicit() on error in
> nvme_auth_transform_key()
> --
>
> commit b03dd5c2705fd9466c887dbc6671b901be8cc15b
> Author: Hannes Reinecke <hare@kernel.org>
>
> nvme-auth: modify nvme_auth_transform_key() to return status
>
> This commit changes nvme_auth_transform_key() to return the transformed key
> length or a negative error code and pass the allocated raw secret buffer via
> an output pointer, updating all callers in the NVMe host and target auth code.
>
>> diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
>> index 1fdc4e4ed0b94..569f21ad4fc7e 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;
>
> [Severity: Low]
> Is transformed_data unused in this patch? Declaring it here triggers a
> -Wunused-variable warning until later commit "nvme-auth: switch to use
> 'struct key'" uses it.
>
Okay, will be removing it.
>>
>> 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);
>> + *transformed_secret = key_data;
>> + return key->len;
>> }
>
> [Severity: High]
> Can this cause a NULL pointer dereference in memcpy() if kzalloc() fails
> when key->hash == 0? A later patch in the series, commit "nvme-auth: switch
> to use 'struct key'", adds a NULL check on key_data, but intermediate
> commits can crash here on allocation failure.
>
Fixed up for the next version.
>> ret = nvme_auth_hmac_init(&hmac, key->hash, key->key, key->len);
>> if (ret)
>> - return ERR_PTR(ret);
>> - key_len = nvme_auth_hmac_hash_len(key->hash);
>> - transformed_key = nvme_auth_alloc_key(key_len, key->hash);
>> - if (!transformed_key) {
>> - memzero_explicit(&hmac, sizeof(hmac));
>> - return ERR_PTR(-ENOMEM);
>> - }
>> + return ret;
>> + transformed_len = nvme_auth_hmac_hash_len(key->hash);
>> + key_data = kzalloc(transformed_len, GFP_KERNEL);
>> + if (!key_data)
>> + return -ENOMEM;
>
> [Severity: Low]
> Should this error path call memzero_explicit(&hmac, sizeof(hmac)) before
> returning -ENOMEM, as the code did prior to this patch so key-derived HMAC
> state is not left on the stack?
>
Fixed up for the next version.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@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
next prev parent reply other threads:[~2026-11-20 11:42 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 11:13 [PATCH v4 0/9] nvme-auth: switch to use the kernel keyring Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 1/9] nvme-auth: modify nvme_auth_transform_key() to return status Hannes Reinecke
2026-11-20 11:19 ` sashiko-bot
2026-11-20 11:42 ` Hannes Reinecke [this message]
2026-11-20 11:14 ` [PATCH v4 2/9] nvme-keyring: add 'dhchap' key type Hannes Reinecke
2026-11-20 11:28 ` sashiko-bot
2026-11-20 12:28 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 3/9] nvme-auth: switch to use 'struct key' Hannes Reinecke
2026-11-20 11:31 ` sashiko-bot
2026-11-20 13:08 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 4/9] nvme: parse dhchap keys during option parsing Hannes Reinecke
2026-11-20 11:32 ` sashiko-bot
2026-11-20 13:55 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 5/9] nvmet-auth: parse dhchap key from configfs attribute Hannes Reinecke
2026-11-20 11:28 ` sashiko-bot
2026-11-20 14:15 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 6/9] nvme: allow to pass in key description as dhchap secret Hannes Reinecke
2026-11-20 11:31 ` sashiko-bot
2026-11-20 14:48 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 7/9] nvme-auth: wait for authentication to finish when changing keys Hannes Reinecke
2026-11-20 11:26 ` sashiko-bot
2026-11-20 14:52 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 8/9] nvme-fabrics: allow to pass in keyring by name Hannes Reinecke
2026-11-20 11:37 ` sashiko-bot
2026-11-20 15:02 ` Hannes Reinecke
2026-11-20 11:14 ` [PATCH v4 9/9] nvmet: add configfs attribute 'dhchap_keyring' Hannes Reinecke
2026-11-20 11:39 ` sashiko-bot
2026-11-20 15:27 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68297149-c8d3-4dee-997e-5821698b4e23@suse.de \
--to=hare@suse.de \
--cc=hare@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox