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=1796387593; b=XCZ+5D+0kyJIhYf7P+HJC9SZRocTCfRbKMlvGkAP0i35XWFSuftn7meYRbWtHLxS6VbR iFhaMxCkd3SWP36dmpUE3EBzPFMH+tbvhpsdI+ViK6tqZXdP0UsWTuifnG+5VuNdTqylS HwQCSMNeNYbe+gc3gqdRqA02ho9D0RiurBzBbb5fWQ6/6AwKQBUaDv4FCQNIVY2rwZ5vL pRb9gU2Fl7k2ZQtSINZtFnZGXfB1YSYEJud1cYDtX7o88K2IGmMWJbY1ycqQ+2aoN+TLN wgNeyoiNETADL6GFBxvsbZ5NUpXaclbqUbNE+hUElDqyihuTwVjQT/mk1AoqmBj1Y0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387593; 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=uDokYxuYjGVVSrnNjnCNdpdgVgCY8WnB9uljaO2PqR0=; b=ex3T8a72iIvmsDzqf61i2jGS7nPW8udB2MuKfripKpJjjoxRDQaXGRAOvOrDVnVZoA7A EdyZhDrbgW7bbVpWY3e9pTyzdkz6Chb8Sdoq5Zm7xBk1L2JErxL/tNQTQLuGb3/ueA4SG kmn4sVl2KSNqMfa1n6ywYORsN3ARQ7dEc3YD4IwdVEzo5okpJMU5Sqta7NySQqKJwi9Ok QUg9sV6/2kn6u2nfcG5eM8/IyGa/zvYyxXjhZnVdwhU06hLxqHEh2jS1Dy9ge9iFGJUSc zs314QrnCmM5Gxuhx/+ADy41l7HVreVmI84H8eAhHdAxrgWqPTYNe24iZa4Bdvd4njw== 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=ggiNh07J; 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 3D7ED606A322; Fri, 4 Dec 2026 12:33:13 +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=ggiNh07J Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA1541F000CE; Fri, 4 Dec 2026 12:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387593; bh=uDokYxuYjGVVSrnNjnCNdpdgVgCY8WnB9uljaO2PqR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ggiNh07Jlie8kMCJ8+nZk0+julDAFLHgHecS65bKegCN5chdPxH2Ow25s4h/MHLfl 0WNDOmYV4RFKDLCJElGTF57VBV0BvSsXTFu2tMxpyOAbzUt1o8HJvg494RDFPo9Vhp 6YSnpq196eWrHo/QyDtocgNZ3HtR2dtD1JBNDsPU= 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.1 0308/1059] bitmap: bitmap_parse(): reject non-hex character before 8 digits Date: Fri, 4 Dec 2026 18:57:19 +0900 Message-ID: <20261204100652.252595972@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 [ sashal: Applied the hunk unchanged to lib/bitmap.c because the bitmap string-parsing function has not yet been split out into lib/bitmap-str.c here. ] Signed-off-by: Sasha Levin --- lib/bitmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index ddb31015e38ae..d3184db294e68 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -880,8 +880,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