[PATCH v7 07/14] nvme: parse dhchap keys during option parsing

sashiko-bot at kernel.org sashiko-bot at kernel.org
Thu Nov 26 06:29:29 PST 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvme-auth: ERR_PTR dereference on key_lookup() in
  nvme_auth_init_ctrl()
--

commit 0df67db2f376340a8318c48ba959e7e18c9db8b6
Author: Hannes Reinecke <hare at kernel.org>

nvme: parse dhchap keys during option parsing

This commit creates DH-HMAC-CHAP keys during fabrics option parsing,
stores their key serials in struct nvmf_ctrl_options, and adds
dhchap_key and dhchap_ctrl_key sysfs attributes.

> diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
> index d6abdb4f1e21c..285aa1c71f102 100644
> --- a/drivers/nvme/host/auth.c
> +++ b/drivers/nvme/host/auth.c
[ ... ]
> @@ -1028,38 +1023,100 @@ static void nvme_ctrl_auth_work(struct work_struct *work)
[ ... ]
>  int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
>  {
>  	struct nvme_dhchap_queue_context *chap;
> +	struct key *host_key, *ctrl_key = NULL;
>  	int i, ret;
>  
>  	mutex_init(&ctrl->dhchap_auth_mutex);
>  	INIT_WORK(&ctrl->dhchap_auth_work, nvme_ctrl_auth_work);
>  	if (!ctrl->opts)
>  		return 0;
> -	ctrl->host_key = nvme_auth_extract_key(ctrl->opts->dhchap_secret,
> -				strlen(ctrl->opts->dhchap_secret));
> -	if (IS_ERR(ctrl->host_key)) {
> -		ret = PTR_ERR(ctrl->host_key);
> -		ctrl->host_key = NULL;
> -		return ret;
> +	if (!ctrl->opts->dhchap_key) {
> +		nvme_auth_clear_host_key(ctrl);
> +		nvme_auth_clear_ctrl_key(ctrl);
> +		return 0;
>  	}
>  
> -	ctrl->ctrl_key = nvme_auth_extract_key(ctrl->opts->dhchap_ctrl_secret,
> -				strlen(ctrl->opts->dhchap_ctrl_secret));
> -	if (IS_ERR(ctrl->ctrl_key)) {
> -		ret = PTR_ERR(ctrl->ctrl_key);
> -		ctrl->ctrl_key = NULL;
> -		goto err_free_dhchap_secret;
> +	host_key = key_lookup(ctrl->opts->dhchap_key);
> +	if (!host_key) {
> +		pr_warn("dhchap host key %08x not present\n",
> +			ctrl->opts->dhchap_key);
> +		return -ENOKEY;
> +	}
> +	down_read(&host_key->sem);
> +	ret = key_validate(host_key);
> +	up_read(&host_key->sem);
> +	if (ret) {
> +		pr_warn("dhchap host key %08x invalidated\n",
> +			key_serial(host_key));
> +		key_put(host_key);
> +		return -ENOKEY;
>  	}
>  
> -	if (!ctrl->opts->dhchap_secret && !ctrl->opts->dhchap_ctrl_secret)
> -		return 0;
> +	if (ctrl->opts->dhchap_ctrl_key) {
> +		ctrl_key = key_lookup(ctrl->opts->dhchap_ctrl_key);
> +		if (!ctrl_key) {
> +			pr_warn("dhchap ctrl key %08x not present\n",
> +				ctrl->opts->dhchap_ctrl_key);
> +			key_put(host_key);
> +			return -ENOKEY;
> +		}
> +		down_read(&ctrl_key->sem);

[Severity: High]
Should host_key and ctrl_key be checked with IS_ERR() rather than for
NULL after key_lookup()?  key_lookup() returns ERR_PTR(-ENOKEY) when a
key serial is not found, so if either key is removed before
nvme_auth_init_ctrl() runs, down_read() will dereference an error
pointer.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-dhchap-keyring-v4-v7-0-ee438ffea527@kernel.org?part=7



More information about the Linux-nvme mailing list