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=1796221509; b=R8nZAZ64EPUL3+VotYbcIyEpufWgoVtizOE7KbS54PTnN5RNmgU6Kk7OmkivsGrj2O9v dA9Mx8Q1wTVBTAT4MmiRWNwd1rsWu/EF/b4c6TEAtlOvBPSmGftZwEpUXpuXqdaK+pJDL O8sBVaKIt9at2pXyd6lduO0LzbgnQLcp6/lJgsPdrivZJmlr5WcMU0RxKJ1wGKByg/vCE NDad0U7jvL3qNhhIUoNLiSCNowAKVG8332M1GtuQOIhv/1mfLvKJFcu76zJLMa2cfwgbm uWiCwFCfP6thN3oNa8HofJ4NX3uyE9pMCyt8tWvoiN3tu8i4mPJsZzd8AcJVsTw1ojQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221509; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=Q7eFpR2eVRMCy4RltCDkK92dBA7vAgTkiR5x8UpR0go=; b=JfoNIGR4fzxljikHUuZz4QR6ZsKyIgpOhAFDwOxOJn6HMaS/TFsZ2NOOsIKnWxV+9za+ eBSpPHlB8vLhotHbe423leT8CmZJ9lKnfbcPjSyXoaxh4VJHm7yp8DARCeIW9vpMQu0UG XUNEOhzhXkfHA1vZIqvq5da1vlm4HqiPwerX2tMGw//DcBn3zgVc8525pnTmwsNmeiW+i i4UEgXo9pmOxJur9NiQYFKfq/6f4rQsid1WJNKag4Yk3IK2w5je4lgF/1rWyUWSl3rRqj QaDWAqd20Y2gSegtbUsdvj6cDY4MXPJcI2MVB76Azn43/oSzUe4h5mPLaaqvhJjSfpw== 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=r3qZ2On2; 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 BDB2C606A31A for ; Wed, 2 Dec 2026 14:25:09 +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=r3qZ2On2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C54091F00897; Wed, 2 Dec 2026 14:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221509; bh=Q7eFpR2eVRMCy4RltCDkK92dBA7vAgTkiR5x8UpR0go=; h=Subject:To:Cc:From:Date; b=r3qZ2On2hhySZaa/Lwi8iSOpAnfs3675RYmYGTMvpO/SqIANCmEN6YXc4QuAtx7W4 mxgYnHqLSZSpVReSI5J0wpVblJ0Z4QfJ46jaRsgJrpiA5UGS204irfyfLodW+7rsOg bp3fGoA0//9bsS2h3O6m4XcgC2mdD6OLcPVNU7lU= Subject: FAILED: patch "[PATCH] nvmet-auth: store the DH-CHAP key offset instead of" failed to apply to 6.18-stable tree To: shao.mingyin@zte.com.cn,hch@lst.de,kbusch@kernel.org Cc: From: Date: Wed, 02 Dec 2026 14:53:23 +0100 Message-ID: <2026120222-collision-neuron-268d@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.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 . 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 # git commit -s git send-email --to '' --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 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;