From nobody Mon Sep 29 22:44:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B82B9C00140 for ; Tue, 16 Aug 2022 00:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241640AbiHPAxN (ORCPT ); Mon, 15 Aug 2022 20:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345200AbiHPAoE (ORCPT ); Mon, 15 Aug 2022 20:44:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D5EAE21D; Mon, 15 Aug 2022 13:40:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E8E96122E; Mon, 15 Aug 2022 20:40:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72B45C433D6; Mon, 15 Aug 2022 20:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596024; bh=Pyw799UMOd9W9JvMkl0+1zzeas8WDF0EpdwV1mZOenI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5SlELF3J/OHBzuVestKGu/k1J5+E2dnx9fIrXU1D/zpsRfw4u8zUWrLyYOYQV17E aw9a1MKD4e0sdyTX/9qCBC4DFLuMqhQuP4figYtxg6RXI6RHLYHP3XRCFOjbOFUjY0 LbsYAy4Hj8cfXu8XsOjv4eaV1cpCAPqL1X1Pf+KM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Lobakin , Andy Shevchenko , Yury Norov , Sasha Levin Subject: [PATCH 5.19 0950/1157] lib/bitmap: fix off-by-one in bitmap_to_arr64() Date: Mon, 15 Aug 2022 20:05:06 +0200 Message-Id: <20220815180517.578237375@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alexander Lobakin [ Upstream commit 428bc098635680a664779f26f24fe9197d186172 ] GENMASK*() family takes the first and the last bits of the mask *including* them. So, with the current code bitmap_to_arr64() doesn't clear the tail properly: nbits % exp mask must be 1 GENMASK(1, 0) 0x3 0x1 ... 63 GENMASK(63, 0) 0xffffffffffffffff 0x7fffffffffffffff This was found by making the function always available instead of 32-bit BE systems only (for reusing in some new functionality). Turn the number of bits into the last bit set by subtracting 1. @nbits is already checked to be positive beforehand. Fixes: 0a97953fd221 ("lib: add bitmap_{from,to}_arr64") Signed-off-by: Alexander Lobakin Reviewed-by: Andy Shevchenko Signed-off-by: Yury Norov Signed-off-by: Sasha Levin --- lib/bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index b18e31ea6e66..e903e13c62e1 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -1564,7 +1564,7 @@ void bitmap_to_arr64(u64 *buf, const unsigned long *b= itmap, unsigned int nbits) =20 /* Clear tail bits in the last element of array beyond nbits. */ if (nbits % 64) - buf[-1] &=3D GENMASK_ULL(nbits % 64, 0); + buf[-1] &=3D GENMASK_ULL((nbits - 1) % 64, 0); } EXPORT_SYMBOL(bitmap_to_arr64); #endif --=20 2.35.1