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=1796384055; b=MREDmqitoFmK6ECVWmcohlWYWMT51TczfsQK4YucDhp8agivgoePAaiD6tDCXNmYRLaM v13ORrkdaKsfOxHrLgwx2tUDQpxrm2DdsaTpqzmoKx3XsZl1r2B24FaP8WMZzJFmoZe3b 2QTXYKBxPSXnHq6D77uFTuJv7r8rqjs6LcGiLqWFLNdGrUze/wshZhXmC1w0BUaqHHuHS 0atsSczfbWfj7W/bf9vGFZwXMaaJSwkl83JwOf6urtZU64guKRggElRTZKp3kbGq6tg4r jwsnklyHwrMhVYLmUtfspM8OyJcvy4jyBeumGG+F9Vcc0399Ej/UxluHJuMjizr+eSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384055; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=pZxht5v/RPL8+jPHT4iF5+XRD/9516kGK2bjvUj7XWA=; b=SR/g9NucqbjE7o+y4MEN+Lwft7BmYJu2WpDlAbM7RCYbq7ea2WkyuG4T9RNqfa7fBiz+ i6EuMsx18jyE7ESk7y+vZkV7v7+1BRoYSPQIkOHWSd3UELvf9hPF7Vv1KL6Ux3YZlJ5bq NlFfkuLKO/9Tys8AUcFULIeg1tdyqvj37EGGTsnQnvrG3u3eN4oH8JaSOSEb/ikGbuCHw QlyEqM0ukSV9wdU0WTqWcheWpfep08G58Sd/w6jHF4sKK2Zg/JdQyGLKTWRt5O8cD3b0a QeefusG7yhk7M9nebQHFpUQJ8+8sct1AhewsjI9dZvSIVDNCHi5K/R/9XSf/nWuM2qw== 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=fEHtTUmX; 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 AB7F1606A32C; Fri, 4 Dec 2026 11:34:15 +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=fEHtTUmX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A7E51F000C2; Fri, 4 Dec 2026 11:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384055; bh=pZxht5v/RPL8+jPHT4iF5+XRD/9516kGK2bjvUj7XWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fEHtTUmX1m0Edq2oJAWz49mjSw/paV3c3DMhx41N39/kEawP2QSTDR8g6WY73ZNt/ u5QP5oJvSRCqLyVYfl89a6R/zuAlhNmV5KLqS5HdspgIR5mgTnKzc9xN9j209mTX2G 5ZeKXQluY/wa8mzSWsBCrj0oUSUaL/lugnwl14j8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Hannes Reinecke , Christoph Hellwig , Keith Busch Subject: [PATCH 6.12 476/555] nvme-auth: use the parsed offset for the DH-CHAP key Date: Fri, 4 Dec 2026 19:08:39 +0900 Message-ID: <20261204100627.354516615@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shao Mingyin commit f7141618d5d0b51bc2a64961bab738a0fe57e83f upstream. nvme_auth_parse_key() accepts the DH-HMAC-CHAP key with if (sscanf(secret, "DHHC-1:%hhd:%*s:", &key_hash) != 1) return -EINVAL; and then skips a hardcoded ten characters: key = nvme_auth_extract_key(secret + 10, key_hash); The ten characters assume that the hash identifier is exactly two characters long. A string such as "DHHC-1:1:" still makes sscanf() return 1, and secret + 10 then points one byte past the NUL terminator of the buffer. nvme_auth_extract_key() starts with strlen(secret), so it reads past the end of the allocation. The sysfs dhchap_secret and dhchap_ctrl_secret stores only require seven characters and a "DHHC-1:" prefix, so a short value reaches this code (even though the nvme-fabrics option parser rejects secrets shorter than eleven characters). Use the %n conversion to obtain the real offset after the "DHHC-1::" prefix and reject a string where the prefix is not complete. This accepts both one and two character hash identifiers and never starts the key past the terminator. Fixes: f50fff73d620 ("nvme: implement In-Band authentication") Cc: stable@vger.kernel.org Signed-off-by: Shao Mingyin Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/common/auth.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/nvme/common/auth.c +++ b/drivers/nvme/common/auth.c @@ -450,17 +450,19 @@ int nvme_auth_generate_key(u8 *secret, s { struct nvme_dhchap_key *key; u8 key_hash; + int offset = 0; if (!secret) { *ret_key = NULL; 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; /* Pass in the secret without the 'DHHC-1:XX:' prefix */ - key = nvme_auth_extract_key(secret + 10, key_hash); + key = nvme_auth_extract_key(secret + offset, key_hash); if (IS_ERR(key)) { *ret_key = NULL; return PTR_ERR(key);