[PATCH v7 09/14] nvme: allow to pass in key description as dhchap secret
Hannes Reinecke
hare at suse.de
Thu Nov 26 23:40:00 PST 2026
On 11/26/26 3:27 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] nvme-auth: ERR_PTR dereference after key_lookup() in show and
> init helpers
> - [Medium] nvmet-auth: wrong generated flag updated in
> nvmet_auth_update_key()
> --
>
> commit 23f2a5a7beef9101cd52fed1a3096af44469d991
> Author: Hannes Reinecke <hare at kernel.org>
>
> nvme: allow to pass in key description as dhchap secret
>
> This commit updates nvme_auth_extract_key() to look up pre-populated
> keys by description in addition to generating keys from raw secret data,
> and tracks whether keys were auto-generated so pre-populated keys are
> not revoked on teardown.
>
>> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
>> index ff0e8569d7067..54e79c8a7cae6 100644
>> --- a/drivers/nvme/target/auth.c
>> +++ b/drivers/nvme/target/auth.c
>> @@ -20,31 +20,38 @@
>> #include "nvmet.h"
>>
>> static void nvmet_auth_update_key(struct nvmet_host *host, bool set_ctrl,
>> - struct key *new_key)
>> + struct key *new_key, bool new_generated)
>> {
>> key_serial_t old_key_id = 0, new_key_id = key_serial(new_key);
>> struct key *key = NULL;
>> + bool generated = false;
>>
>> if (set_ctrl) {
>> if (host->dhchap_ctrl_key) {
>> if (host->dhchap_ctrl_key == new_key_id) {
>> - if (new_key)
>> + if (new_key && new_generated)
>> key_revoke(new_key);
>> return;
>> }
>> old_key_id = host->dhchap_ctrl_key;
>> + generated = host->dhchap_ctrl_key_generated;
>> + host->dhchap_ctrl_key_generated = false;
>> }
>> host->dhchap_ctrl_key = new_key_id;
>> + host->dhchap_key_generated = new_generated;
>
> [Severity: Medium]
> Should the set_ctrl branch update host->dhchap_ctrl_key_generated instead
> of host->dhchap_key_generated?
>
> As written, host->dhchap_ctrl_key_generated remains false, so
> nvmet_host_dhchap_ctrl_key_show() prints the internal UUID description
> instead of the secret for auto-generated controller keys and replacing or
> clearing the controller key never revokes it. At the same time, setting
> or clearing the controller key overwrites host->dhchap_key_generated,
> which can cause a pre-populated host key to be revoked or an
> auto-generated host key to be leaked.
>
Fixed with the next version.
> [ ... ]
>
>> diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
>> index f6bfda757f076..3defa3f948497 100644
>> --- a/drivers/nvme/target/configfs.c
>> +++ b/drivers/nvme/target/configfs.c
>> @@ -2248,13 +2248,15 @@ static ssize_t nvmet_host_dhchap_key_show(struct config_item *item,
>> down_read(&key->sem);
>> if (key_validate(key))
>> ret = sprintf(page, "<invalidated>\n");
>> - else {
>> + else if (host->dhchap_key_generated) {
>> ret = key->type->read(key, page, PAGE_SIZE);
>> if (ret > 0) {
>> page[ret] = '\n';
>> ret++;
>> }
>> - }
>> + } else
>> + ret = scnprintf(page, PAGE_SIZE,
>> + "%s\n", key->description);
>> up_read(&key->sem);
>> key_put(key);
>> }
>
> [Severity: High]
> Can nvmet_host_dhchap_key_show() and nvmet_host_dhchap_ctrl_key_show()
> dereference an error pointer when the key is unset or has been unlinked?
>
> drivers/nvme/target/configfs.c:nvmet_host_dhchap_key_show() {
> down_read(&nvmet_config_sem);
> key = key_lookup(host->dhchap_key);
> if (!key) {
> page[0] = '\0';
> ret = 0;
> } else {
> down_read(&key->sem);
> ...
> }
>
> key_lookup() returns ERR_PTR(-ENOKEY) rather than NULL when a key serial
> is not found (including when host->dhchap_key is 0), so the !key check
> falls through to the else branch and dereferences ERR_PTR(-ENOKEY) in
> down_read(&key->sem). nvme_auth_init_ctrl() and nvmet_setup_auth() also
> check !host_key and !ctrl_key instead of IS_ERR() after key_lookup(),
> which can similarly oops if a pre-populated key was unlinked after option
> or configfs parsing dropped its reference.
>
Already fixed with updates to the previous patch.
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