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=1796387597; b=sFKp4XJmwfiNNtCsnFf/LFKNpGezHsWK5KGw8TOKxPSXS0GewaG13GEdMQbjXYDehAx1 dAc9Yr721WByeF4kuCj7SFXa13oWRRoA17uxoZ8zfJUw+NTTJT1Xz6ic0WVSAvW/F26uN fBkKqVntFSMlVvg0aQlCMG1uXVupErXbe17D6eqJL6JxJb3BdAB6UJbIMWLdVIlg5V9dc FvECbKnhYMB5gxjGiZmEk3Ph5+HJOPiGpotaGX7C7UQ4bvLhXizWdwqntckgCZLuSx249 edp0OVKXq0V3QwhMACgu1h4IdpAdCCvo9hAdr9V4LCFbi0yYRr6n6Hq9jncw+pRj2Vg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387597; 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=XBpDGqvy4fUM8ej5ZVLtZxYg3rR/FpmOj+dVkpH92zY=; b=JQMggfITKUK/BHKm3ro0KfhG8h/f9Fj1qSWlzNWrx8bCFXvByr/9qzATmyaaU8ik25pM X2DkFRQfqsHGqsSXbsvaRtHCRf+FJSus/5h2pbmr2JDMelK5Rl4vOBaBFwQkkfddtkqA1 jM4pKwGlJFU23kISDXFvvQ7sf7wp1Zf7EF40By0v+4HTgh32Ioew5e2WAAHrh9mpa3ocL W8lrZj1Nj+J8JKKVecUq5hyTjkiAE7TyJM2z9WX2dzn3CmOFhOvR/LCEc4l4vPP8Ru1E4 b5jtnYFGXumVn84SvXuijJJUYJuj4TjGRnQCJHOrS76OaqhgRIsIoVHyQGRlj7RgJwg== 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=HyiOEmi3; 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 C8B78606A322; Fri, 4 Dec 2026 12:33:17 +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=HyiOEmi3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 422E51F000CE; Fri, 4 Dec 2026 12:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387597; bh=XBpDGqvy4fUM8ej5ZVLtZxYg3rR/FpmOj+dVkpH92zY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HyiOEmi30yvHjTD6QzebkCv+h+QKPVzuY8x69d2FmhbJoL8J++nc0fE90KnDHo3f7 i2/i14hQejfTPYqCAv2MBRb/y5NuauorxlLwrH4+mWIRkI7F7xwIbhLHBQ0DFRZuA0 rY8F7Q8l18nCfOqY63qXkqR3Mxd5D0xLKrpR32sg= 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 0310/1059] bitmap: bitmap_parselist(): dont wrap around on a huge group size Date: Fri, 4 Dec 2026 18:57:21 +0900 Message-ID: <20261204100652.303468907@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 d075c4dc0b3c8ed91a4f67ebdf3384aa59fd4fbb ] In the "range:used/group" form bitmap_set_region() walks the range with for (start = r->start; start <= r->end; start += r->group_len) where all values are unsigned int. bitmap_getnum() accepts any group size up to UINT_MAX, and bitmap_check_region() only requires it to be non-zero and at least the used size. If start + group_len exceeds UINT_MAX, start wraps around to a small value that is still <= end, and bits below the start of the range get set: "1-1:1/4294967295" -> bits 0,1 (expected bit 1) "15-15:1/4294967281" -> bits 0,15 (expected bit 15) The loop still terminates, because start keeps decreasing until it wraps past zero again, but the resulting mask contains bits outside the requested range. This needs a group size within 'start' of UINT_MAX, so it is unlikely to be hit by accident; all bits set stay below the end of the range, so there is no out-of-bounds write. A group larger than the range simply means that the range contains a single group, so stop the walk when the next group would start beyond UINT_MAX. Fixes: 0a5ce0831d04 ("lib/bitmap.c: make bitmap_parselist() thread-safe and much faster") Assisted-by: LLM Signed-off-by: Shashank Mohan Jain Signed-off-by: Yury Norov [ sashal: Applied the change to lib/bitmap.c instead of lib/bitmap-str.c, which doesn't exist in this tree, and added #include there. ] Signed-off-by: Sasha Levin --- lib/bitmap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 9b41b17c96d32..96641893c9e1d 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -652,10 +653,12 @@ struct region { static void bitmap_set_region(const struct region *r, unsigned long *bitmap) { - unsigned int start; + unsigned int start = r->start; - for (start = r->start; start <= r->end; start += r->group_len) + do { bitmap_set(bitmap, start, min(r->end - start + 1, r->off)); + } while (!check_add_overflow(start, r->group_len, &start) && + start <= r->end); } static int bitmap_check_region(const struct region *r) -- 2.53.0