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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 1F161C433F5 for ; Thu, 6 Oct 2022 12:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kGAcEwD26mmK+QhZ+m9etRmY/2LJvmttqgcSDbJH+LM=; b=VJVMFT/6ytT61v agkB5K+q5T1HmPnfuMemHBITXDsS6o2L8G1X819VTyiZ/BO2D+UR5OBoYPGlT1fLi/394XPP0oqW6 jPp1FQiDbLs02Uc3ILfSmHlxRXL6gyhjTpI3Swak53E2RN3v3yqPfVdSc4200cXXIXLPX/sHUIDXr GZ1O/vtEmdPAROdYLbIumuxSlfGaInQF7KYf4wcgCYzV7LVb1fQSu8cgodm2Lvuusf2TCW6d0JZUd 7K0zi+Tqnm+QKPldzADBENPg4vazFjtr+ztj1gB8+GdvyUPcv52JVAffEwoGqKckx6IqBMk4HQQ02 uEY4c1FwgbSHQsObjRtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogQGJ-002PXH-96; Thu, 06 Oct 2022 12:46:03 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogQGE-002PUT-28; Thu, 06 Oct 2022 12:46:01 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 6F88CB8206F; Thu, 6 Oct 2022 12:45:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BBD6C433B5; Thu, 6 Oct 2022 12:45:39 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="gqKJ5uKA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1665060337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8dWFI8h4OMBAtrqSOGO78rNNmSB/3Qreg0w0Og/94qc=; b=gqKJ5uKA335nUt4dHqz8iF9PLBDcDgx3n0YhiOxMrlk3oPDvs/7yiBJIDKV/E4nv62pdqe sPWU3H5aG76qM2evnoA3/Ys8c2HrO6GXFQDfmwl/KqnyJgMuSbwIQZf5GAnNUvK/lVQDpw cqr/cVirflho361qsz5SQunwSlNAMYo= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c546cd47 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 6 Oct 2022 12:45:37 +0000 (UTC) Date: Thu, 6 Oct 2022 06:45:25 -0600 From: "Jason A. Donenfeld" To: Kees Cook Cc: linux-kernel@vger.kernel.org, Ajay Singh , Akinobu Mita , Alexandre Torgue , Amitkumar Karwar , Andreas Dilger , Andreas =?utf-8?Q?F=C3=A4rber?= , Andreas Noever , Andrew Lunn , Andrew Morton , Andrii Nakryiko , Andy Gospodarek , Andy Lutomirski , Andy Shevchenko , Anil S Keshavamurthy , Anna Schumaker , Arend van Spriel , Ayush Sawal , Borislav Petkov , Chao Yu , Christoph =?utf-8?Q?B=C3=B6hmwalder?= , Christoph Hellwig , Christophe Leroy , Chuck Lever , Claudiu Beznea , Cong Wang , Dan Williams , Daniel Borkmann , "Darrick J . Wong" , Dave Hansen , David Ahern , "David S . Miller" , Dennis Dalessandro , Dick Kennedy , Dmitry Vyukov , Eric Dumazet , Florian Westphal , Franky Lin , Ganapathi Bhat , Greg Kroah-Hartman , Gregory Greenman , "H . Peter Anvin" , Hannes Reinecke , Hans Verkuil , Hante Meuleman , Hao Luo , Haoyue Xu , Heiner Kallweit , Helge Deller , Herbert Xu , Hideaki YOSHIFUJI , Hugh Dickins , Igor Mitsyanko , Ilya Dryomov , Ingo Molnar , Jack Wang , Jaegeuk Kim , Jaehoon Chung , Jakub Kicinski , Jamal Hadi Salim , "James E . J . Bottomley" , James Smart , Jan Kara , Jason Gunthorpe , Jay Vosburgh , Jean-Paul Roubelat , Jeff Layton , Jens Axboe , Jiri Olsa , Jiri Pirko , Johannes Berg , John Fastabend , John Stultz , Jon Maloy , Jonathan Corbet , Jozsef Kadlecsik , Julian Anastasov , KP Singh , Kalle Valo , Keith Busch , Lars Ellenberg , Leon Romanovsky , Manish Rangankar , Manivannan Sadhasivam , Marcelo Ricardo Leitner , Marco Elver , "Martin K . Petersen" , Martin KaFai Lau , Masami Hiramatsu , Mauro Carvalho Chehab , Maxime Coquelin , "Md . Haris Iqbal" , Michael Chan , Michael Ellerman , Michael Jamet , Michal Januszewski , Mika Westerberg , Miquel Raynal , Namjae Jeon , "Naveen N . Rao" , Neil Horman , Nicholas Piggin , Nilesh Javali , OGAWA Hirofumi , Pablo Neira Ayuso , Paolo Abeni , Peter Zijlstra , Philipp Reisner , Potnuri Bharat Teja , Pravin B Shelar , Rasmus Villemoes , Richard Weinberger , Rohit Maheshwari , Russell King , Sagi Grimberg , Santosh Shilimkar , Sergey Matyukevich , Sharvari Harisangam , Simon Horman , Song Liu , Stanislav Fomichev , Steffen Klassert , Stephen Boyd , Stephen Hemminger , Sungjong Seo , Theodore Ts'o , Thomas Gleixner , Thomas Graf , Thomas Sailer , Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= , Trond Myklebust , Ulf Hansson , Varun Prakash , Veaceslav Falico , Vignesh Raghavendra , Vinay Kumar Yadav , Vinod Koul , Vlad Yasevich , Wenpeng Liang , Xinming Hu , Xiubo Li , Yehezkel Bernat , Ying Xue , Yishai Hadas , Yonghong Song , Yury Norov , brcm80211-dev-list.pdl@broadcom.com, cake@lists.bufferbloat.net, ceph-devel@vger.kernel.org, coreteam@netfilter.org, dccp@vger.kernel.org, dev@openvswitch.org, dmaengine@vger.kernel.org, drbd-dev@lists.linbit.com, dri-devel@lists.freedesktop.org, kasan-dev@googlegroups.com, linux-actions@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-block@vger.kernel.org, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fbdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hams@vger.kernel.org, linux-media@vger.kernel.org, linux-mm@kvack.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-nfs@vger.kernel.org, linux-nvme@lists.infradead.org, linux-raid@vger.kernel.org, linux-rdma@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sctp@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, linux-xfs@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, lvs-devel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, rds-devel@oss.oracle.com, SHA-cyfmac-dev-list@infineon.com, target-devel@vger.kernel.org, tipc-discussion@lists.sourceforge.net Subject: Re: [PATCH v1 1/5] treewide: use prandom_u32_max() when possible Message-ID: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-2-Jason@zx2c4.com> <202210052035.A1020E3@keescook> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202210052035.A1020E3@keescook> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221006_054558_399383_B410C18E X-CRM114-Status: GOOD ( 25.39 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org Hi Kees, On Wed, Oct 05, 2022 at 09:16:50PM -0700, Kees Cook wrote: > On Wed, Oct 05, 2022 at 11:48:40PM +0200, Jason A. Donenfeld wrote: > > Rather than incurring a division or requesting too many random bytes for > > the given range, use the prandom_u32_max() function, which only takes > > the minimum required bytes from the RNG and avoids divisions. > > Yes please! > > Since this is a treewide patch, it's helpful for (me at least) doing > reviews to detail the mechanism of the transformation. This is hand done. There were also various wrong seds done. And then I'd edit the .diff manually, and then reapply it, as an iterative process. No internet on the airplane, and oddly no spatch already on my laptop (I think I had some Gentoo ocaml issues at some point and removed it?). > e.g. I imagine this could be done with something like Coccinelle and Feel free to check the work here by using Coccinelle if you're into that. > > static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) > > { > > if (ubi->dbg.emulate_bitflips) > > - return !(prandom_u32() % 200); > > + return !(prandom_u32_max(200)); > > return 0; > > } > > > > Because some looks automated (why the parens?) I saw this before going out and thought I'd fixed it but I guess I sent the wrong one. Jason ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/