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=1795024559; b=njGo9LNwsBtsQLVq55KmKQ0c3E6QQ/JG3rYmEzaEE4DnuCZqQol48mZREYkmuQwwS09j 6OXFx2+FE+meHAAl2zN4AFCQ+USzA868WlzRk4/WR8bdtfBr4DiY0DkmChEAbHJyXPQK9 qRkaLs9LWGOV1DMHP578NBPoh3W5mQPuygLFWg3W0WL+7TAwnF83jKaYaZZ35J/yi6OaX wnSqQwCJ+eDChWeMmC8g+LSsTNAM7m0fjN5heqsV+MUlZevd7HzH6/1vDZ6ZKiUlJlN91 K+LpuFu4eZOAo9ncyqpYZmoB3SKNBupC7io7aPY2C0Do7yb+MOBN+daz+nZ1AwFAG9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795024559; 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=4AmoSXU5R0+38BdOiuDUkBr9YudHxoc4mhU6IynfzXw=; b=W3ny2dnSnZxsE/k0XGxDgb6ceJOp+WySjFoh8txPXJZ7u0OwVFCRXCHK6tny3G8N1Ylq 1f/Ak5+vnYOVZmnp/qUy6+TKoBLM7q5kB/cJdlOocU9x+C0KTc/xjJDpbZhV/ScSYwEdF 5ZMscCMXubDMr0zIlzC+/03VvcL7bNMO2Fk5gb6MzO45CgWCge5VtQWoxyK1js6aRtBhw wgF17N0lSIhvwOHfRRJPOgLNVKwZm3kqmVcrBCPGPgho4pk2PLBWW2I6R9r3NNzshmahw Bh406vfZyR1OxNNdTB/Fc5j9rWAc7P5ILumDeZgxHT1Bo7Ji9p4KQicAvgT/9+ZWS3g== 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=zO1rDi3t; 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 37467606A31C; Wed, 18 Nov 2026 17:55:58 +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=zO1rDi3t Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49D3C1F000C4; Wed, 18 Nov 2026 17:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795024558; bh=4AmoSXU5R0+38BdOiuDUkBr9YudHxoc4mhU6IynfzXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zO1rDi3tH4F0P3Z01+Ml/zF339M1xNaWozYabj87j7mGoM+ZnEPHhpWTDO1eAaac5 q3YkiASLEFpYG599ov/PypdE7Ml4b39kp+dhaf8aTgEn37h40aOCw/v5lFISnX3pHD Rh9h9cMbff8UaCCgSyJvht3CDh0uB/8AELaIhT5c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shashank Mohan Jain , Yury Norov , Sasha Levin Subject: [PATCH 6.18 0767/2151] bitmap: bitmap_parse(): reject non-hex character before 8 digits Date: Wed, 18 Nov 2026 15:41:42 +0100 Message-ID: <20261118150150.025919938@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shashank Mohan Jain [ Upstream commit 7cee2fb210a198667d3d4200705215e6f315cab0 ] bitmap_parse() is documented to return -EINVAL for illegal characters, and it does so everywhere except when the illegal character directly precedes a chunk of exactly eight hex digits. bitmap_get_x32_reverse() parses a chunk from right to left. After it has consumed eight digits it looks at one more character: a hex digit means the chunk is wider than 32 bits and -EOVERFLOW is returned. Any other character is silently consumed as if it were a separator, and the remaining input is parsed as the next chunk. As a result: "x12345678" -> 0x12345678, returns 0 (expected -EINVAL) "1g12345678" -> 0x1_12345678, returns 0 (expected -EINVAL) "0x0000000f" -> 0xf, returns 0, while "0xf" returns -EINVAL bitmap_parse() backs cpumask_parse() and cpumask_parse_user(), so the same inconsistency is visible when writing masks such as /proc/irq/*/smp_affinity or the network queue rps_cpus/xps_cpus files. __bitmap_parse(), which this function replaced in commit 2d6261583be0 ("lib: rework bitmap_parse()"), rejected all three strings with -EINVAL, and a "0x" prefix is accepted today only when exactly eight digits follow it, so no reliably working input is lost. When the loop falls through, *end is known to be a non-separator character inside the buffer, so return -EOVERFLOW if it is a hex digit and -EINVAL otherwise. Fixes: 2d6261583be0 ("lib: rework bitmap_parse()") Assisted-by: LLM Signed-off-by: Shashank Mohan Jain Signed-off-by: Yury Norov Signed-off-by: Sasha Levin --- lib/bitmap-str.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/bitmap-str.c b/lib/bitmap-str.c index be745209507a4..692a150a4d65c 100644 --- a/lib/bitmap-str.c +++ b/lib/bitmap-str.c @@ -447,8 +447,12 @@ static const char *bitmap_get_x32_reverse(const char *start, goto out; } - if (hex_to_bin(*end--) >= 0) - return ERR_PTR(-EOVERFLOW); + /* + * Eight digits have been consumed and the next character is not a + * separator: another hex digit means the chunk does not fit in 32 + * bits, anything else is an illegal character. + */ + return ERR_PTR(hex_to_bin(*end) >= 0 ? -EOVERFLOW : -EINVAL); out: *num = ret; return end; -- 2.53.0