From: <gregkh@linuxfoundation.org>
To: shao.mingyin@zte.com.cn,hch@lst.de,kbusch@kernel.org
Cc: <stable@vger.kernel.org>
Subject: FAILED: patch "[PATCH] nvmet-auth: store the DH-CHAP key offset instead of" failed to apply to 6.18-stable tree
Date: Wed, 02 Dec 2026 14:53:23 +0100 [thread overview]
Message-ID: <2026120222-collision-neuron-268d@gregkh> (raw)
The patch below does not apply to the 6.18-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-6.18.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-collision-neuron-268d@gregkh' --subject-prefix 'PATCH 6.18.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;
reply other threads:[~2026-12-02 14:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2026120222-collision-neuron-268d@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=shao.mingyin@zte.com.cn \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox