* FAILED: patch "[PATCH] nvmet-auth: store the DH-CHAP key offset instead of" failed to apply to 7.3-stable tree
@ 2026-12-02 13:53 gregkh
2026-12-03 13:16 ` [PATCH 7.3.y] nvmet-auth: store the DH-CHAP key offset instead of hardcoding it shao.mingyin
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-12-02 13:53 UTC (permalink / raw)
To: shao.mingyin, hch, kbusch; +Cc: stable
The patch below does not apply to the 7.3-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.3.y
git checkout FETCH_HEAD
git cherry-pick -x 62dae895f986f7459fea1deebd89a0bce76a886f
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120222-egotistic-jurist-7adf@gregkh' --subject-prefix 'PATCH 7.3.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 62dae895f986f7459fea1deebd89a0bce76a886f Mon Sep 17 00:00:00 2001
From: Shao Mingyin <shao.mingyin@zte.com.cn>
Date: Mon, 9 Nov 2026 22:59:21 +0800
Subject: [PATCH] nvmet-auth: store the DH-CHAP key offset instead of
hardcoding it
nvmet_auth_set_key() accepts variable-width hash identifiers, but
nvmet_setup_auth() always skips ten bytes before extracting the key.
For "DHHC-1:1:" this starts one byte past the allocated string's NUL
terminator, causing an out-of-bounds read in nvme_auth_extract_key().
Other nonstandard prefix widths also select the wrong key bytes.
Use %n to validate the complete prefix and record its actual length
for both host and controller secrets. Keep the offsets as int, matching
the scan result, so whitespace or leading zeroes in the hash identifier
do not truncate the saved offset.
Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Cc: stable@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
index 8ca5a061d565..a4a2a5cfd823 100644
--- a/drivers/nvme/target/auth.c
+++ b/drivers/nvme/target/auth.c
@@ -24,6 +24,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
{
unsigned char key_hash;
char *dhchap_secret;
+ int offset = 0;
if (!strlen(secret)) {
down_write(&nvmet_config_sem);
@@ -31,15 +32,18 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
kfree(host->dhchap_ctrl_secret);
host->dhchap_ctrl_secret = NULL;
host->dhchap_ctrl_key_hash = 0;
+ host->dhchap_ctrl_key_offset = 0;
} else {
kfree(host->dhchap_secret);
host->dhchap_secret = NULL;
host->dhchap_key_hash = 0;
+ host->dhchap_key_offset = 0;
}
up_write(&nvmet_config_sem);
return 0;
}
- if (sscanf(secret, "DHHC-1:%hhd:%*s", &key_hash) != 1)
+ if (sscanf(secret, "DHHC-1:%hhd:%n", &key_hash, &offset) != 1 ||
+ !offset)
return -EINVAL;
if (key_hash > 3) {
pr_warn("Invalid DH-HMAC-CHAP hash id %d\n",
@@ -54,10 +58,12 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
kfree(host->dhchap_ctrl_secret);
host->dhchap_ctrl_secret = strim(dhchap_secret);
host->dhchap_ctrl_key_hash = key_hash;
+ host->dhchap_ctrl_key_offset = offset;
} else {
kfree(host->dhchap_secret);
host->dhchap_secret = strim(dhchap_secret);
host->dhchap_key_hash = key_hash;
+ host->dhchap_key_offset = offset;
}
up_write(&nvmet_config_sem);
return 0;
@@ -186,14 +192,16 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset)
* Skip the 'DHHC-1:XX:' prefix. Keep the old keys until the new ones
* are there: a controller without a host key needs no authentication.
*/
- host_key = nvme_auth_extract_key(host->dhchap_secret + 10,
+ host_key = nvme_auth_extract_key(host->dhchap_secret +
+ host->dhchap_key_offset,
host->dhchap_key_hash);
if (IS_ERR(host_key)) {
ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
goto out_unlock;
}
if (host->dhchap_ctrl_secret) {
- ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10,
+ ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret +
+ host->dhchap_ctrl_key_offset,
host->dhchap_ctrl_key_hash);
if (IS_ERR(ctrl_key)) {
nvme_auth_free_key(host_key);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 2c2460ef5e2b..e33884a81efc 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -401,6 +401,8 @@ struct nvmet_host {
struct config_group group;
u8 *dhchap_secret;
u8 *dhchap_ctrl_secret;
+ int dhchap_key_offset;
+ int dhchap_ctrl_key_offset;
u8 dhchap_key_hash;
u8 dhchap_ctrl_key_hash;
u8 dhchap_hash_id;
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 7.3.y] nvmet-auth: store the DH-CHAP key offset instead of hardcoding it
2026-12-02 13:53 FAILED: patch "[PATCH] nvmet-auth: store the DH-CHAP key offset instead of" failed to apply to 7.3-stable tree gregkh
@ 2026-12-03 13:16 ` shao.mingyin
2026-12-04 19:49 ` Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: shao.mingyin @ 2026-12-03 13:16 UTC (permalink / raw)
To: stable; +Cc: hch, kbusch
From: Shao Mingyin <shao.mingyin@zte.com.cn>
commit 62dae895f986f7459fea1deebd89a0bce76a886f upstream.
nvmet_auth_set_key() accepts variable-width hash identifiers, but
nvmet_setup_auth() always skips ten bytes before extracting the key.
For "DHHC-1:1:" this starts one byte past the allocated string's NUL
terminator, causing an out-of-bounds read in nvme_auth_extract_key().
Other nonstandard prefix widths also select the wrong key bytes.
Use %n to validate the complete prefix and record its actual length
for both host and controller secrets. Keep the offsets as int, matching
the scan result, so whitespace or leading zeroes in the hash identifier
do not truncate the saved offset.
This is a backport to 7.3.y. The offset reset for a cleared key is
added in the empty-secret branch as upstream does; this tree acquires
nvmet_config_sem before the assignment, so the locking layout is
unchanged. nvmet_setup_auth() already has the upstream shape.
Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Cc: stable@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/nvme/target/auth.c | 14 +++++++++++---
drivers/nvme/target/nvmet.h | 2 ++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
index ccba84b134..a4cd045515 100644
--- a/drivers/nvme/target/auth.c
+++ b/drivers/nvme/target/auth.c
@@ -24,20 +24,24 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
{
unsigned char key_hash;
char *dhchap_secret;
+ int offset = 0;
if (!strlen(secret)) {
if (set_ctrl) {
kfree(host->dhchap_ctrl_secret);
host->dhchap_ctrl_secret = NULL;
host->dhchap_ctrl_key_hash = 0;
+ host->dhchap_ctrl_key_offset = 0;
} else {
kfree(host->dhchap_secret);
host->dhchap_secret = NULL;
host->dhchap_key_hash = 0;
+ host->dhchap_key_offset = 0;
}
return 0;
}
- if (sscanf(secret, "DHHC-1:%hhd:%*s", &key_hash) != 1)
+ if (sscanf(secret, "DHHC-1:%hhd:%n", &key_hash, &offset) != 1 ||
+ !offset)
return -EINVAL;
if (key_hash > 3) {
pr_warn("Invalid DH-HMAC-CHAP hash id %d\n",
@@ -52,10 +56,12 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
kfree(host->dhchap_ctrl_secret);
host->dhchap_ctrl_secret = strim(dhchap_secret);
host->dhchap_ctrl_key_hash = key_hash;
+ host->dhchap_ctrl_key_offset = offset;
} else {
kfree(host->dhchap_secret);
host->dhchap_secret = strim(dhchap_secret);
host->dhchap_key_hash = key_hash;
+ host->dhchap_key_offset = offset;
}
up_write(&nvmet_config_sem);
return 0;
@@ -177,14 +183,16 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset)
* Skip the 'DHHC-1:XX:' prefix. Keep the old keys until the new ones
* are there: a controller without a host key needs no authentication.
*/
- host_key = nvme_auth_extract_key(host->dhchap_secret + 10,
+ host_key = nvme_auth_extract_key(host->dhchap_secret +
+ host->dhchap_key_offset,
host->dhchap_key_hash);
if (IS_ERR(host_key)) {
ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
goto out_unlock;
}
if (host->dhchap_ctrl_secret) {
- ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret + 10,
+ ctrl_key = nvme_auth_extract_key(host->dhchap_ctrl_secret +
+ host->dhchap_ctrl_key_offset,
host->dhchap_ctrl_key_hash);
if (IS_ERR(ctrl_key)) {
nvme_auth_free_key(host_key);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index aab65ef2f2..4427814197 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -390,6 +390,8 @@ struct nvmet_host {
struct config_group group;
u8 *dhchap_secret;
u8 *dhchap_ctrl_secret;
+ int dhchap_key_offset;
+ int dhchap_ctrl_key_offset;
u8 dhchap_key_hash;
u8 dhchap_ctrl_key_hash;
u8 dhchap_hash_id;
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 7.3.y] nvmet-auth: store the DH-CHAP key offset instead of hardcoding it
2026-12-03 13:16 ` [PATCH 7.3.y] nvmet-auth: store the DH-CHAP key offset instead of hardcoding it shao.mingyin
@ 2026-12-04 19:49 ` Sasha Levin
0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-12-04 19:49 UTC (permalink / raw)
To: stable; +Cc: Sasha Levin, hch, kbusch, shao.mingyin
> commit 62dae895f986f7459fea1deebd89a0bce76a886f upstream.
>
> nvmet_auth_set_key() accepts variable-width hash identifiers, but
> nvmet_setup_auth() always skips ten bytes before extracting the key.
Queued for 7.3, and your 6.18, 6.12, 6.6 and 6.1 backports for those
trees, thanks.
On top of it I also took "nvmet: synchronize DH-CHAP secret removal"
for 7.3, 6.18 and 6.12, and "nvmet: lock config semaphore when
accessing DH-HMAC-CHAP key" for 6.6 and 6.1, so the key handling is
under nvmet_config_sem on every tree.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 19:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:53 FAILED: patch "[PATCH] nvmet-auth: store the DH-CHAP key offset instead of" failed to apply to 7.3-stable tree gregkh
2026-12-03 13:16 ` [PATCH 7.3.y] nvmet-auth: store the DH-CHAP key offset instead of hardcoding it shao.mingyin
2026-12-04 19:49 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox