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 12/14] nvme-fabrics: allow to pass in keyring by name
Date: Thu, 26 Nov 2026 14:31:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-235711@kernel.org> (raw)
In-Reply-To: <20261126-dhchap-keyring-v4-v7-12-ee438ffea527@kernel.org>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] nvme-fabrics: NULL dereference and key leak in
nvmf_parse_options()
- [High] nvme-fabrics: missing keyring link and key leak in
tls_keyring_store()
- [High] nvme-fabrics: vmlinux link failure when CONFIG_NVME_KEYRING=m
- [High] nvme-keyring: broken header stubs when CONFIG_NVME_KEYRING=n
- [Medium] nvme-fabrics: unstripped newline in tls_keyring_store()
breaks lookup
- [Medium] nvme-fabrics: missing key type and state checks in keyring ID
fallback
- [Medium] nvme-fabrics: unsynchronized opts->keyring access in
tls_keyring_store()
- [Low] nvme-fabrics: unreachable !keyring path in
nvme_tls_attrs_are_visible()
--
commit cea520ca62b4a11b68d9d8f8ca9eeea627f871dd
Author: Hannes Reinecke <hare@kernel.org>
nvme-fabrics: allow to pass in keyring by name
This commit allows specifying the fabrics keyring option by name in
addition to serial number, enables the keyring option for all fabrics
transports, and makes the tls_keyring sysfs attribute writable.
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index bba6a4848f227..12a30ed16f9ef 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -663,8 +663,8 @@ static struct key *nvmf_parse_key(int key_id)
> {
> struct key *key;
>
> - if (!IS_ENABLED(CONFIG_NVME_TCP_TLS)) {
> - pr_err("TLS is not supported\n");
> + if (!IS_ENABLED(CONFIG_NVME_KEYRING)) {
> + pr_err("nvme keyring is not supported\n");
> return ERR_PTR(-EINVAL);
> }
[Severity: High]
Can this fail to link vmlinux when CONFIG_NVME_KEYRING=m?
IS_ENABLED(CONFIG_NVME_KEYRING) is true when NVME_KEYRING is a module,
while NVME_FABRICS in drivers/nvme/host/Kconfig only selects NVME_KEYRING
if NVME_TCP_TLS is enabled. If CONFIG_NVME_FABRICS=y (with
CONFIG_NVME_TCP_TLS=n and CONFIG_NVME_HOST_AUTH=n) and
CONFIG_NVME_KEYRING=m (for example via CONFIG_NVME_TARGET=m), built-in
fabrics.o references nvme_tls_key_lookup() and nvme_keyring_link() in
nvme-keyring.ko. Similarly, when CONFIG_NVME_CORE=y, CONFIG_NVME_TCP=m,
and CONFIG_NVME_TCP_TLS=y, NVME_FABRICS=m selects CONFIG_NVME_KEYRING=m,
so built-in drivers/nvme/host/sysfs.o fails to link against
nvme_keyring_name() and nvme_keyring_unlink().
[ ... ]
> @@ -993,14 +995,24 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
> opts->tos = token;
> break;
> case NVMF_OPT_KEYRING:
> - if (match_int(args, &key_id) || key_id <= 0) {
> - ret = -EINVAL;
> +#if IS_ENABLED(CONFIG_NVME_KEYRING)
> + p = match_strdup(args);
> + if (!p) {
> + ret = -ENOMEM;
> goto out;
> }
> - key = nvmf_parse_key(key_id);
> + key = request_key(&key_type_keyring, p, NULL);
> + kfree(p);
> if (IS_ERR(key)) {
> - ret = PTR_ERR(key);
> - goto out;
> + if (match_int(args, &key_id) || key_id <= 0) {
> + ret = -EINVAL;
> + goto out;
> + }
> + key = nvmf_parse_key(key_id);
> + if (IS_ERR(key)) {
> + ret = PTR_ERR(key);
> + goto out;
> + }
> }
> ret = nvme_keyring_link(opts->keyring);
> if (ret) {
> @@ -1008,6 +1020,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
> goto out;
> }
> opts->keyring = key;
> +#endif
> break;
[Severity: High]
Does nvme_keyring_link(opts->keyring) pass NULL instead of the newly
looked-up key?
On the first keyring= option, opts->keyring is NULL, so
nvme_keyring_link(NULL) calls key_link(nvme_keyring, NULL) ->
__key_link_lock(), triggering a NULL pointer dereference on
index_key->type with nvme_keyring->sem held write-locked. If keyring= is
specified more than once in the option string, the previous opts->keyring
is also overwritten without being unlinked or released with key_put().
[Severity: High]
Does guarding this block with #if IS_ENABLED(CONFIG_NVME_KEYRING) expose
broken stubs in include/linux/nvme-keyring.h when CONFIG_NVME_KEYRING=n?
include/linux/nvme-keyring.h {
...
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;
}
...
}
When CONFIG_NVME_KEYRING is disabled, nvme_keyring_unlink() is defined as
a non-static function in the header, causing multiple-definition linker
errors across fabrics.o, sysfs.o, and tcp.o, while the non-inline static
nvme_keyring_link() stub becomes unused in fabrics.c and triggers
-Wunused-function.
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 4ebc03a8ddcae..0ffea12fcfb6b 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -1212,7 +1212,38 @@ static ssize_t tls_keyring_show(struct device *dev,
> return sysfs_emit(buf, "%s\n", nvme_keyring_name());
> return sysfs_emit(buf, "%s\n", keyring->description);
> }
> -static DEVICE_ATTR_RO(tls_keyring);
> +
> +static ssize_t tls_keyring_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> + struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> + struct key *keyring = ctrl->opts->keyring;
> + int ret;
> +
> + keyring = request_key(&key_type_keyring, buf, NULL);
[Severity: Medium]
Does passing buf directly to request_key() without stripping a trailing
newline break keyring lookup by name from sysfs?
Writes such as "echo my_keyring > tls_keyring" pass "my_keyring\n" to
request_key(), which fails with -ENOKEY and falls through to kstrtoul(),
returning -EINVAL. Other sysfs handlers in this file (such as
dhchap_secret_store()) strip the trailing newline with strcspn(buf, "\n").
> + if (IS_ERR(keyring)) {
> + unsigned long keyring_id;
> +
> + ret = kstrtoul(buf, 0, &keyring_id);
> + if (ret < 0)
> + return -EINVAL;
> + keyring = key_lookup(keyring_id);
> + if (IS_ERR(keyring))
> + return -EINVAL;
> + }
[Severity: Medium]
Can the serial ID fallback in tls_keyring_store() and nvmf_parse_options()
accept a key that is not a keyring?
Neither key_lookup() here nor nvmf_parse_key() in nvmf_parse_options()
verifies that keyring->type == &key_type_keyring. In addition,
tls_keyring_store() does not check that keyring_id fits in a positive
key_serial_t or call key_validate(keyring) to reject revoked, expired, or
invalidated keys.
> + if (ctrl->opts->keyring) {
> + ret = nvme_keyring_unlink(ctrl->opts->keyring);
> + if (ret < 0) {
> + pr_warn("failed to unlink '%08X' from default keyring\n",
> + key_serial(ctrl->opts->keyring));
> + key_put(keyring);
> + return ret;
> + }
> + }
> + ctrl->opts->keyring = keyring;
> + return count;
> +}
> +static DEVICE_ATTR_ADMIN_RW(tls_keyring);
[Severity: High]
Does tls_keyring_store() leak the old ctrl->opts->keyring reference and
leave the new keyring unlinked from the default .nvme keyring?
After nvme_keyring_unlink(ctrl->opts->keyring) removes the link from
nvme_keyring, key_put(ctrl->opts->keyring) is never called before
ctrl->opts->keyring is overwritten. The new keyring is also never passed
to nvme_keyring_link(keyring), so keys in it cannot be found through
nvme_keyring, any subsequent write to tls_keyring fails in
nvme_keyring_unlink() with -ENOENT, and controller teardown hits
WARN_ON(ret) in nvmf_free_options().
[Severity: Medium]
What serializes tls_keyring_store() against concurrent calls to
tls_keyring_store(), tls_keyring_show(), or nvme_tcp_start_tls()?
CPU0 CPU1
tls_keyring_store() tls_keyring_show()
keyring = ctrl->opts->keyring
nvme_keyring_unlink(
ctrl->opts->keyring)
/* once key_put() is added: */
key_put(ctrl->opts->keyring)
sysfs_emit(...,
keyring->description)
<-- use-after-free
Two concurrent writers can also unlink and replace ctrl->opts->keyring at
the same time, while tls_keyring_show() and nvme_tcp_start_tls() read
ctrl->opts->keyring without holding a lock or taking a key reference.
[Severity: Low]
Is tls_keyring visible in sysfs when a controller is created without an
initial keyring= option?
drivers/nvme/host/sysfs.c:nvme_tls_attrs_are_visible() {
...
if (a == &dev_attr_tls_keyring.attr &&
!ctrl->opts->keyring)
return 0;
...
}
Because nvme_tls_attrs_are_visible() hides tls_keyring whenever
ctrl->opts->keyring is NULL, the !keyring fallback in tls_keyring_show()
cannot be reached and a keyring cannot be configured via
tls_keyring_store() unless one was already passed at connect time. Also,
making tls_keyring writable and changing it from DEVICE_ATTR_RO (0444) to
DEVICE_ATTR_ADMIN_RW (0600) is not mentioned in the commit message or
Documentation/ABI/stable/sysfs-nvme.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-dhchap-keyring-v4-v7-0-ee438ffea527@kernel.org?part=12
next prev parent reply other threads:[~2026-11-26 14:32 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
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 [this message]
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-235711@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