* [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets
@ 2026-11-16 10:02 Martin George
2026-11-16 10:02 ` [PATCH 1/2] nvme-sysfs: " Martin George
2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George
0 siblings, 2 replies; 4+ messages in thread
From: Martin George @ 2026-11-16 10:02 UTC (permalink / raw)
To: linux-nvme; +Cc: hch, kbusch, sagi, hare
The host side stores the raw DH-HMAC-CHAP secret ("DHHC-1:...") but frees
it with plain kfree() in a few places, leaving the secret in freed slab
until the memory is reused. Switch those kfrees to kfree_sensitive() so
the contents are wiped on free.
This is a hardening-only series; it fixes no functional bug and changes
no behaviour.
Martin George (2):
nvme-sysfs: use kfree_sensitive() for DH-HMAC-CHAP secrets
nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret
drivers/nvme/host/fabrics.c | 4 ++--
drivers/nvme/host/sysfs.c | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] nvme-sysfs: use kfree_sensitive() for DH-HMAC-CHAP secrets
2026-11-16 10:02 [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets Martin George
@ 2026-11-16 10:02 ` Martin George
2026-11-16 10:14 ` sashiko-bot
2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George
1 sibling, 1 reply; 4+ messages in thread
From: Martin George @ 2026-11-16 10:02 UTC (permalink / raw)
To: linux-nvme; +Cc: hch, kbusch, sagi, hare
dhchap_secret_store() and dhchap_ctrl_secret_store() free the raw
"DHHC-1:..." secret with plain kfree(), leaving it in the freed
slab. As these are the runtime rotation handlers, every secret
change also leaves the previous secret behind. Free them with
kfree_sensitive() instead.
Signed-off-by: Martin George <marting@netapp.com>
---
drivers/nvme/host/sysfs.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 9672ca3f74d2..35f871e3e0c0 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -850,10 +850,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);
@@ -861,7 +861,7 @@ static ssize_t dhchap_secret_store(struct device *dev,
mutex_unlock(&ctrl->dhchap_auth_mutex);
nvme_auth_free_key(host_key);
} else
- kfree(dhchap_secret);
+ kfree_sensitive(dhchap_secret);
/* Start re-authentication */
dev_info(ctrl->device, "re-authenticating controller\n");
queue_work(nvme_wq, &ctrl->dhchap_auth_work);
@@ -907,10 +907,10 @@ static ssize_t dhchap_ctrl_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_ctrl_secret);
+ kfree_sensitive(opts->dhchap_ctrl_secret);
opts->dhchap_ctrl_secret = dhchap_secret;
ctrl_key = ctrl->ctrl_key;
mutex_lock(&ctrl->dhchap_auth_mutex);
@@ -918,7 +918,7 @@ static ssize_t dhchap_ctrl_secret_store(struct device *dev,
mutex_unlock(&ctrl->dhchap_auth_mutex);
nvme_auth_free_key(ctrl_key);
} else
- kfree(dhchap_secret);
+ kfree_sensitive(dhchap_secret);
/* Start re-authentication */
dev_info(ctrl->device, "re-authenticating controller\n");
queue_work(nvme_wq, &ctrl->dhchap_auth_work);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret
2026-11-16 10:02 [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets Martin George
2026-11-16 10:02 ` [PATCH 1/2] nvme-sysfs: " Martin George
@ 2026-11-16 10:02 ` Martin George
1 sibling, 0 replies; 4+ messages in thread
From: Martin George @ 2026-11-16 10:02 UTC (permalink / raw)
To: linux-nvme; +Cc: hch, kbusch, sagi, hare
When a connect string overrides dhchap_secret or dhchap_ctrl_secret,
nvmf_parse_options() frees the previous raw secret with plain kfree().
The invalid-input path already uses kfree_sensitive(), so do the same
for the replaced secret.
Signed-off-by: Martin George <marting@netapp.com>
---
drivers/nvme/host/fabrics.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index c262538523fb..5ed91557f070 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -1026,7 +1026,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -EINVAL;
goto out;
}
- kfree(opts->dhchap_secret);
+ kfree_sensitive(opts->dhchap_secret);
opts->dhchap_secret = p;
break;
case NVMF_OPT_DHCHAP_CTRL_SECRET:
@@ -1041,7 +1041,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -EINVAL;
goto out;
}
- kfree(opts->dhchap_ctrl_secret);
+ kfree_sensitive(opts->dhchap_ctrl_secret);
opts->dhchap_ctrl_secret = p;
break;
case NVMF_OPT_TLS:
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] nvme-sysfs: use kfree_sensitive() for DH-HMAC-CHAP secrets
2026-11-16 10:02 ` [PATCH 1/2] nvme-sysfs: " Martin George
@ 2026-11-16 10:14 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-16 10:14 UTC (permalink / raw)
To: Martin George, linux-nvme
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@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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-16 10:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 10:02 [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets Martin George
2026-11-16 10:02 ` [PATCH 1/2] nvme-sysfs: " Martin George
2026-11-16 10:14 ` sashiko-bot
2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox