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 05/14] nvme-keyring: link addtional keyring into .nvme keyring
Date: Thu, 26 Nov 2026 14:24:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-235695@kernel.org> (raw)
In-Reply-To: <20261126-dhchap-keyring-v4-v7-5-ee438ffea527@kernel.org>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] nvme-fabrics: NULL deref and key leak linking opts->keyring in
nvmf_parse_options()
- [High] nvme-keyring: broken !CONFIG_NVME_KEYRING stubs in
include/linux/nvme-keyring.h
- [High] nvme-keyring: non-recursive keyring_search() in
nvme_tls_psk_lookup() skips linked keyrings
- [High] nvme-tcp: nvme_tcp_start_tls() still passes opts->keyring
instead of .nvme to tlshd
- [Medium] nvme-fabrics: unrefcounted keyring link/unlink breaks shared
keyrings and triggers WARN_ON
- [Low] nvme: unreachable default keyring fallback in tls_keyring_show()
- [Low] nvme-keyring: stale @keyring reference in nvme_tls_psk_refresh()
kernel-doc
--
commit baf89e86a63698b34af74abf311ec9f03c1d91b9
Author: Hannes Reinecke <hare@kernel.org>
nvme-keyring: link addtional keyring into .nvme keyring
This commit links any user-specified keyring into the default .nvme keyring
for the lifetime of the controller options and updates TLS PSK lookup and
refresh helpers to operate directly on the .nvme keyring.
> diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c
> index 373f51e1032a4..0fc6b4825c2dd 100644
> --- a/drivers/nvme/common/keyring.c
> +++ b/drivers/nvme/common/keyring.c
[ ... ]
> @@ -104,12 +120,8 @@ static struct key *nvme_tls_psk_lookup(struct key *keyring,
> snprintf(identity, identity_len, "NVMe%u%c%02u %s %s",
> psk_ver, generated ? 'G' : 'R', hmac, hostnqn, subnqn);
>
> - if (!keyring)
> - keyring = nvme_keyring;
> - keyring_id = key_serial(keyring);
> - pr_debug("keyring %x lookup tls psk '%s'\n",
> - keyring_id, identity);
> - keyref = keyring_search(make_key_ref(keyring, true),
> + pr_debug("lookup tls psk '%s'\n", identity);
> + keyref = keyring_search(make_key_ref(nvme_keyring, true),
> &nvme_tls_psk_key_type,
> identity, false);
[Severity: High]
Should keyring_search() pass recurse = true here? With recurse = false,
KEYRING_SEARCH_RECURSE is not set, so keyring_search() only checks the
top-level nvme_keyring and never descends into keyrings linked via
nvme_keyring_link(), causing nvme_tls_psk_default() lookups for keys in
linked keyrings to fail with -ENOKEY.
> if (IS_ERR(keyref)) {
> @@ -125,7 +137,6 @@ static struct key *nvme_tls_psk_lookup(struct key *keyring,
>
> /**
> * nvme_tls_psk_refresh - Refresh TLS PSK
> - * @keyring: Keyring holding the TLS PSK
> * @hostnqn: Host NQN to use
> * @subnqn: Subsystem NQN to use
> * @hmac_id: Hash function identifier
[Severity: Low]
This isn't a bug, but the kernel-doc body just below this hunk still says
"in the keyring given by @keyring" after the @keyring parameter was
removed.
[ ... ]
> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
> index 295e0a9533c89..06399c0754053 100644
> --- a/drivers/nvme/host/auth.c
> +++ b/drivers/nvme/host/auth.c
> @@ -726,8 +726,7 @@ static int nvme_auth_secure_concat(struct nvme_ctrl *ctrl,
> goto out_free_digest;
> }
>
> - tls_key = nvme_tls_psk_refresh(ctrl->opts->keyring,
> - ctrl->opts->host->nqn,
> + tls_key = nvme_tls_psk_refresh(ctrl->opts->host->nqn,
> ctrl->opts->subsysnqn, chap->hash_id,
> tls_psk, psk_len, digest);
> if (IS_ERR(tls_key)) {
[Severity: High]
When secure concatenation is used with a custom keyring,
nvme_tls_psk_refresh() now inserts the generated PSK into the default .nvme
keyring, but doesn't nvme_tcp_start_tls() still pass nctrl->opts->keyring
to tlshd?
drivers/nvme/host/tcp.c:nvme_tcp_start_tls() {
...
key_serial_t keyring = nvme_keyring_id();
...
if (nctrl->opts->keyring)
keyring = key_serial(nctrl->opts->keyring);
args.ta_keyring = keyring;
...
}
Because nctrl->opts->keyring is linked beneath .nvme and not the other way
around, tlshd searches nctrl->opts->keyring instead of .nvme and fails to
find the generated PSK.
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index 5ed91557f0706..6a918d72d14c5 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -995,7 +995,11 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
> ret = PTR_ERR(key);
> goto out;
> }
> - key_put(opts->keyring);
> + ret = nvme_keyring_link(opts->keyring);
> + if (ret) {
> + key_put(key);
> + goto out;
> + }
> opts->keyring = key;
> break;
[Severity: High]
Does nvme_keyring_link(opts->keyring) pass NULL on the first keyring=
option instead of linking the newly parsed key? key_link() immediately
dereferences its key argument via key_check(key) and &key->index_key,
causing a NULL pointer dereference oops when connecting with keyring=.
Also, if keyring= is specified more than once in the option string,
overwriting opts->keyring without unlinking and calling key_put() on the
previous opts->keyring leaks the earlier keyring reference and link.
> @@ -1296,7 +1300,12 @@ static int nvmf_check_allowed_opts(struct nvmf_ctrl_options *opts,
> void nvmf_free_options(struct nvmf_ctrl_options *opts)
> {
> nvmf_host_put(opts->host);
> - key_put(opts->keyring);
> + if (opts->keyring) {
> + int ret = nvme_keyring_unlink(opts->keyring);
> +
> + WARN_ON(ret);
> + key_put(opts->keyring);
> + }
> key_put(opts->tls_key);
[Severity: Medium]
What happens if two controllers (or an active controller and a failed
connection attempt) specify the same keyring? key_link() only maintains a
single link to a given key in nvme_keyring rather than a reference count,
so freeing the first controller unlinks the keyring from .nvme while the
second controller still uses it, and freeing the second controller fails
with -ENOENT and triggers WARN_ON(ret).
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 35f871e3e0c0a..c1375f23a97f6 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
[ ... ]
> @@ -1069,6 +1070,8 @@ static ssize_t tls_keyring_show(struct device *dev,
> struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> struct key *keyring = ctrl->opts->keyring;
>
> + if (!keyring)
> + return sysfs_emit(buf, "%s\n", nvme_keyring_name());
> return sysfs_emit(buf, "%s\n", keyring->description);
> }
> static DEVICE_ATTR_RO(tls_keyring);
[Severity: Low]
Is this !keyring branch reachable? nvme_tls_attrs_are_visible() still
hides dev_attr_tls_keyring when !ctrl->opts->keyring:
drivers/nvme/host/sysfs.c:nvme_tls_attrs_are_visible() {
...
if (a == &dev_attr_tls_keyring.attr &&
!ctrl->opts->keyring)
return 0;
...
}
> diff --git a/include/linux/nvme-keyring.h b/include/linux/nvme-keyring.h
> index ab8971afa9734..680eb93088d48 100644
> --- a/include/linux/nvme-keyring.h
> +++ b/include/linux/nvme-keyring.h
> @@ -10,20 +10,22 @@
>
> #if IS_ENABLED(CONFIG_NVME_KEYRING)
>
> -struct key *nvme_tls_psk_refresh(struct key *keyring,
> - const char *hostnqn, const char *subnqn, u8 hmac_id,
> - u8 *data, size_t data_len, const char *digest);
> -key_serial_t nvme_tls_psk_default(struct key *keyring,
> - const char *hostnqn, const char *subnqn);
> +struct key *nvme_tls_psk_refresh(const char *hostnqn, const char *subnqn,
> + u8 hmac_id, u8 *data, size_t data_len, const char *digest);
> +key_serial_t nvme_tls_psk_default(const char *hostnqn, const char *subnqn);
>
> key_serial_t nvme_keyring_id(void);
> +const char *nvme_keyring_name(void);
> +int nvme_keyring_link(struct key *keyring);
> +int nvme_keyring_unlink(struct key *keyring);
> struct key *nvme_tls_key_lookup(key_serial_t key_id);
> +
> #else
> static inline struct key *nvme_tls_psk_refresh(struct key *keyring,
> - const char *hostnqn, char *subnqn, u8 hmac_id,
> + const char *hostnqn, const char *subnqn, u8 hmac_id,
> u8 *data, size_t data_len, const char *digest)
> {
> - return ERR_PTR(-ENOTSUPP);
> + return ERR_PTR(-EOPNOTSUPP);
> }
> static inline key_serial_t nvme_tls_psk_default(struct key *keyring,
> const char *hostnqn, const char *subnqn)
> @@ -34,9 +36,21 @@ static inline key_serial_t nvme_keyring_id(void)
> {
> return 0;
> }
> +static const char *nvme_keyring_name(void)
> +{
> + return NULL;
> +}
> +static int nvme_keyring_link(struct key *keyring)
> +{
> + return 0;
> +}
> +int nvme_keyring_unlink(struct key *keyring)
> +{
> + return 0;
> +}
[Severity: High]
Does the !CONFIG_NVME_KEYRING build fail here?
The nvme_tls_psk_refresh() and nvme_tls_psk_default() stubs still take
struct key *keyring as their first argument, breaking compilation of
callers like nvme_tcp_alloc_admin_queue() when CONFIG_NVME_KEYRING is
disabled. In addition, nvme_keyring_unlink() is missing "static inline"
(causing multiple-definition link errors across translation units including
this header), and nvme_keyring_name() and nvme_keyring_link() are missing
"inline" (triggering unused-function warnings).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-dhchap-keyring-v4-v7-0-ee438ffea527@kernel.org?part=5
next prev parent reply other threads:[~2026-11-26 14:24 UTC|newest]
Thread overview: 28+ 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 [this message]
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
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
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-235695@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