From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 060F123EAB2; Wed, 11 Mar 2026 01:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773191912; cv=none; b=aQyI+uQ1IdWoIvXgh6k13glNR2Ard7EsPppG7cwZzgb3Vs7f++VaPdjPqQy4NtUgwQ/ip5Lfps9JNkgyj2T8P4QR54VU3WYCWpKXs0o1iiesiOfk7ysdTo3l9++6z75erhJsBNidzcbrjuZM7JGNzarQwKJFiQ+bC1+eyQHAeCA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773191912; c=relaxed/simple; bh=3MN5J7gHtT0iB6q2hgPDZbQjxnI7iGXFyfIUNXZZ6RE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YyZKuo+wkwTW6d73zxGVR/PpmvWswd9InpeZA95HQ0juxOYReiUBP6S2XFdAqMHc6F5s8bVnX1DMFyVjmjMmrlc72Xme/2seTRUp3kiRmGB1xGW+G1uUIF2llCWbYVJYDbaBjR5n9EVHMBnO8w7fSIXARY5Xj0UCu/KskDRiiIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rNElMcZ/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rNElMcZ/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F8A1C2BC87; Wed, 11 Mar 2026 01:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773191911; bh=3MN5J7gHtT0iB6q2hgPDZbQjxnI7iGXFyfIUNXZZ6RE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rNElMcZ/oiqPMT/syzmk66cskejh79Cstrn6kGqi34MlnfQgHH3oXRf/b6pp8t3cr eQZBKlG0YUGoy6qvmNbm9VSkZGe89hTvf9S3KYoOuY87OOonsgjldShGI0h9JswIlT kIOBDzzz/9diVIPAtmu4HqB2KW3ucNm2B01I2HzMecC5r//hLXyMPoEUZgtUpWOt2j KXJZwBeOS1svS+9hOO3uappOtHNYbprQqULxT4smEtsN26/95gWugNwpPQ2af8mWew HQDisRYaMYMTxu22UqX8vhhY8Jz4kxSYTeCzDitiCkuKPat1c3I4xcTuhQyrmL0xyi Kp8gn9th2s7Mg== Date: Tue, 10 Mar 2026 18:18:28 -0700 From: Eric Biggers To: Petr Pavlu Cc: Thomas =?iso-8859-1?Q?Wei=DFschuh?= , Nathan Chancellor , Arnd Bergmann , Luis Chamberlain , Sami Tolvanen , Daniel Gomez , Paul Moore , James Morris , "Serge E. Hallyn" , Jonathan Corbet , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , Nicolas Schier , Daniel Gomez , Aaron Tomlin , "Christophe Leroy (CS GROUP)" , Nicolas Schier , Nicolas Bouchinet , Xiu Jianfeng , Fabian =?iso-8859-1?Q?Gr=FCnbichler?= , Arnout Engelen , Mattia Rizzolo , kpcyrd , Christian Heusel , =?iso-8859-1?Q?C=E2ju?= Mihai-Drosi , Sebastian Andrzej Siewior , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-modules@vger.kernel.org, linux-security-module@vger.kernel.org, linux-doc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-integrity@vger.kernel.org Subject: Re: [PATCH v4 15/17] module: Introduce hash-based integrity checking Message-ID: <20260311011828.GB212983@quark> References: <20260113-module-hashes-v4-0-0b932db9b56b@weissschuh.net> <20260113-module-hashes-v4-15-0b932db9b56b@weissschuh.net> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Feb 03, 2026 at 01:19:20PM +0100, Petr Pavlu wrote: > > +static unsigned int get_pow2(unsigned int val) > > +{ > > + return 31 - __builtin_clz(val); > > +} > > + > > +static unsigned int roundup_pow2(unsigned int val) > > +{ > > + return 1 << (get_pow2(val - 1) + 1); > > +} > > + > > +static unsigned int log2_roundup(unsigned int val) > > +{ > > + return get_pow2(roundup_pow2(val)); > > +} > > In the edge case when the kernel is built with only one module, the code > calls log2_roundup(1) -> roundup_pow2(1) -> get_pow2(0) -> > __builtin_clz(0). The return value of __builtin_clz() is undefined if > the input is zero. A suggestion: static unsigned int log2_roundup(unsigned int val) { if (val <= 1) return 0; return 32 - __builtin_clz(val - 1); } - Eric