From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221513; b=VKFCbSqOg3Rj5uGLKTqC0x+FOZkymdlb7u161XYMdSBGgwPydz1ps1fJfkjPzwK0yRtI s7wcwGMun8aIgOWBekfHLQSHg5pDryUPjVUoyfJ3gFI7e8Pu4hC6Yxnbo28nEqMfCe/PE Zy3D9exLUCZgHIlxpBLB47I03Gwsc3aUmd1PVji6NPm9nNNpInAOoBFdGs+StOCAqYMhJ w0HGuoeDvqujXa2VKIxX8rTjswRCn5XyjNbcv+Q8+kqD3GapRYxrZLp2rMCLPZUdS6x92 UPSYsMvfnlwLJnXLpL1TOA26/XGj+bmYMRbSg9aFx4orJ5eWJJFAfK9O+fIs06cii8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221513; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=M1o3LFwiWiVASmeG0lgNiPCzl+2A4g3ytrax5+YjUT0=; b=rTG28xwHGAD0lIkrAcz6U8OdPym9q96UXIjAbfZjfo2qxvJB5StUEkSWE99syKpSBO7/ lEdqQrfgjQ/iuu54kH4S7f2zQi7Pk/OF+G4Ipu+ie1nP9JAi+Bo8iOOBHLgXmYNqnIMbe AFylmO+/kmAdrTxM8IGdML2Oy6sYagqnOWU85OY2RNCB1JhplGt6ojzdwkmGDDAITxQAt 0vWC/7JDsEMch5Jbwzu0/qr4CZ/1Y3fzOZfGTSLsSQtPjbd9+8IUXphsofEvirzSDOm2w 8GwLn8fsNxR2dcvRsSSnTU1YzOkqSNDiek+fMYo6I1MzWrmz5BaqqSIC80nK8s5t9Wg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PmzCtk5A; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 267FC606A322 for ; Wed, 2 Dec 2026 14:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PmzCtk5A Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF3B01F00897; Wed, 2 Dec 2026 14:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221512; bh=M1o3LFwiWiVASmeG0lgNiPCzl+2A4g3ytrax5+YjUT0=; h=Subject:To:Cc:From:Date; b=PmzCtk5AyWTSCEt9URfvBJf3H8MlzRhEUfaSdVDgl4fTg4s82yzDlwboy2GSv4xg7 OzIbMFzgcnPwxmyb3NPjd/66uFPTPPKjStahjkESRYgmlCI4yl/ZHOeAbp2ROHwGuG oSay502leRszW5+LP53SQMdsYL0ESwTOm7cLH+wY= Subject: FAILED: patch "[PATCH] nvmet-auth: store the DH-CHAP key offset instead of" failed to apply to 6.1-stable tree To: shao.mingyin@zte.com.cn,hch@lst.de,kbusch@kernel.org Cc: From: Date: Wed, 02 Dec 2026 14:53:24 +0100 Message-ID: <2026120224-saddling-reboot-6034@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.1-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 . 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.1.y git checkout FETCH_HEAD git cherry-pick -x 62dae895f986f7459fea1deebd89a0bce76a886f # git commit -s git send-email --to '' --in-reply-to '2026120224-saddling-reboot-6034@gregkh' --subject-prefix 'PATCH 6.1.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 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 Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch 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;