From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D18DAC433FE for ; Sat, 8 Oct 2022 09:57:26 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Ml0w51yJpz3drR for ; Sat, 8 Oct 2022 20:57:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=inria.fr header.i=@inria.fr header.a=rsa-sha256 header.s=dc header.b=j3ST7SGn; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=inria.fr (client-ip=192.134.164.83; helo=mail2-relais-roc.national.inria.fr; envelope-from=julia.lawall@inria.fr; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=inria.fr header.i=@inria.fr header.a=rsa-sha256 header.s=dc header.b=j3ST7SGn; dkim-atps=neutral X-Greylist: delayed 64 seconds by postgrey-1.36 at boromir; Sat, 08 Oct 2022 18:34:23 AEDT Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Mkxl30nmmz2xfV for ; Sat, 8 Oct 2022 18:34:22 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=zZQ88pPgtouR86lBpg+x1aw/csf1v9uxp8peXKk1cb0=; b=j3ST7SGnTYT/Y5wi6lWHZVyoTN6fTohW3n4oD0o9maLZmdhUccDAwXNB CrIK4oBY5dqegOsWJRE3rrwkzrofbuFPsdX2RZ0LPGmouitc76P+QhHmS HaFrH+aHq9cCtdo04t374NKt8+gA8QS7/hDJOozImMV5dxKm1CxmPsJ2W U=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="5.95,169,1661810400"; d="scan'208";a="56593050" Received: from 51.123.68.85.rev.sfr.net (HELO hadrien) ([85.68.123.51]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2022 09:33:09 +0200 Date: Sat, 8 Oct 2022 09:33:08 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Kees Cook Subject: Re: [PATCH v4 2/6] treewide: use prandom_u32_max() when possible In-Reply-To: <53DD0148-ED15-4294-8496-9E4B4C7AD061@chromium.org> Message-ID: References: <53DD0148-ED15-4294-8496-9E4B4C7AD061@chromium.org> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Mailman-Approved-At: Sat, 08 Oct 2022 20:56:33 +1100 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-wireless@vger.kernel.org, "Jason A. Donenfeld" , x86@kernel.org, Jan Kara , Vignesh Raghavendra , linux-doc@vger.kernel.org, Peter Zijlstra , Catalin Marinas , Dave Hansen , kernel-janitors@vger.kernel.org, KP Singh , dri-devel@lists.freedesktop.org, patches@lists.linux.dev, linux-mm@kvack.org, Eric Dumazet , netdev@vger.kernel.org, linux-mtd@lists.infradead.org, kasan-dev@googlegroups.com, "H. Peter Anvin" , Andreas Noever , WANG Xuerui , Will Deacon , Christoph Hellwig , linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, Mauro Carvalho Chehab , Herbert Xu , Daniel Borkmann , Jonathan Corbet , linux-rdma@vger.kernel.org, Helge Deller , Huacai Chen , Hugh Dickins , Russell King , Jozsef Kadlecsik , Jason Gunthorpe , Dave Airlie , Ulf Hansson , Paolo Abeni , "James E. J. Bottomley" , Pablo Neira Ayuso , linux-media@vger.kernel.org, Marco Elver , Yury Norov , Heiko Carstens , linux-um@lists.infradead.org, linux-mips@vger.kernel.org, linux-block@vger.kernel.org, Richard Weinberger , Borislav Petkov , linux-nvme@lists.infradead.org, loongarch@lists.linux.dev, Jakub Kicinski , Thomas Gleixner , Andy Shevchenko , Johannes Berg , linux-arm-kernel@lists.infradead.org, Jens Axboe , linux-mmc@vger.kernel.o rg, Thomas Bogendoerfer , Theodore Ts'o , linux-parisc@vger.kernel.org, Greg Kroah-Hartman , linux-usb@vger.kernel.org, Florian Westphal , linux-kernel@vger.kernel.org, =?ISO-8859-15?Q?Christoph_B=F6hmwalder?= , linux-crypto@vger.kernel.org, Jan Kara , Thomas Graf , linux-fsdevel@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" > >> @minus_one@ > >> expression FULL; > >> @@ > >> > >> - (get_random_int() & ((FULL) - 1) > >> + prandom_u32_max(FULL) > > > >Ahh, well, okay, this is the example I mentioned above. Only works if > >FULL is saturated. Any clever way to get coccinelle to prove that? Can > >it look at the value of constants? > > I'm not sure if Cocci will do that without a lot of work. The literals trick I used below would need a lot of fanciness. :) If FULL is an arbitrary expression, it would not be easy to automate. If it is a constant then you can use python/ocaml to analyze its value. But if it's a #define constant then you would need a previous rule to match the #define and find that value. For LITERAL, I think you could just do constant int LITERAL; for the metavariable declaration. julia