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=1796381276; b=HH+ujH4jWHz77CE5/Kd2pFBdG17AMuDsPMGGJQiNr9H9W2FGBdVmN6YXqQNrERHUxQqf oykHMgoicJKS3oyHwDjyZjlWJLX5pey/wjamlpl9uNi9Wtt8HOS7dBdFRuaNQFH/34w6Y 9wa2YUND0d0jPc9fzdXcLwv6yj174MIwzty90sK87rmOt8OReXgtS5yAcIsrVMxTnBPgV SPEgb7GdqqzVvgyDclgJ2pQzxgrUjJGdyxj3Eb12rSYTyWg7X/LO+dq9e66p/Y0IzZoJS cReRSi0rptnuw5/FQnjt/cqsY3lhO97oyG7+s0xNzBFe//uBBED3JH1WGt0+sJC/HBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381276; 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=3kHohyFRjA9DFFjgdMNWb1/S/YHzWx8nUkUpB8lmZd4=; b=PiQRvZqvTj6jHNgyKRZS0WYZxIElGhqGPO7rb9YTrR44F1Xz11RxflTT/LgF/Fgsktel OCl53ks6+1MTOXgCj30piS5amK3VeL7++GIZWIuhd4xnaYy9WCnXtrnwoy6HWdZt9k66g VgSf6jJJM77A2JcTHZQtDKg7DHiEGOtnS7nhUagGO4ACMGmNt6hRORf+E8mgmXmMdjoFv MUl51yoqULK/+HHD8BVzI7/MdBZUT+JNgq+NuuHoQpFtETbIpc03BEEZP6V+AtBbePm55 rBzZN5bucDAapBGDZQfi2PahDeEDhAvrUeOm2ulfyYjJBvIuAnBvTqT8nZIbxneKvlw== 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=dncoYPh4; 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 C2BCD606A68A; Fri, 4 Dec 2026 10:47:56 +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=dncoYPh4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0437A1F00A02; Fri, 4 Dec 2026 10:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381276; bh=3kHohyFRjA9DFFjgdMNWb1/S/YHzWx8nUkUpB8lmZd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dncoYPh4ptUCJr1L/LOuhR1YpPf0uoHpOdYsj+CSpoCg2x9m1nOjjYoSkq6uzkdeX Icq+ipwyihcxQqEbBZc27OsMM/kFgiK40HZVEacyfyR4XOfybjXHPFacfp5eTtBG/u NJySSbmbzMDmL3tjMdU396CdEiR46H0zbgePdnYQ= 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 7.3 635/742] nvme-auth: use the parsed offset for the DH-CHAP key Date: Fri, 4 Dec 2026 19:08:19 +0900 Message-ID: <20261204100651.965092522@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 @@ -489,17 +489,19 @@ int nvme_auth_parse_key(const char *secr { 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);