* [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
` (2 more replies)
0 siblings, 3 replies; 9+ 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] 9+ 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 ` (2 more replies) 2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George 2026-11-16 16:18 ` [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets Keith Busch 2 siblings, 3 replies; 9+ 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] 9+ 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 2026-11-16 13:44 ` Hannes Reinecke 2026-11-20 17:29 ` Christoph Hellwig 2 siblings, 0 replies; 9+ 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] 9+ 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 @ 2026-11-16 13:44 ` Hannes Reinecke 2026-11-20 17:29 ` Christoph Hellwig 2 siblings, 0 replies; 9+ messages in thread From: Hannes Reinecke @ 2026-11-16 13:44 UTC (permalink / raw) To: Martin George, linux-nvme; +Cc: hch, kbusch, sagi, hare On 11/16/26 11:02 AM, Martin George wrote: > 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(-) > Reviewed-by: Hannes Reinecke <hare@kernel.org> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@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 ^ permalink raw reply [flat|nested] 9+ 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 2026-11-16 13:44 ` Hannes Reinecke @ 2026-11-20 17:29 ` Christoph Hellwig 2 siblings, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2026-11-20 17:29 UTC (permalink / raw) To: Martin George; +Cc: linux-nvme, hch, kbusch, sagi, hare Looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 9+ 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 2026-11-16 13:45 ` Hannes Reinecke 2026-11-20 17:29 ` Christoph Hellwig 2026-11-16 16:18 ` [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets Keith Busch 2 siblings, 2 replies; 9+ 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] 9+ messages in thread
* Re: [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret 2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George @ 2026-11-16 13:45 ` Hannes Reinecke 2026-11-20 17:29 ` Christoph Hellwig 1 sibling, 0 replies; 9+ messages in thread From: Hannes Reinecke @ 2026-11-16 13:45 UTC (permalink / raw) To: Martin George, linux-nvme; +Cc: hch, kbusch, sagi, hare On 11/16/26 11:02 AM, Martin George wrote: > 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: Reviewed-by: Hannes Reinecke <hare@kernel.org> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret 2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George 2026-11-16 13:45 ` Hannes Reinecke @ 2026-11-20 17:29 ` Christoph Hellwig 1 sibling, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2026-11-20 17:29 UTC (permalink / raw) To: Martin George; +Cc: linux-nvme, hch, kbusch, sagi, hare Looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] nvme: 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 ` [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 @ 2026-11-16 16:18 ` Keith Busch 2 siblings, 0 replies; 9+ messages in thread From: Keith Busch @ 2026-11-16 16:18 UTC (permalink / raw) To: linux-nvme, Martin George; +Cc: hch, sagi, hare On Mon, 16 Nov 2026 15:32:42 +0530, Martin George wrote: > 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. > > [...] Thanks, applied to nvme-7.4. [1/2] nvme-sysfs: use kfree_sensitive() for DH-HMAC-CHAP secrets commit: 7fce38923253c27650835c91201b222214aeb149 [2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret commit: 68099cf27253a8c89d703a282d3d811446d9453b -- Keith Busch <kbusch@kernel.org> ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-20 17:30 UTC | newest] Thread overview: 9+ 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 13:44 ` Hannes Reinecke 2026-11-20 17:29 ` Christoph Hellwig 2026-11-16 10:02 ` [PATCH 2/2] nvme-fabrics: use kfree_sensitive() for the old DH-HMAC-CHAP secret Martin George 2026-11-16 13:45 ` Hannes Reinecke 2026-11-20 17:29 ` Christoph Hellwig 2026-11-16 16:18 ` [PATCH 0/2] nvme: use kfree_sensitive() for DH-HMAC-CHAP secrets Keith Busch
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.