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 13/14] nvme-auth: link pre-provisioned keys into .nvme keyring
Date: Thu, 26 Nov 2026 14:30:48 +0000 [thread overview]
Message-ID: <sashiko-outbox-235710@kernel.org> (raw)
In-Reply-To: <20261126-dhchap-keyring-v4-v7-13-ee438ffea527@kernel.org>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] nvme-auth: nvme_keyring_unlink() removes shared or .nvme
pre-provisioned keys
- [Medium] nvmet-auth: nvmet_auth_update_key() mutates host state before
linking key
- [Medium] nvmet-auth: nvmet_auth_update_key() sets wrong generated flag
for ctrl key
- [Low] nvmet-auth: nvmet_auth_update_key() logs new_key serial on
unlink failure
--
commit 03391c2ce04bdc0cd535d7de4d681251fe291e19
Author: Hannes Reinecke <hare@kernel.org>
nvme-auth: link pre-provisioned keys into .nvme keyring
This commit links pre-provisioned DH-HMAC-CHAP keys into the .nvme keyring
when parsed on the host or set on the target, and unlinks them when the
options or host keys are cleared or replaced.
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index 12a30ed16f9ef..e7f51474ab5e1 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
[ ... ]
> @@ -1346,23 +1366,27 @@ void nvmf_free_options(struct nvmf_ctrl_options *opts)
> struct key *key;
>
> nvmf_host_put(opts->host);
> - if (opts->dhchap_key &&
> - opts->dhchap_key_generated) {
> + if (opts->dhchap_key) {
> key = key_lookup(opts->dhchap_key);
> if (!IS_ERR(key)) {
> - pr_debug("revoke dhchap host key %08x\n",
> - opts->dhchap_key);
> - key_revoke(key);
> + if (opts->dhchap_key_generated) {
> + pr_debug("revoke dhchap host key %08x\n",
> + opts->dhchap_key);
> + key_revoke(key);
> + } else
> + nvme_keyring_unlink(key);
> key_put(key);
> }
> }
[Severity: High]
Does nvme_keyring_unlink() remove a pre-provisioned key that originally
lived in the .nvme keyring or is shared across multiple controllers?
Keyring links are indexed by key type and description rather than
reference-counted, so key_link() replaces an existing link in .nvme in
place and key_unlink() deletes that sole link. A pre-provisioned key
placed directly in .nvme (as required when looking up keys by description
via nvme_dhchap_psk_lookup()) is removed from .nvme as soon as the first
controller disconnects or fails to connect, and a key from another keyring
that is shared across controllers or target hosts is unlinked from .nvme
while other users still depend on it.
[ ... ]
> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
> index 54e79c8a7cae6..04a9177ffa1f4 100644
> --- a/drivers/nvme/target/auth.c
> +++ b/drivers/nvme/target/auth.c
> @@ -19,19 +19,20 @@
>
> #include "nvmet.h"
>
> -static void nvmet_auth_update_key(struct nvmet_host *host, bool set_ctrl,
> +static int nvmet_auth_update_key(struct nvmet_host *host, bool set_ctrl,
> 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;
> + int ret;
>
> if (set_ctrl) {
> if (host->dhchap_ctrl_key) {
> if (host->dhchap_ctrl_key == new_key_id) {
> if (new_key && new_generated)
> key_revoke(new_key);
> - return;
> + return 0;
> }
> old_key_id = host->dhchap_ctrl_key;
> generated = host->dhchap_ctrl_key_generated;
> @@ -44,7 +45,7 @@ static void nvmet_auth_update_key(struct nvmet_host *host, bool set_ctrl,
[Severity: Medium]
In the set_ctrl branch of nvmet_auth_update_key(), does
"host->dhchap_key_generated = new_generated" right after
"host->dhchap_ctrl_key = new_key_id" overwrite the host key's flag instead
of host->dhchap_ctrl_key_generated?
That leaves host->dhchap_ctrl_key_generated false so generated controller
keys are unlinked instead of revoked, while clobbering
host->dhchap_key_generated so a pre-provisioned host key can be revoked by
key_revoke() when later replaced or cleared.
> if (host->dhchap_key == new_key_id) {
> if (new_key && new_generated)
> key_revoke(new_key);
> - return;
> + return 0;
> }
> old_key_id = host->dhchap_key;
> generated = host->dhchap_key_generated;
> @@ -53,18 +54,37 @@ static void nvmet_auth_update_key(struct nvmet_host *host, bool set_ctrl,
> host->dhchap_key = new_key_id;
> host->dhchap_key_generated = new_generated;
> }
> + if (new_key && !new_generated) {
> + ret = nvme_keyring_link(new_key);
> + if (ret < 0) {
> + pr_warn("%s: failed to link %s key %08x\n",
> + __func__, set_ctrl ? "ctrl" : "host",
> + key_serial(new_key));
> + return ret;
> + }
> + }
[Severity: Medium]
If nvme_keyring_link(new_key) fails here, does this early return leave
host->dhchap_key or host->dhchap_ctrl_key updated to new_key_id while
leaking old_key_id?
Because the host fields are overwritten before linking new_key, an error
from nvme_keyring_link() skips revoking or unlinking old_key_id and leaves
the unlinked new_key_id installed on host.
> +
> if (!old_key_id)
> - return;
> + return 0;
>
> key = key_lookup(old_key_id);
> if (IS_ERR(key))
> - return;
> + return PTR_ERR(key);
> if (generated) {
> pr_debug("%s: revoke %s key %08x\n", __func__,
> set_ctrl ? "ctrl" : "host", key_serial(key));
> key_revoke(key);
> + ret = 0;
> + } else {
> + ret = nvme_keyring_unlink(key);
> + if (ret < 0) {
> + pr_warn("%s: failed to unlink %s key %08x\n",
> + __func__, set_ctrl ? "ctrl" : "host",
> + key_serial(new_key));
> + }
> }
[Severity: Low]
Should this pr_warn() log key_serial(key) instead of key_serial(new_key)
when unlinking the old key fails?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-dhchap-keyring-v4-v7-0-ee438ffea527@kernel.org?part=13
next prev parent reply other threads:[~2026-11-26 14:30 UTC|newest]
Thread overview: 43+ 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 15:08 ` Hannes Reinecke
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 19:49 ` kernel test robot
2026-11-26 20:22 ` kernel test robot
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-27 7:23 ` Hannes Reinecke
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-27 7:32 ` Hannes Reinecke
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-27 7:34 ` Hannes Reinecke
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-27 7:40 ` Hannes Reinecke
2026-11-27 14:35 ` Martin Belanger
2026-12-01 10:21 ` Hannes Reinecke
2026-12-01 11:27 ` Martin Belanger
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-27 9:13 ` Hannes Reinecke
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-27 10:14 ` Hannes Reinecke
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 [this message]
2026-11-26 16:49 ` Martin Belanger
2026-11-27 9:39 ` Hannes Reinecke
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
2026-11-27 10:48 ` Hannes Reinecke
2026-11-26 21:15 ` kernel test robot
2026-11-26 16:00 ` [PATCH v7 00/14] nvme-auth: switch to use the kernel keyring Jarkko Sakkinen
2026-11-26 16:03 ` Jarkko Sakkinen
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-235710@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.