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 08/14] nvmet-auth: parse dhchap key from configfs attribute
Date: Thu, 26 Nov 2026 14:30:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-235707@kernel.org> (raw)
In-Reply-To: <20261126-dhchap-keyring-v4-v7-8-ee438ffea527@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvmet-auth: ERR_PTR dereference in key_lookup() callers
--

commit b41d5ff16da6a60366fa816c551dfd75334950eb
Author: Hannes Reinecke <hare@kernel.org>

nvmet-auth: parse dhchap key from configfs attribute

This commit converts the nvmet DH-HMAC-CHAP configfs attributes to store
key serial numbers in struct nvmet_host and look up the keys via
key_lookup() when needed.

> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
> index e1d92f5455219..ff0e8569d7067 100644
> --- a/drivers/nvme/target/auth.c
> +++ b/drivers/nvme/target/auth.c

[ ... ]

> @@ -186,22 +212,45 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset)
>  		goto out_unlock;
>  	}
>  
> -	if (!host->dhchap_secret) {
> +	if (!host->dhchap_key) {
>  		pr_debug("No authentication provided\n");
>  		goto out_unlock;
>  	}
>  
> -	host_key = nvme_auth_extract_key(host->dhchap_secret,
> -					 strlen(host->dhchap_secret));
> -	if (IS_ERR(host_key)) {
> +	host_key = key_lookup(host->dhchap_key);
> +	if (!host_key) {
> +		pr_warn("%s: host key %08x not found\n",
> +			__func__, host->dhchap_key);
>  		ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
>  		goto out_unlock;
>  	}
> -	if (host->dhchap_ctrl_secret) {
> -		ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret,
> -						 strlen(host->dhchap_ctrl_secret));
> -		if (IS_ERR(ctrl_key)) {
> +	down_read(&host_key->sem);
> +	ret = key_validate(host_key);
> +	up_read(&host_key->sem);
> +	if (ret) {
> +		pr_warn("host key %08x invalidated\n",
> +			host->dhchap_key);
> +		key_put(host_key);
> +		ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
> +		goto out_unlock;
> +	}
> +	if (host->dhchap_ctrl_key) {
> +		ctrl_key = key_lookup(host->dhchap_ctrl_key);
> +		if (!ctrl_key) {
> +			pr_warn("%s: ctrl key %08x not found\n",
> +				__func__, host->dhchap_ctrl_key);
> +			key_put(host_key);
> +			ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
> +			goto out_unlock;
> +		}
> +		down_read(&ctrl_key->sem);
>  
> diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
> index ff3a8d74de599..f6bfda757f076 100644
> --- a/drivers/nvme/target/configfs.c
> +++ b/drivers/nvme/target/configfs.c

[ ... ]

> @@ -2234,15 +2235,29 @@ static struct config_group nvmet_ports_group;
>  static ssize_t nvmet_host_dhchap_key_show(struct config_item *item,
>  		char *page)
>  {
> -	char *dhchap_secret;
> +	struct nvmet_host *host = to_host(item);
> +	struct key *key;
>  	ssize_t ret;
>  
>  	down_read(&nvmet_config_sem);
> -	dhchap_secret = to_host(item)->dhchap_secret;
> -	if (!dhchap_secret)
> -		ret = sprintf(page, "\n");
> -	else
> -		ret = sprintf(page, "%s\n", dhchap_secret);
> +	key = key_lookup(host->dhchap_key);
> +	if (!key) {
> +		page[0] = '\0';
> +		ret = 0;
> +	} else {
> +		down_read(&key->sem);

[ ... ]

> @@ -2267,15 +2292,29 @@ CONFIGFS_ATTR(nvmet_host_, dhchap_key);
>  static ssize_t nvmet_host_dhchap_ctrl_key_show(struct config_item *item,
>  		char *page)
>  {
> -	char *dhchap_secret = to_host(item)->dhchap_ctrl_secret;
> +	struct nvmet_host *host = to_host(item);
> +	struct key *key;
>  	ssize_t ret;
>  
>  	down_read(&nvmet_config_sem);
> -	dhchap_secret = to_host(item)->dhchap_ctrl_secret;
> -	if (!dhchap_secret)
> -		ret = sprintf(page, "\n");
> -	else
> -		ret = sprintf(page, "%s\n", dhchap_secret);
> +	key = key_lookup(host->dhchap_ctrl_key);
> +	if (!key) {
> +		page[0] = '\0';
> +		ret = 0;
> +	} else {
> +		down_read(&key->sem);

[Severity: High]
Should the key_lookup() checks in nvmet_setup_auth(),
nvmet_host_dhchap_key_show(), and nvmet_host_dhchap_ctrl_key_show() use
IS_ERR() instead of testing for NULL?

key_lookup() returns ERR_PTR(-ENOKEY) when a key serial is not found
(including when dhchap_key or dhchap_ctrl_key is 0 because no key is
configured).  Checking !key lets ERR_PTR(-ENOKEY) through and crashes at
down_read(&key->sem) when reading the configfs attributes on a host
without a key configured or when a key is not found during
authentication setup.

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


  reply	other threads:[~2026-11-26 14:30 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 [this message]
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
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-235707@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