Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hannes Reinecke" <hare@kernel.org>,
	"Keith Busch" <kbusch@kernel.org>, "Jens Axboe" <axboe@kernel.dk>,
	"Christoph Hellwig" <hch@lst.de>,
	"Sagi Grimberg" <sagi@grimberg.me>,
	"Hannes Reinecke" <hare@suse.de>,
	"Chaitanya Kulkarni" <kch@nvidia.com>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"David Howells" <dhowells@redhat.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Kees Cook" <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-nvme@lists.infradead.org, keyrings@vger.kernel.org
Subject: Re: [PATCH v7 09/14] nvme: allow to pass in key description as dhchap secret
Date: Thu, 26 Nov 2026 14:27:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-235701@kernel.org> (raw)
In-Reply-To: <20261126-dhchap-keyring-v4-v7-9-ee438ffea527@kernel.org>

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@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.

[ ... ]

> 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-dhchap-keyring-v4-v7-0-ee438ffea527@kernel.org?part=9


  reply	other threads:[~2026-11-26 14:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 14:12 [PATCH v7 00/14] nvme-auth: switch to use the kernel keyring Hannes Reinecke
2026-11-26 14:12 ` [PATCH v7 01/14] nvme-auth: modify nvme_auth_transform_key() to return status Hannes Reinecke
2026-11-26 14:12 ` [PATCH v7 02/14] nvme-keyring: add 'dhchap' key type Hannes Reinecke
2026-11-26 14:32   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 03/14] nvme-keyring: drop nvme_tls_psk_revoked() Hannes Reinecke
2026-11-26 14:12 ` [PATCH v7 04/14] Documentation/security/keys: fixup function name Hannes Reinecke
2026-11-26 14:12 ` [PATCH v7 05/14] nvme-keyring: link addtional keyring into .nvme keyring Hannes Reinecke
2026-11-26 14:24   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 06/14] nvme-auth: switch to use 'struct key' Hannes Reinecke
2026-11-26 14:33   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 07/14] nvme: parse dhchap keys during option parsing Hannes Reinecke
2026-11-26 14:29   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 08/14] nvmet-auth: parse dhchap key from configfs attribute Hannes Reinecke
2026-11-26 14:30   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 09/14] nvme: allow to pass in key description as dhchap secret Hannes Reinecke
2026-11-26 14:27   ` sashiko-bot [this message]
2026-11-26 14:12 ` [PATCH v7 10/14] nvme-auth: allow to specify the key by key serial Hannes Reinecke
2026-11-26 14:26   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 11/14] nvme-auth: wait for authentication to finish when changing keys Hannes Reinecke
2026-11-26 14:12 ` [PATCH v7 12/14] nvme-fabrics: allow to pass in keyring by name Hannes Reinecke
2026-11-26 14:31   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 13/14] nvme-auth: link pre-provisioned keys into .nvme keyring Hannes Reinecke
2026-11-26 14:30   ` sashiko-bot
2026-11-26 14:12 ` [PATCH v7 14/14] nvme-auth: allow to update pre-provisioned keys Hannes Reinecke
2026-11-26 14:31   ` sashiko-bot

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=sashiko-outbox-235701@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=corbet@lwn.net \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=hare@kernel.org \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jarkko@kernel.org \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=kees@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=sagi@grimberg.me \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    /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