[PATCH v6 4/9] nvme: parse dhchap keys during option parsing
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 23 09:26:34 PST 2026
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] nvme: dhchap_key_show() and dhchap_ctrl_key_show() return 0
instead of none
- [Low] nvme-auth: log of unassigned ctrl->host_key in
nvme_auth_init_ctrl()
--
commit bfaa9fb3c74e5de5eb5e03ecba9893bb438923f7
Author: Hannes Reinecke <hare at kernel.org>
nvme: parse dhchap keys during option parsing
This commit creates DH-HMAC-CHAP keys during fabric option parsing to store
struct key pointers instead of plain text secrets in nvmf_ctrl_options, and
adds dhchap_key and dhchap_ctrl_key sysfs attributes exposing their key
serial numbers.
> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
> index 0ddf3834f4ea2..26e8f321650e7 100644
> --- a/drivers/nvme/host/auth.c
> +++ b/drivers/nvme/host/auth.c
[ ... ]
> @@ -1029,40 +1024,100 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
[ ... ]
> + pr_debug("%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;
[Severity: Low]
Should this pr_debug() pass key_serial(host_key) instead of
key_serial(ctrl->host_key)? Because ctrl->host_key has not been assigned
yet, it logs 00000000 instead of the new key serial.
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index a5c1511e49ac2..6fab0d217e749 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
[ ... ]
> @@ -925,6 +985,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)
> +{
> + struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> + struct key *key;
> + ssize_t count = 0;
> +
> + mutex_lock(&ctrl->dhchap_auth_mutex);
> + key = ctrl->host_key;
> + if (key) {
> + down_read(&key->sem);
> + if (key_validate(key))
> + count = sysfs_emit(buf, "<invalidated>\n");
> + else
> + count = sysfs_emit(buf, "%08x\n",
> + key_serial(key));
> + up_read(&key->sem);
> + }
> + mutex_unlock(&ctrl->dhchap_auth_mutex);
> + return count;
> +}
> +static DEVICE_ATTR_ADMIN_RO(dhchap_key);
> +
> +static ssize_t dhchap_ctrl_key_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> + struct key *key;
> + ssize_t count = 0;
> +
> + mutex_lock(&ctrl->dhchap_auth_mutex);
> + key = ctrl->ctrl_key;
> + if (key) {
> + down_read(&key->sem);
> + if (key_validate(key))
> + count = sysfs_emit(buf, "<invalidated>\n");
> + else
> + count = sysfs_emit(buf, "%08x\n",
> + key_serial(key));
> + up_read(&key->sem);
> + }
> + mutex_unlock(&ctrl->dhchap_auth_mutex);
> + return count;
> +}
> +static DEVICE_ATTR_ADMIN_RO(dhchap_ctrl_key);
[Severity: Low]
Should dhchap_key_show() and dhchap_ctrl_key_show() emit "none\n" when key
is NULL? The Documentation/ABI/stable/sysfs-nvme entry added in this patch
states that reading dhchap_key and dhchap_ctrl_key returns "none" if not
set, matching dhchap_secret_show() and dhchap_ctrl_secret_show(), but both
functions currently return 0 (empty output).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v6-0-5082a49715ab@kernel.org?part=4
More information about the Linux-nvme
mailing list