[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y3WW2lOgoYLKQeve@zx2c4.com>
Date: Thu, 17 Nov 2022 03:05:14 +0100
From: "Jason A. Donenfeld" <Jason@...c4.com>
To: Kees Cook <keescook@...omium.org>
Cc: linux-kernel@...r.kernel.org, patches@...ts.linux.dev,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jakub Kicinski <kuba@...nel.org>,
Russell King <linux@...linux.org.uk>,
Catalin Marinas <catalin.marinas@....com>,
Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
Heiko Carstens <hca@...ux.ibm.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
Christoph Böhmwalder
<christoph.boehmwalder@...bit.com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Jason Gunthorpe <jgg@...dia.com>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
"Martin K . Petersen" <martin.petersen@...cle.com>,
Theodore Ts'o <tytso@....edu>,
Andreas Dilger <adilger.kernel@...ger.ca>,
Jaegeuk Kim <jaegeuk@...nel.org>,
Richard Weinberger <richard@....at>,
"Darrick J . Wong" <djwong@...nel.org>,
SeongJae Park <sj@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Michael Ellerman <mpe@...erman.id.au>,
Helge Deller <deller@....de>, netdev@...r.kernel.org,
linux-crypto@...r.kernel.org, linux-block@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-media@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, loongarch@...ts.linux.dev,
linux-mips@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-mmc@...r.kernel.org, linux-parisc@...r.kernel.org,
ydroneaud@...eya.com
Subject: Re: [PATCH v2 3/3] treewide: use get_random_u32_between() when
possible
On Thu, Nov 17, 2022 at 12:55:47AM +0100, Jason A. Donenfeld wrote:
> 1) How/whether to make f(0, UR2_MAX) safe,
> - without additional 64-bit arithmetic,
> - minimizing the number of branches.
> I have a few ideas I'll code golf for a bit.
> I think I can make progress with (1) alone by fiddling around with
> godbolt enough, like usual.
The code gen is definitely worse.
Original half-open interval:
return floor + get_random_u32_below(ceil - floor);
Suggested fully closed interval:
ceil = ceil - floor + 1;
return likely(ceil) ? floor + get_random_u32_below(ceil) : get_random_u32();
Is the worse code gen actually worth it? Options:
a) Decide worse codegen is worth it.
b) Declare f(0, U32_MAX) undefined and just not handle it.
c) Stick with original half-open interval that doesn't have this problem.
Jason
Powered by blists - more mailing lists