[PATCH v5 4/9] nvme: parse dhchap keys during option parsing

Hannes Reinecke hare at suse.de
Mon Nov 23 06:10:21 PST 2026


On 11/23/26 1:34 PM, sashiko-bot at kernel.org wrote:
> 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 at 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().
> 
Fixed with the next version.

>> 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.
> 
Removed the '#else' branches for the next version.

>> 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.
> 
Fixed wit the next version.

>> @@ -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.
> 
Fixed with the next version.

>> @@ -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".
> 
Fixed with the next version.

> [ ... ]
> 
>> @@ -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).
> 
Updated for the next version.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare at suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich



More information about the Linux-nvme mailing list