Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3122197rwb; Mon, 15 Aug 2022 18:40:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Q2ghHC4m50brFvNHrdk/7PKVSaJhUt5gK4JqLqfAWl15cifMM27JoJzUIh4/3OwR1zd1g X-Received: by 2002:a05:6402:5190:b0:43d:da02:566a with SMTP id q16-20020a056402519000b0043dda02566amr16791170edd.187.1660614013519; Mon, 15 Aug 2022 18:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660614013; cv=none; d=google.com; s=arc-20160816; b=G/el8O6dX6d6Ll5VfSTigFdZn1tRxP9sitOopiXpTbpPookgXxq+TrnI2Ymfegyu+B EyS1xyoHNF/tcoHCSMwBdhjxrNEn8DVBnfHcdQxlnqMEedxwLQbl3ogbyjKHth70crQF NZQw4wEuaj20yeqCl56se7CnhqLwaxBCXam0wzBi1WEfML/OzNFIIxb2fx2NoXyURPNg /bOuggcsWpv+oiv7ZapooQiL5kMD4onWujlIxmhBOJzE2BWYXtXyXmveS09Osjh/5M8b tJUDiu4zn1QMZ6tkpG/jUl2hAGF2EwDsjEPQ9a1gQNG5Nj7ab4DSY3pPaSMuhC5Gtr5l CKww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oewvERYz3/1jW7IRXWh4CydfSYxxZ2kJiDL7fDZzjZA=; b=TuTDzBpd+mxn4TAmI29Y6UfrAjzReh3Sd2nAZr3IurAMzDt2BYGddp4djVHP9fYWwA Xqjxr+GGysDkm8HYHHyjrpPj0sE68KODlejwpfoKAgIAuljXMpPkqQZrSrzCkOqxnZp5 i+tDHV96KWi/rU4j1Tb3dSfuUFIDkjZ/R7YwnV8d0z/00zr2bBiRxIFtaqj5KNjxO+kC l0Y4/dV+qrAbSIbgg+iwcex9q5IhhnPGOL3ygWz50WM3c73FZampFd7lMkjgE25Mdbaj 4OqWKuQTKrKoI8of1ris72DSlxs+nLuXqpcDkW+qQg3W9nynKKbpEALTbyHPprUYu2zg C4DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p5SlELF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j39-20020a05640223a700b00442fd542407si9527884eda.284.2022.08.15.18.39.48; Mon, 15 Aug 2022 18:40:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p5SlELF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240319AbiHPAxL (ORCPT + 99 others); Mon, 15 Aug 2022 20:53:11 -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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 *bitmap, unsigned int nbits) /* Clear tail bits in the last element of array beyond nbits. */ if (nbits % 64) - buf[-1] &= GENMASK_ULL(nbits % 64, 0); + buf[-1] &= GENMASK_ULL((nbits - 1) % 64, 0); } EXPORT_SYMBOL(bitmap_to_arr64); #endif -- 2.35.1