From: sashiko-bot@kernel.org
To: "Hannes Reinecke" <hare@kernel.org>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v5 6/9] nvme: allow to pass in key description as dhchap secret
Date: Mon, 23 Nov 2026 12:36:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-229231@kernel.org> (raw)
In-Reply-To: <20261123-dhchap-keyring-v4-v5-6-81eefb4c0724@kernel.org>
Thank you for your contribution! Sashiko AI review found 10 potential
issues to consider:
- [High] nvmet-auth: NULL pointer dereference in nvmet_auth_set_key()
when clearing key
- [High] nvme-keyring: broken !CONFIG_NVME_KEYRING stubs in
include/linux/nvme-keyring.h
- [Medium] nvme: broken key visibility check in
nvme_dev_attrs_are_visible()
- [Medium] nvme-auth: self-revocation when updating key with active key
description
- [Medium] nvmet: off-by-one PAGE_SIZE overflow via sprintf() in dhchap
key configfs show
- [Medium] nvme-auth: unnecessary synchronize_rcu() stalls after
key_revoke() under locks
- [Low] nvme-auth: mismatched key serial docs and prototype in
nvme_auth_extract_key()
- [Low] nvme-auth: key_serial() logged before key assignment in
nvme_auth_init_ctrl()
- [Low] nvme-sysfs: missing trailing newline on invalidated in
dhchap_ctrl_secret_show()
- [Low] nvme-auth: nvme_auth_init_ctrl() logs key_serial() before
assigning ctrl keys
--
commit 4ce0c96fc574d457ee6098926055522bf6b8f799
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 a pre-populated
DH-HMAC-CHAP key in the keyring before falling back to generating a key
from raw secret data, and tracks whether the key was auto-generated so
only generated keys are revoked on teardown.
> diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
> index ee26fb416ee62..abdad41daa8fb 100644
> --- a/drivers/nvme/common/auth.c
> +++ b/drivers/nvme/common/auth.c
> @@ -144,20 +144,32 @@ EXPORT_SYMBOL_GPL(nvme_auth_hmac_hash_len);
> * nvme_auth_extract_key - extract the DH-HMAC-CHAP key
> *
> * @keyring: keyring to be used for the resulting key
> - * @secret: key data
> - * @secret_len: length of @secret
> + * @input: key serial or key data
> + * @input_len: length of @input
> + * @generated: indicate whether a key has been generated
> *
> - * Extracts a dhchap key from @secret.
> + * Extracts or generates a key from @input.
> + * @input can either be a key serial or raw key data; in
> + * the latter case a key is generated from @input and
> + * @generated is set to 'true'.
> *
> * Returns the dhchap key or an error pointer on failure.
> */
> -struct key *nvme_auth_extract_key(struct key *keyring, const char *secret,
> - size_t secret_len)
> +struct key *nvme_auth_extract_key(struct key *keyring, const char *input,
> + size_t input_len, bool *generated)
> {
> struct key *key;
>
> - key = nvme_dhchap_psk_create(keyring, secret, secret_len);
> + /* Check if @input is a key serial number */
> + key = nvme_dhchap_psk_lookup(keyring, input);
[Severity: Low]
This isn't a bug, but the commit message body, kernel-doc and inline
comment refer to @input as a key serial number, whereas
nvme_dhchap_psk_lookup() searches the keyring by key description
(key->description).
> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
> index 535cc433dd35d..98913eaeb6d68 100644
> --- a/drivers/nvme/host/auth.c
> +++ b/drivers/nvme/host/auth.c
[ ... ]
> @@ -1109,6 +1122,7 @@ int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
> if (ctrl->host_key)
> nvme_auth_clear_host_key(ctrl);
> ctrl->host_key = host_key;
> + ctrl->host_key_generated = host_key_generated;
[Severity: Low]
Just above this in nvme_auth_init_ctrl(), dev_dbg() logs
key_serial(ctrl->host_key) before ctrl->host_key = host_key is assigned:
drivers/nvme/host/auth.c:nvme_auth_init_ctrl() {
...
dev_dbg(ctrl->device,
"%s: using dhchap host key %08x\n",
__func__, key_serial(ctrl->host_key));
if (ctrl->host_key)
nvme_auth_clear_host_key(ctrl);
ctrl->host_key = host_key;
...
}
Should that log key_serial(host_key) instead so it does not print 00000000
(or the previous key's serial on reset)?
> if (ctrl->ctrl_key)
> nvme_auth_clear_ctrl_key(ctrl);
> @@ -1117,6 +1131,7 @@ int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
> "%s: using dhchap ctrl key %08x\n",
> __func__, key_serial(ctrl->ctrl_key));
> ctrl->ctrl_key = ctrl_key;
> + ctrl->ctrl_key_generated = ctrl_key_generated;
> }
[Severity: Low]
Similarly, nvme_auth_clear_ctrl_key(ctrl) clears ctrl->ctrl_key to NULL
right before dev_dbg() logs key_serial(ctrl->ctrl_key), so this always
prints 00000000 instead of key_serial(ctrl_key).
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index 0c09888be31f7..1277749c6e2e3 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
[ ... ]
> @@ -1339,15 +1343,25 @@ void nvmf_free_options(struct nvmf_ctrl_options *opts)
> kfree(opts->host_traddr);
> kfree(opts->host_iface);
> if (opts->dhchap_key) {
> - pr_debug("revoke dhchap host key %08x\n",
> + if (opts->dhchap_key_generated) {
> + pr_debug("revoke dhchap host key %08x\n",
> + key_serial(opts->dhchap_key));
> + key_revoke(opts->dhchap_key);
> + synchronize_rcu();
> + }
> + pr_debug("drop dhchap host key %08x\n",
> key_serial(opts->dhchap_key));
> - key_revoke(opts->dhchap_key);
> key_put(opts->dhchap_key);
> }
> if (opts->dhchap_ctrl_key) {
> - pr_debug("revoke dhchap ctrl key %08x\n",
> + if (opts->dhchap_ctrl_key_generated) {
> + pr_debug("revoke dhchap ctrl key %08x\n",
> + key_serial(opts->dhchap_ctrl_key));
> + key_revoke(opts->dhchap_ctrl_key);
> + synchronize_rcu();
> + }
> + pr_debug("drop dhchap ctrl key %08x\n",
> key_serial(opts->dhchap_ctrl_key));
> - key_revoke(opts->dhchap_ctrl_key);
> key_put(opts->dhchap_ctrl_key);
> }
> kfree(opts);
[Severity: Medium]
Why call synchronize_rcu() after key_revoke() here, in
dhchap_secret_store(), dhchap_ctrl_secret_store() and
nvmet_auth_revoke_key()?
key_revoke() sets KEY_FLAG_REVOKED under key->sem and schedules payload
destruction via call_rcu(), while all DH-HMAC-CHAP key readers serialize
on key->sem and key_validate(). Waiting synchronously for an RCU grace
period stalls callers unnecessarily, including while holding
ctrl->dhchap_auth_mutex in dhchap_[ctrl_]secret_store() and while holding
down_write(&nvmet_config_sem) in nvmet_auth_set_key(), which blocks all
concurrent target connections and configfs operations.
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index e73c3ad89adc0..e6d42da84e168 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
[ ... ]
> @@ -875,19 +878,25 @@ static ssize_t dhchap_secret_store(struct device *dev,
> up_read(&key->sem);
> if (ret) {
> dev_warn(ctrl->dev, "key %08x invalidated\n", key_serial(key));
> - dev_dbg(ctrl->dev, "revoke host key %08x\n", key_serial(key));
> - key_revoke(key);
> + if (generated) {
> + dev_dbg(ctrl->dev, "revoke host key %08x\n", key_serial(key));
> + key_revoke(key);
> + synchronize_rcu();
> + }
> key_put(key);
> kfree_sensitive(dhchap_secret);
> return ret;
> }
> mutex_lock(&ctrl->dhchap_auth_mutex);
> old_key = ctrl->host_key;
> - dev_dbg(ctrl->dev, "revoke host key %08x\n",
> - key_serial(old_key));
> - key_revoke(old_key);
> -
> + if (ctrl->host_key_generated) {
> + dev_dbg(ctrl->dev, "revoke host key %08x\n",
> + key_serial(old_key));
> + key_revoke(old_key);
> + synchronize_rcu();
> + }
> ctrl->host_key = key;
> + ctrl->host_key_generated = generated;
> mutex_unlock(&ctrl->dhchap_auth_mutex);
[Severity: Medium]
Can this revoke the newly selected key when the active key was
auto-generated?
An auto-generated key is linked into the keyring with a UUID description.
If a user writes that active key's description to dhchap_secret_store()
(or dhchap_ctrl_secret_store(), or nvmet_auth_set_key() on the target),
nvme_auth_extract_key() finds it in the keyring before the old key is
revoked and returns key == old_key with generated = false. Because
ctrl->host_key_generated is still true, key_revoke(old_key) then revokes
key itself, causing subsequent authentication to fail with -EKEYREVOKED.
Should these paths check old_key != key before revoking old_key?
> @@ -913,16 +922,18 @@ static ssize_t dhchap_ctrl_secret_show(struct device *dev,
> mutex_unlock(&ctrl->dhchap_auth_mutex);
> return sysfs_emit(buf, "none\n");
> }
> +
> down_read(&key->sem);
> if (key_validate(key))
> count = sysfs_emit(buf, "<invalidated>");
[Severity: Low]
Should "<invalidated>" have a trailing newline here to match
dhchap_secret_show() and the other branches of dhchap_ctrl_secret_show()?
[ ... ]
> @@ -1090,9 +1110,11 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
> return 0;
> if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts)
> return 0;
> - if (a == &dev_attr_dhchap_key.attr && !ctrl->opts)
> + if (a == &dev_attr_dhchap_key.attr && !ctrl->opts &&
> + !ctrl->host_key_generated)
> return 0;
> - if (a == &dev_attr_dhchap_ctrl_key.attr && !ctrl->opts)
> + if (a == &dev_attr_dhchap_ctrl_key.attr && !ctrl->opts &&
> + !ctrl->ctrl_key_generated)
> return 0;
> #endif
[Severity: Medium]
Should the visibility conditions for dev_attr_dhchap_key.attr and
dev_attr_dhchap_ctrl_key.attr use || instead of &&?
On Fabrics controllers ctrl->opts is non-NULL, so !ctrl->opts is false and
the !ctrl->host_key_generated / !ctrl->ctrl_key_generated checks are never
reached. In addition, because sysfs group visibility is only evaluated at
device creation unless sysfs_update_group() is called, changing
ctrl->host_key_generated or ctrl->ctrl_key_generated later in
dhchap_secret_store() or dhchap_ctrl_secret_store() will not update the
visibility of these attributes.
> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
> index 8b77164512c9c..7204ace149565 100644
> --- a/drivers/nvme/target/auth.c
> +++ b/drivers/nvme/target/auth.c
[ ... ]
> @@ -46,6 +57,7 @@ void nvmet_auth_revoke_key(struct nvmet_host *host, bool set_ctrl)
> int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
> bool set_ctrl)
> {
> + bool generated = false;
> struct key *key;
> size_t len;
>
> @@ -56,7 +68,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
> return 0;
> }
> len = strcspn(secret, "\n");
> - key = nvme_auth_extract_key(NULL, secret, len);
> + key = nvme_auth_extract_key(NULL, secret, len, &generated);
[Severity: High]
Does clearing a host or controller key via configfs trigger a NULL pointer
dereference in nvmet_auth_set_key()?
In nvmet_host_dhchap_key_store() and nvmet_host_dhchap_ctrl_key_store(),
writing an empty string or newline leaves keydata as NULL:
drivers/nvme/target/configfs.c:nvmet_host_dhchap_key_store() {
...
len = strcspn(page, "\n");
if (len) {
keydata = kstrndup(page, len, GFP_KERNEL);
if (!keydata)
return -ENOMEM;
}
ret = nvmet_auth_set_key(host, keydata, false);
...
}
nvmet_auth_set_key() then calls strlen(secret) at the start of the
function without checking if (!secret), dereferencing NULL.
> diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
> index 12c093f4c8363..bc46d760aaa4a 100644
> --- a/drivers/nvme/target/configfs.c
> +++ b/drivers/nvme/target/configfs.c
> @@ -2248,13 +2248,14 @@ 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 = sprintf(page, "%s\n", key->description);
> up_read(&key->sem);
> key_put(key);
> }
> @@ -2305,13 +2306,14 @@ static ssize_t nvmet_host_dhchap_ctrl_key_show(struct config_item *item,
> down_read(&key->sem);
> if (key_validate(key))
> ret = sprintf(page, "<invalidated>\n");
> - else {
> + else if (host->dhchap_ctrl_key_generated) {
> ret = key->type->read(key, page, PAGE_SIZE);
> if (ret > 0) {
> page[ret] = '\n';
> ret++;
> }
> - }
> + } else
> + ret = sprintf(page, "%s\n", key->description);
> up_read(&key->sem);
> key_put(key);
> }
[Severity: Medium]
Can sprintf(page, "%s\n", key->description) in nvmet_host_dhchap_key_show()
and nvmet_host_dhchap_ctrl_key_show() overflow the PAGE_SIZE configfs
buffer by 1 byte?
add_key() permits key->description up to 4095 characters (KEY_MAX_DESC_SIZE
is 4096 including the NUL terminator), so appending "\n" and the
terminating NUL writes 4097 bytes into the 4096-byte page buffer. Using
scnprintf(page, PAGE_SIZE, "%s\n", key->description) would avoid writing
past the end of page.
> diff --git a/include/linux/nvme-auth.h b/include/linux/nvme-auth.h
> index 75e1e75e298e1..d5fbae8fc510b 100644
> --- a/include/linux/nvme-auth.h
> +++ b/include/linux/nvme-auth.h
> @@ -32,7 +32,7 @@ void nvme_auth_hmac_update(struct nvme_auth_hmac_ctx *hmac, const u8 *data,
> void nvme_auth_hmac_final(struct nvme_auth_hmac_ctx *hmac, u8 *out);
>
> struct key *nvme_auth_extract_key(struct key *keyring, const char *secret,
> - size_t secret_len);
> + size_t secret_len, bool *generated);
[Severity: Low]
The commit message notes that the secret parameter of
nvme_auth_extract_key() was renamed to input, but this declaration in
include/linux/nvme-auth.h still uses secret and secret_len.
[Severity: High]
Also in the keyring headers included by drivers/nvme/host/sysfs.c,
drivers/nvme/host/fabrics.c and drivers/nvme/target/configfs.c, do the
!CONFIG_NVME_KEYRING stubs in include/linux/nvme-keyring.h break the build
when CONFIG_NVME_KEYRING is disabled?
include/linux/nvme-keyring.h {
...
static inline struct key *nvme_tls_psk_refresh(struct key *keyring,
const char *hostnqn, const char *subnqn, *data, u8 hmac_id,
u8 *data, size_t data_len, const char *digest)
{
return ERR_PTR(-ENOTSUPP);
}
...
u8 nvme_dhchap_psk_hash(struct key *key)
{
return 0;
}
}
nvme_tls_psk_refresh() has a stray untyped *data parameter before
u8 hmac_id, and nvme_dhchap_psk_hash() is missing static inline, causing
compile and multiple-definition link errors whenever CONFIG_NVME_KEYRING=n.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v5-0-81eefb4c0724@kernel.org?part=6
next prev parent reply other threads:[~2026-11-23 12:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 12:14 [PATCH v5 0/9] nvme-auth: switch to use the kernel keyring Hannes Reinecke
2026-11-23 12:14 ` [PATCH v5 1/9] nvme-auth: modify nvme_auth_transform_key() to return status Hannes Reinecke
2026-11-23 12:14 ` [PATCH v5 2/9] nvme-keyring: add 'dhchap' key type Hannes Reinecke
2026-11-23 12:36 ` sashiko-bot
2026-11-23 13:18 ` Hannes Reinecke
2026-11-23 12:14 ` [PATCH v5 3/9] nvme-auth: switch to use 'struct key' Hannes Reinecke
2026-11-23 12:35 ` sashiko-bot
2026-11-23 13:31 ` Hannes Reinecke
2026-11-23 12:14 ` [PATCH v5 4/9] nvme: parse dhchap keys during option parsing Hannes Reinecke
2026-11-23 12:34 ` sashiko-bot
2026-11-23 12:14 ` [PATCH v5 5/9] nvmet-auth: parse dhchap key from configfs attribute Hannes Reinecke
2026-11-23 12:29 ` sashiko-bot
2026-11-23 12:14 ` [PATCH v5 6/9] nvme: allow to pass in key description as dhchap secret Hannes Reinecke
2026-11-23 12:36 ` sashiko-bot [this message]
2026-11-23 12:14 ` [PATCH v5 7/9] nvme-auth: wait for authentication to finish when changing keys Hannes Reinecke
2026-11-23 12:14 ` [PATCH v5 8/9] nvme-fabrics: allow to pass in keyring by name Hannes Reinecke
2026-11-23 12:29 ` sashiko-bot
2026-11-23 12:14 ` [PATCH v5 9/9] nvmet: add configfs attribute 'dhchap_keyring' Hannes Reinecke
2026-11-23 12:35 ` sashiko-bot
2026-11-23 12:59 ` [PATCH v5 0/9] nvme-auth: switch to use the kernel keyring Martin Belanger
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-229231@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hare@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
/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