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=1796382685; b=H2azwiTQe+GuDt7O+ChumV+c1lksSiWu8K65baF7nW5Clo8PJwJzzugcCeRgsFkTZ7qn yqdRLIbm/jv5oXMLZ5PpZLa2xRYmfoCbWOcYCnfmuuyVmCyXkjifFdv8Am1YJoJmTS7iE xK8B6zZk4c66DM9K3Zl4S+XQ+xO3Rv+lynV+/D+vup/00Om96Q2MLP/l+AV93V0IkbXTr rzTXQgjfYVj28dagSfOS3OVynzO40a3hPfwp/sEGMlH3hCnXqz6koMKitFvD3/9IZXTY7 mNb723NgVzCwKGtxj2SabmXNGpSB/Z85jybYjLs15S/+1Mumr7TgEQ8QWX37P8Mq39g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382685; 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=v+hZN6hSkBwPkYEa6ifJtlm4DMU4aXB18GkKdDrfnS0=; b=c5pbucE5aWvizVcg0OxhY6nlRj04I5CPAdFRLVvJG7hR7J8+cGF3hKg1dZuKIu+iXO60 qI6Vn7AshVZIN6+yAvGBz42iihf0BFmz9jCAoDPVSrzQvyYtodz1zfbh6QmvPGoEP2+1m S8QpvNLFZZADLH1IyRMRShBikn2SnZWgbvZSlkR8F8uG1MTuiEQ20Bw/QtF/ZVpFO1EHP HhsDr0fo3JgrMaNruuQgeABeqPtF2HU7Op1iKP4sZ7msCOZywe1Hioo93usJ4Vs4AwJyn 3e0rtJg9jDQDQsszIUwa358WVCjMnF/VSSUKE6XsAaARS+KghyG+SPyQH5vaH+ZYy8g== 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=rUg1PulE; 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 39036606A322; Fri, 4 Dec 2026 11:11:25 +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=rUg1PulE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E1A21F000C2; Fri, 4 Dec 2026 11:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382685; bh=v+hZN6hSkBwPkYEa6ifJtlm4DMU4aXB18GkKdDrfnS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rUg1PulEfhZMdoIPbf/Z77E9sKZeij9OTTxKC9p5Ni67JR2fiTs6nZbCR1Ao/6rk+ VkbdiElYu+5yOvPCNa1DdPYoxMCB08XQiAAlMqvjvxGsiQ7V3kttsB9+pe6CPh+fIM EUZ0371d/kLh7VwjmIJxLQ/7DHXbR+tdudT5FS/k= 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.18 560/703] nvme-auth: use the parsed offset for the DH-CHAP key Date: Fri, 4 Dec 2026 19:07:39 +0900 Message-ID: <20261204100642.673486606@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 @@ -536,17 +536,19 @@ int nvme_auth_generate_key(const char *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);