From: sashiko-bot@kernel.org
To: "Hannes Reinecke" <hare@kernel.org>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v5 4/9] nvme: parse dhchap keys during option parsing
Date: Mon, 23 Nov 2026 12:34:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-229226@kernel.org> (raw)
In-Reply-To: <20261123-dhchap-keyring-v4-v5-4-81eefb4c0724@kernel.org>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] nvme: build failure in sysfs.c when CONFIG_NVME_KEYRING is
disabled
- [Low] nvme-auth: log of unassigned keys and NULL device in
nvme_auth_init_ctrl()
- [Low] nvme-fabrics: dead !CONFIG_NVME_HOST_AUTH branches in
nvmf_parse_options()
- [Low] nvme: missing trailing newline in dhchap_ctrl_secret_show() on
invalid key
- [Low] nvme: wrong device pointer logged in dhchap_secret_store() and
ctrl store
- [Low] nvme: undocumented dhchap_key sysfs attrs and inaccurate
changelog
--
commit 8a46b5c132a1f37ed808c2b1576c3ace8af7cf7f
Author: Hannes Reinecke <hare@kernel.org>
nvme: parse dhchap keys during option parsing
This commit extracts DH-HMAC-CHAP secrets into key objects during fabrics
option parsing and exposes the active keys and their serial numbers via
controller sysfs attributes.
> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
> index 0ddf3834f4ea2..535cc433dd35d 100644
> --- a/drivers/nvme/host/auth.c
> +++ b/drivers/nvme/host/auth.c
[ ... ]
> @@ -1029,40 +1024,106 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
[ ... ]
> + 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;
> +
> + if (ctrl->ctrl_key)
> + nvme_auth_clear_ctrl_key(ctrl);
> + if (ctrl_key) {
> + dev_dbg(ctrl->device,
> + "%s: using dhchap ctrl key %08x\n",
> + __func__, key_serial(ctrl->ctrl_key));
> + ctrl->ctrl_key = ctrl_key;
> + }
[Severity: Low]
Do these two dev_dbg() calls pass ctrl->host_key and ctrl->ctrl_key to
key_serial() before assigning host_key and ctrl_key, always logging key
serial 00000000?
Also, nvme_init_ctrl() calls nvme_auth_init_ctrl() before setting
ctrl->device = &ctrl->ctrl_device, so ctrl->device is NULL for all
dev_warn() and dev_dbg() calls in nvme_auth_init_ctrl().
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index 5ed91557f0706..0c09888be31f7 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
[ ... ]
> @@ -1086,6 +1078,53 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
> pr_warn("failfast tmo (%d) larger than controller loss tmo (%d)\n",
> opts->fast_io_fail_tmo, ctrl_loss_tmo);
> }
> +
> + opts->host = nvmf_host_add(hostnqn, &hostid);
> + if (IS_ERR(opts->host)) {
> + ret = PTR_ERR(opts->host);
> + opts->host = NULL;
> + goto out;
> + }
> +
> + if (host_secret) {
> +#ifdef CONFIG_NVME_HOST_AUTH
> + pr_debug("lookup host identity '%s'\n", host_secret);
> + key = nvme_auth_extract_key(opts->keyring, host_secret,
> + strlen(host_secret));
> + if (IS_ERR(key)) {
> + ret = PTR_ERR(key);
> + goto out;
> + }
> + pr_debug("using dhchap host key %08x\n", key_serial(key));
> + opts->dhchap_key = key;
> +#else
> + pr_warn("nvme authentication is disabled\n");
> + ret = -EINVAL;
> + goto out;
> +#endif
> + }
> + if (ctrl_secret) {
> +#ifdef CONFIG_NVME_HOST_AUTH
> + if (!opts->dhchap_key) {
> + ret = -EINVAL;
> + goto out;
> + }
> + pr_debug("lookup ctrl identity '%s'\n", ctrl_secret);
> + key = nvme_auth_extract_key(opts->keyring, ctrl_secret,
> + strlen(ctrl_secret));
> + if (IS_ERR(key)) {
> + ret = PTR_ERR(key);
> + goto out;
> + }
> + pr_debug("using dhchap ctrl key %08x\n", key_serial(key));
> + opts->dhchap_ctrl_key = key;
> +#else
> + pr_warn("nvme authentication is disabled\n");
> + ret = -EINVAL;
> + goto out;
> +#endif
> + }
[Severity: Low]
Can the !CONFIG_NVME_HOST_AUTH branches under if (host_secret) and
if (ctrl_secret) ever be reached?
NVMF_OPT_DHCHAP_SECRET and NVMF_OPT_DHCHAP_CTRL_SECRET in opt_tokens are
guarded by #ifdef CONFIG_NVME_HOST_AUTH, so when CONFIG_NVME_HOST_AUTH is
disabled, match_token() rejects dhchap_secret and dhchap_ctrl_secret as
unknown parameters and jumps to out while host_secret and ctrl_secret are
still NULL.
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index a5c1511e49ac2..e73c3ad89adc0 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -6,6 +6,8 @@
> */
>
> #include <linux/nvme-auth.h>
> +#include <linux/nvme-keyring.h>
> +#include <linux/key-type.h>
> #include <linux/blkdev.h>
[Severity: High]
Does including linux/nvme-keyring.h unconditionally in sysfs.c break the
build when CONFIG_NVME_CORE is enabled and CONFIG_NVME_KEYRING is
disabled?
In the !IS_ENABLED(CONFIG_NVME_KEYRING) block of
include/linux/nvme-keyring.h (updated earlier in commit "nvme-auth: switch
to use 'struct key'"), nvme_tls_psk_refresh() has a malformed parameter
list and nvme_dhchap_psk_hash() is defined without static inline:
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)
...
u8 nvme_dhchap_psk_hash(struct key *key)
{
return 0;
}
Since sysfs.c is built for any CONFIG_NVME_CORE configuration and does not
use any symbols from linux/nvme-keyring.h, compiling with
CONFIG_NVME_KEYRING=n fails with syntax and multiple-definition errors.
> @@ -830,36 +850,47 @@ static ssize_t dhchap_secret_store(struct device *dev,
[ ... ]
> + down_read(&key->sem);
> + ret = key_validate(key);
> + 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);
> + 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);
[Severity: Low]
Should these dev_warn() and dev_dbg() calls in dhchap_secret_store() and
dhchap_ctrl_secret_store() use ctrl->device instead of ctrl->dev?
ctrl->dev is the parent transport device (such as the shared
/sys/class/nvme-fabrics/ctl device), whereas ctrl->device is the nvmeX
controller device used by the rest of the function.
> @@ -873,11 +904,28 @@ static ssize_t dhchap_ctrl_secret_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> - struct nvmf_ctrl_options *opts = ctrl->opts;
> + struct key *key;
> + ssize_t count;
>
> - if (!opts->dhchap_ctrl_secret)
> + mutex_lock(&ctrl->dhchap_auth_mutex);
> + key = ctrl->ctrl_key;
> + if (!key) {
> + mutex_unlock(&ctrl->dhchap_auth_mutex);
> return sysfs_emit(buf, "none\n");
> - return sysfs_emit(buf, "%s\n", opts->dhchap_ctrl_secret);
> + }
> + down_read(&key->sem);
> + if (key_validate(key))
> + count = sysfs_emit(buf, "<invalidated>");
[Severity: Low]
Is a trailing newline missing from "<invalidated>" in
dhchap_ctrl_secret_show()? dhchap_secret_show(), dhchap_key_show(), and
dhchap_ctrl_key_show() all emit "<invalidated>\n".
[ ... ]
> @@ -925,6 +981,52 @@ static ssize_t dhchap_ctrl_secret_store(struct device *dev,
> }
>
> static DEVICE_ATTR_ADMIN_RW(dhchap_ctrl_secret);
> +
> +static ssize_t dhchap_key_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
[ ... ]
> +}
> +static DEVICE_ATTR_ADMIN_RO(dhchap_key);
> +
> +static ssize_t dhchap_ctrl_key_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
[ ... ]
> +}
> +static DEVICE_ATTR_ADMIN_RO(dhchap_ctrl_key);
[Severity: Low]
This isn't a bug, but the new dhchap_key and dhchap_ctrl_key sysfs
attributes are not mentioned in the commit message or documented in
Documentation/ABI/stable/sysfs-nvme. Also, the commit message says the
key serial is stored in struct nvmf_ctrl_options, whereas opts stores
struct key pointers (dhchap_key and dhchap_ctrl_key).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v5-0-81eefb4c0724@kernel.org?part=4
next prev parent reply other threads:[~2026-11-23 12:34 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 [this message]
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
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-229226@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