[PATCH v6 9/9] nvmet: add configfs attribute 'dhchap_keyring'

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Nov 23 09:33:13 PST 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmet: writing .nvme to nvmet_host_dhchap_keyring_store()
  fails with -ENOKEY
--

commit 11d3b355e4b75a4b62f576abb3e457739f6b882d
Author: Hannes Reinecke <hare at kernel.org>

nvmet: add configfs attribute 'dhchap_keyring'

This commit adds a dhchap_keyring configfs attribute to the nvmet host
directory so userspace can configure the keyring used for DH-HMAC-CHAP key
lookups.

> diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
> index e19af764561ec..179f6bef77372 100644
> --- a/drivers/nvme/target/configfs.c
> +++ b/drivers/nvme/target/configfs.c
> @@ -2350,6 +2350,64 @@ static ssize_t nvmet_host_dhchap_ctrl_key_store(struct config_item *item,
>  
>  CONFIGFS_ATTR(nvmet_host_, dhchap_ctrl_key);
>  
> +static ssize_t nvmet_host_dhchap_keyring_show(struct config_item *item,
> +		char *page)
> +{
> +	struct nvmet_host *host = to_host(item);
> +	struct key *keyring;
> +	ssize_t ret;
> +
> +	down_read(&nvmet_config_sem);
> +	keyring = key_get(host->dhchap_keyring);
> +	if (!keyring) {
> +		page[0] = '\0';
> +		ret = 0;
> +	} else {
> +		down_read(&keyring->sem);
> +		if (key_validate(keyring))
> +			ret = sprintf(page, "<invalidated>\n");
> +		else
> +			ret = scnprintf(page, PAGE_SIZE,
> +					"%s\n", keyring->description);
> +		up_read(&keyring->sem);
> +		key_put(keyring);
> +	}
> +	up_read(&nvmet_config_sem);
> +	return ret;
> +}
> +
> +static ssize_t nvmet_host_dhchap_keyring_store(struct config_item *item,
> +		const char *page, size_t count)
> +{
> +	struct nvmet_host *host = to_host(item);
> +	struct key *keyring;
> +	char *desc = NULL;
> +	size_t len;
> +	int ret = 0;
> +
> +	len = strcspn(page, "\n");
> +	if (len) {
> +		desc = kstrndup(page, len, GFP_KERNEL);
> +		if (!desc)
> +			return -ENOMEM;
> +		keyring = request_key(&key_type_keyring, desc, NULL);
> +	} else
> +		keyring = key_lookup(nvme_keyring_id());

[Severity: Medium]
Does writing ".nvme" to dhchap_keyring fail with -ENOKEY?

nvmet_hosts_make_group() initializes host->dhchap_keyring via
key_lookup(nvme_keyring_id()), so nvmet_host_dhchap_keyring_show() outputs
".nvme" by default (making the !keyring branch in show unreachable).
However, nvme_keyring_init() allocates the ".nvme" keyring with dest set to
NULL, so it is not linked into the calling task's process keyrings.

When a tool such as nvmetcli saves and restores the configuration by
writing ".nvme" back to dhchap_keyring, len is non-zero and
nvmet_host_dhchap_keyring_store() calls request_key(), which searches only
the process keyrings and fails with -ENOKEY unless ".nvme" was manually
linked into them.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v6-0-5082a49715ab@kernel.org?part=9



More information about the Linux-nvme mailing list