From: Kees Cook <keescook@chromium.org>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: "Darrick J . Wong" <djwong@kernel.org>,
patches@lists.linux.dev, netdev@vger.kernel.org,
"Andreas Dilger" <adilger.kernel@dilger.ca>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Richard Weinberger" <richard@nod.at>,
"Helge Deller" <deller@gmx.de>,
"Russell King" <linux@armlinux.org.uk>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Jakub Kicinski" <kuba@kernel.org>,
linux-mips@vger.kernel.org, linux-media@vger.kernel.org,
"Heiko Carstens" <hca@linux.ibm.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
linux-block@vger.kernel.org, "SeongJae Park" <sj@kernel.org>,
loongarch@lists.linux.dev, "Jaegeuk Kim" <jaegeuk@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
linux-arm-kernel@lists.infradead.org,
"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
"Theodore Ts'o" <tytso@mit.edu>,
linux-parisc@vger.kernel.org,
"Martin K . Petersen" <martin.petersen@oracle.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
"Chr istoph Böhmwalder" <christoph.boehmwalder@linbit.com>,
linux-crypto@vger.kernel.org,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
linux-fsdevel@vger.kernel.org,
"Andrew Morton" <akpm@linux-foundation.org>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v3 3/3] treewide: use get_random_u32_inclusive() when possible
Date: Thu, 17 Nov 2022 13:57:13 -0800 [thread overview]
Message-ID: <202211171349.F42BA5B0@keescook> (raw)
In-Reply-To: <20221117202906.2312482-4-Jason@zx2c4.com>
On Thu, Nov 17, 2022 at 09:29:06PM +0100, Jason A. Donenfeld wrote:
> These cases were done with this Coccinelle:
>
> @@
> expression H;
> expression L;
> @@
> - (get_random_u32_below(H) + L)
> + get_random_u32_inclusive(L, H + L - 1)
>
> @@
> expression H;
> expression L;
> expression E;
> @@
> get_random_u32_inclusive(L,
> H
> - + E
> - - E
> )
>
> @@
> expression H;
> expression L;
> expression E;
> @@
> get_random_u32_inclusive(L,
> H
> - - E
> - + E
> )
>
> @@
> expression H;
> expression L;
> expression E;
> expression F;
> @@
> get_random_u32_inclusive(L,
> H
> - - E
> + F
> - + E
> )
>
> @@
> expression H;
> expression L;
> expression E;
> expression F;
> @@
> get_random_u32_inclusive(L,
> H
> - + E
> + F
> - - E
> )
>
> And then subsequently cleaned up by hand, with several automatic cases
> rejected if it didn't make sense contextually.
>
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> # for infiniband
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> arch/x86/kernel/module.c | 2 +-
> crypto/rsa-pkcs1pad.c | 2 +-
> crypto/testmgr.c | 10 ++++----
> drivers/bus/mhi/host/internal.h | 2 +-
> drivers/dma-buf/st-dma-fence-chain.c | 2 +-
> drivers/infiniband/core/cma.c | 2 +-
> drivers/infiniband/hw/hns/hns_roce_ah.c | 5 ++--
> drivers/mtd/nand/raw/nandsim.c | 2 +-
> drivers/net/wireguard/selftest/allowedips.c | 8 +++---
> .../broadcom/brcm80211/brcmfmac/p2p.c | 2 +-
> .../net/wireless/intel/iwlwifi/mvm/mac-ctxt.c | 2 +-
> fs/f2fs/segment.c | 6 ++---
> kernel/kcsan/selftest.c | 2 +-
> lib/test_hexdump.c | 10 ++++----
> lib/test_printf.c | 2 +-
> lib/test_vmalloc.c | 6 ++---
> mm/kasan/kasan_test.c | 6 ++---
> mm/kfence/kfence_test.c | 2 +-
> mm/swapfile.c | 5 ++--
> net/bluetooth/mgmt.c | 5 ++--
> net/core/pktgen.c | 25 ++++++++-----------
> net/ipv4/tcp_input.c | 2 +-
> net/ipv6/addrconf.c | 6 ++---
> net/netfilter/nf_nat_helper.c | 2 +-
> net/xfrm/xfrm_state.c | 2 +-
> 25 files changed, 56 insertions(+), 64 deletions(-)
Even the diffstat agrees this is a nice clean-up. :)
Reviewed-by: Kees Cook <keescook@chromium.org>
The only comment I have is that maybe these cases can just be left as-is
with _below()?
> - size_t len = get_random_u32_below(rs) + gs;
> + size_t len = get_random_u32_inclusive(gs, rs + gs - 1);
It seems like writing it in the form of base plus [0, limit) is clearer?
size_t len = gs + get_random_u32_below(rs);
But there is only a handful, so *shrug*
All the others are much cleaner rewritten as _inclusive().
--
Kees Cook
next prev parent reply other threads:[~2022-11-17 21:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 16:45 [PATCH v2 0/3] convert tree to get_random_u32_{below,above,between}() Jason A. Donenfeld
2022-11-14 16:45 ` [PATCH v2 1/3] treewide: use get_random_u32_below() instead of deprecated function Jason A. Donenfeld
2022-11-14 17:35 ` Russell King (Oracle)
2022-11-14 16:45 ` [PATCH v2 2/3] treewide: use get_random_u32_{above,below}() instead of manual loop Jason A. Donenfeld
2022-11-14 16:45 ` [PATCH v2 3/3] treewide: use get_random_u32_between() when possible Jason A. Donenfeld
2022-11-16 22:43 ` Kees Cook
2022-11-16 23:55 ` Jason A. Donenfeld
2022-11-17 0:03 ` Jason A. Donenfeld
2022-11-17 0:31 ` Kees Cook
2022-11-17 0:43 ` Jason A. Donenfeld
2022-11-17 0:47 ` Kees Cook
2022-11-17 15:42 ` Theodore Ts'o
2022-11-17 16:19 ` Jason A. Donenfeld
2022-11-17 22:15 ` David Laight
2022-11-17 2:05 ` Jason A. Donenfeld
2022-11-17 10:32 ` Russell King (Oracle)
2022-11-17 20:29 ` [PATCH v3 0/3] convert tree to get_random_u32_{below,above,inclusive}() Jason A. Donenfeld
2022-11-17 20:29 ` [PATCH v3 1/3] treewide: use get_random_u32_below() instead of deprecated function Jason A. Donenfeld
2022-11-17 21:59 ` Kees Cook
2022-11-17 20:29 ` [PATCH v3 2/3] treewide: use get_random_u32_{above,below}() instead of manual loop Jason A. Donenfeld
2022-11-17 21:58 ` Kees Cook
2022-11-17 20:29 ` [PATCH v3 3/3] treewide: use get_random_u32_inclusive() when possible Jason A. Donenfeld
2022-11-17 21:57 ` Kees Cook [this message]
2022-11-17 22:10 ` Jason A. Donenfeld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202211171349.F42BA5B0@keescook \
--to=keescook@chromium.org \
--cc=Jason@zx2c4.com \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=christoph.boehmwalder@linbit.com \
--cc=deller@gmx.de \
--cc=djwong@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hca@linux.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=jaegeuk@kernel.org \
--cc=jani.nikula@linux.intel.com \
--cc=jgg@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=martin.petersen@oracle.com \
--cc=netdev@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=richard@nod.at \
--cc=sakari.ailus@linux.intel.com \
--cc=sj@kernel.org \
--cc=tglx@linutronix.de \
--cc=tsbogend@alpha.franken.de \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).