[PATCH 1/2] nvme-sysfs: use kfree_sensitive() for DH-HMAC-CHAP secrets

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Nov 16 02:14:02 PST 2026


Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] nvme: double-free and use-after-free in
  nvme_ctrl_dhchap_secret_store() [1]
--

commit 86ec9e603dccdb522db4b07402c30b2c18b2a11b
Author: Martin George <martinus.gpy at gmail.com>

nvme-sysfs: use kfree_sensitive() for DH-HMAC-CHAP secrets

This commit replaces kfree() with kfree_sensitive() when freeing DH-HMAC-CHAP
secret strings in dhchap_secret_store() and dhchap_ctrl_secret_store().

> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 10018c6356b62..5a195b8971f21 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -849,10 +849,10 @@ static ssize_t dhchap_secret_store(struct device *dev,
>  
>  		ret = nvme_auth_parse_key(dhchap_secret, &key);
>  		if (ret) {
> -			kfree(dhchap_secret);
> +			kfree_sensitive(dhchap_secret);
>  			return ret;
>  		}
> -		kfree(opts->dhchap_secret);
> +		kfree_sensitive(opts->dhchap_secret);
>  		opts->dhchap_secret = dhchap_secret;
>  		host_key = ctrl->host_key;
>  		mutex_lock(&ctrl->dhchap_auth_mutex);

[Severity: Critical]
This problem wasn't introduced by this patch, but can concurrent sysfs accesses
[1] trigger a double free or use-after-free on opts->dhchap_secret and
ctrl->host_key?

In dhchap_secret_store(), opts->dhchap_secret is freed and replaced without
holding a lock, and ctrl->host_key is read before acquiring
ctrl->dhchap_auth_mutex:

CPU0                                  CPU1
dhchap_secret_store()                 dhchap_secret_store()
  kfree_sensitive(opts->dhchap_secret)
                                        kfree_sensitive(opts->dhchap_secret)
                                          <-- double free
  opts->dhchap_secret = dhchap_secret
  host_key = ctrl->host_key
                                        host_key = ctrl->host_key
  mutex_lock(&ctrl->dhchap_auth_mutex)
  ctrl->host_key = key
  mutex_unlock(&ctrl->dhchap_auth_mutex)
  nvme_auth_free_key(host_key)
                                        mutex_lock(&ctrl->dhchap_auth_mutex)
                                        ctrl->host_key = key
                                        mutex_unlock(&ctrl->dhchap_auth_mutex)
                                        nvme_auth_free_key(host_key)
                                          <-- double free

A concurrent dhchap_secret_show() or strcmp() in dhchap_secret_store() can
also read opts->dhchap_secret while it is being freed, causing a
use-after-free.  The same unlocked accesses exist in
dhchap_ctrl_secret_store() and dhchap_ctrl_secret_show() for
opts->dhchap_ctrl_secret and ctrl->ctrl_key.

[1] https://sashiko.dev/#/bug/linux-d9bcd9ea-2b96-4998-b954-e0e2557a158a

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116100244.7824-1-marting@netapp.com?part=1



More information about the Linux-nvme mailing list