All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yann Droneaud" <ydroneaud@opteya.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	"Julia Lawall" <Julia.Lawall@inria.fr>,
	"Nicolas Palix" <nicolas.palix@imag.fr>,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 0/5] treewide cleanup of random integer usage
Date: Thu, 06 Oct 2022 08:17:18 +0000	[thread overview]
Message-ID: <125581881ad4aa85b2dadfe0d7338af9901caa03@opteya.com> (raw)
In-Reply-To: <20221005214844.2699-1-Jason@zx2c4.com>

Hi,

6 octobre 2022 à 04:51 "Jason A. Donenfeld" a écrit:

> 
> This is a five part treewide cleanup of random integer handling. The
> rules for random integers are:
> 
> - If you want a secure or an insecure random u64, use get_random_u64().
> - If you want a secure or an insecure random u32, use get_random_u32().
>  * The old function prandom_u32() has been deprecated for a while now
>  and is just a wrapper around get_random_u32().
> - If you want a secure or an insecure random u16, use get_random_u16().
> - If you want a secure or an insecure random u8, use get_random_u8().
> - If you want secure or insecure random bytes, use get_random_bytes().
>  * The old function prandom_bytes() has been deprecated for a while now
>  and has long been a wrapper around get_random_bytes().
> - If you want a non-uniform random u32, u16, or u8 bounded by a certain
>  open interval maximum, use prandom_u32_max().
>  * I say "non-uniform", because it doesn't do any rejection sampling or
>  divisions. Hence, it stays within the prandom_* namespace.
> 
> These rules ought to be applied uniformly, so that we can clean up the
> deprecated functions, and earn the benefits of using the modern
> functions. In particular, in addition to the boring substitutions, this
> patchset accomplishes a few nice effects:
> 
> - By using prandom_u32_max() with an upper-bound that the compiler can
>  prove at compile-time is ≤65536 or ≤256, internally get_random_u16()
>  or get_random_u8() is used, which wastes fewer batched random bytes,
>  and hence has higher throughput.
> 
> - By using prandom_u32_max() instead of %, when the upper-bound is not a
>  constant, division is still avoided, because prandom_u32_max() uses
>  a faster multiplication-based trick instead.
> 
> - By using get_random_u16() or get_random_u8() in cases where the return
>  value is intended to indeed be a u16 or a u8, we waste fewer batched
>  random bytes, and hence have higher throughput.
> 
> So, based on those rules and benefits from following them, this patchset
> breaks down into the following five steps:
> 
> 1) Replace `prandom_u32() % max` and variants thereof with
>  prandom_u32_max(max).
> 
> 2) Replace `(type)get_random_u32()` and variants thereof with
>  get_random_u16() or get_random_u8(). I took the pains to actually
>  look and see what every lvalue type was across the entire tree.
> 
> 3) Replace remaining deprecated uses of prandom_u32() with
>  get_random_u32(). 
> 
> 4) Replace remaining deprecated uses of prandom_bytes() with
>  get_random_bytes().
> 
> 5) Remove the deprecated and now-unused prandom_u32() and
>  prandom_bytes() inline wrapper functions.
> 

Did you use some coccinelle patches ? Or other semantic patch tool ?

Maybe we could introduce some coccinelle patch to ensure future get_random_u{16,32,64} usages be checked and patched to use the best fit.

Regards.

-- 
Yann Droneaud
OPTEYA

  parent reply	other threads:[~2022-10-06  8:55 UTC|newest]

Thread overview: 207+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 21:48 [f2fs-dev] [PATCH v1 0/5] treewide cleanup of random integer usage Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48 ` Jason A. Donenfeld via dev
2022-10-05 21:48 ` Jason A. Donenfeld
2022-10-05 21:48 ` Jason A. Donenfeld
2022-10-05 21:48 ` Jason A. Donenfeld
2022-10-05 21:48 ` Jason A. Donenfeld
2022-10-05 21:48 ` Jason A. Donenfeld
2022-10-05 21:48 ` [f2fs-dev] [PATCH v1 1/5] treewide: use prandom_u32_max() when possible Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-06  4:16   ` Kees Cook
2022-10-06  4:16     ` Kees Cook
2022-10-06  4:16     ` Kees Cook
2022-10-06  4:16     ` Kees Cook
2022-10-06  4:16     ` Kees Cook
2022-10-06  4:16     ` [f2fs-dev] " Kees Cook
2022-10-06  4:22     ` KP Singh
2022-10-06  4:22       ` KP Singh
2022-10-06  4:22       ` KP Singh
2022-10-06  4:22       ` KP Singh
2022-10-06  4:22       ` KP Singh
2022-10-06  4:22       ` KP Singh
2022-10-06 12:45     ` [f2fs-dev] " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:45       ` Jason A. Donenfeld via dev
2022-10-06 12:45       ` Jason A. Donenfeld
2022-10-06 12:45       ` Jason A. Donenfeld
2022-10-06 12:45       ` Jason A. Donenfeld
2022-10-06 12:45       ` Jason A. Donenfeld
2022-10-06 12:55       ` Jason Gunthorpe
2022-10-06 12:55         ` Jason Gunthorpe
2022-10-06 12:55         ` Jason Gunthorpe
2022-10-06 12:55         ` Jason Gunthorpe
2022-10-06 12:55         ` Jason Gunthorpe
2022-10-06 12:55         ` [f2fs-dev] " Jason Gunthorpe
2022-10-06 13:05         ` Andy Shevchenko
2022-10-06 13:05           ` Andy Shevchenko
2022-10-06 13:05           ` Andy Shevchenko
2022-10-06 13:05           ` Andy Shevchenko
2022-10-06 13:05           ` Andy Shevchenko
2022-10-06 13:05           ` Andy Shevchenko
2022-10-06  9:07   ` Christoph Böhmwalder
2022-10-05 21:48 ` [f2fs-dev] [PATCH v1 2/5] treewide: use get_random_{u8, u16}() " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld via dev
2022-10-05 21:48   ` [PATCH v1 2/5] treewide: use get_random_{u8,u16}() " Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-06  4:38   ` Kees Cook
2022-10-06  4:38     ` [PATCH v1 2/5] treewide: use get_random_{u8, u16}() " Kees Cook
2022-10-06  4:38     ` [PATCH v1 2/5] treewide: use get_random_{u8,u16}() " Kees Cook
2022-10-06  4:38     ` Kees Cook
2022-10-06  4:38     ` Kees Cook
2022-10-06  4:38     ` [f2fs-dev] [PATCH v1 2/5] treewide: use get_random_{u8, u16}() " Kees Cook
2022-10-06 12:28     ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:28       ` Jason A. Donenfeld via dev
2022-10-06 12:28       ` [PATCH v1 2/5] treewide: use get_random_{u8,u16}() " Jason A. Donenfeld
2022-10-06 12:28       ` Jason A. Donenfeld
2022-10-06 12:28       ` Jason A. Donenfeld
2022-10-06 12:28       ` Jason A. Donenfeld
2022-10-06 13:37   ` Toke Høiland-Jørgensen
2022-10-05 21:48 ` [f2fs-dev] [PATCH v1 3/5] treewide: use get_random_u32() " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-06  8:43   ` [f2fs-dev] " Jan Kara
2022-10-06  8:43     ` Jan Kara
2022-10-06  8:43     ` Jan Kara
2022-10-06  8:43     ` Jan Kara
2022-10-06  8:43     ` Jan Kara
2022-10-06  8:43     ` Jan Kara
2022-10-06 12:33     ` [f2fs-dev] " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:33       ` Jason A. Donenfeld via dev
2022-10-06 12:33       ` Jason A. Donenfeld
2022-10-06 12:33       ` Jason A. Donenfeld
2022-10-06 12:33       ` Jason A. Donenfeld
2022-10-06 12:33       ` Jason A. Donenfeld
2022-10-06 12:56       ` Andy Shevchenko
2022-10-06 13:01         ` Andy Shevchenko
2022-10-06 13:01         ` Andy Shevchenko
2022-10-06 13:01         ` Andy Shevchenko
2022-10-06 13:01         ` Andy Shevchenko
2022-10-06 13:01         ` Andy Shevchenko
2022-10-06 13:01         ` Andy Shevchenko
2022-10-06 13:07         ` Jason A. Donenfeld
2022-10-06 13:07           ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 13:07           ` [f2fs-dev] " Jason A. Donenfeld
2022-10-06 13:07           ` Jason A. Donenfeld
2022-10-06 13:07           ` Jason A. Donenfeld
2022-10-06 13:07           ` Jason A. Donenfeld
2022-10-06 13:07           ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:47   ` Jason Gunthorpe
2022-10-06 12:47     ` Jason Gunthorpe
2022-10-06 12:47     ` Jason Gunthorpe
2022-10-06 12:47     ` Jason Gunthorpe
2022-10-06 12:47     ` Jason Gunthorpe
2022-10-06 12:47     ` [f2fs-dev] " Jason Gunthorpe
2022-10-06 13:05     ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 13:05       ` Jason A. Donenfeld via dev
2022-10-06 13:05       ` Jason A. Donenfeld
2022-10-06 13:05       ` Jason A. Donenfeld
2022-10-06 13:05       ` Jason A. Donenfeld
2022-10-06 13:05       ` Jason A. Donenfeld
2022-10-06 13:15       ` Jason Gunthorpe
2022-10-06 13:15         ` Jason Gunthorpe
2022-10-06 13:15         ` Jason Gunthorpe
2022-10-06 13:15         ` Jason Gunthorpe
2022-10-06 13:15         ` Jason Gunthorpe
2022-10-06 13:15         ` Jason Gunthorpe
2022-10-06 13:15         ` [f2fs-dev] " Jason Gunthorpe
2022-10-06 13:20       ` Andy Shevchenko
2022-10-06 13:20         ` Andy Shevchenko
2022-10-06 13:20         ` Andy Shevchenko
2022-10-06 13:20         ` Andy Shevchenko
2022-10-06 13:20         ` Andy Shevchenko
2022-10-06 13:20         ` Andy Shevchenko
2022-10-06 13:20         ` Andy Shevchenko
2022-10-06 13:20         ` [f2fs-dev] " Andy Shevchenko
2022-10-06 13:38   ` Toke Høiland-Jørgensen
     [not found]   ` <20221005214844.2699-4-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-12 19:16     ` Joe Perches
2022-10-12 19:16   ` Joe Perches
2022-10-12 19:16   ` Joe Perches
2022-10-12 19:16     ` Joe Perches
2022-10-12 19:16     ` Joe Perches
2022-10-12 19:16     ` [f2fs-dev] " Joe Perches
2022-10-12 19:16     ` Joe Perches
2022-10-12 19:16     ` Joe Perches
2022-10-12 19:16     ` Joe Perches
2022-10-12 21:29     ` David Laight
2022-10-12 21:29       ` David Laight
2022-10-12 21:29       ` David Laight
2022-10-12 21:29       ` David Laight
2022-10-12 21:29       ` [f2fs-dev] " David Laight
2022-10-12 21:29       ` David Laight
2022-10-12 21:29       ` David Laight
2022-10-12 21:29       ` David Laight
2022-10-13  1:37       ` Joe Perches
2022-10-13  1:37         ` Joe Perches
2022-10-13  1:37         ` Joe Perches
2022-10-13  1:37         ` Joe Perches
2022-10-13  1:37         ` Joe Perches
2022-10-13  1:37         ` Joe Perches
2022-10-13  1:37         ` Joe Perches
2022-10-13  1:37         ` [f2fs-dev] " Joe Perches
2022-10-05 21:48 ` [f2fs-dev] [PATCH v1 4/5] treewide: use get_random_bytes " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-06  4:45   ` [f2fs-dev] " Kees Cook
2022-10-06  4:45     ` Kees Cook
2022-10-06  4:45     ` Kees Cook
2022-10-06  4:45     ` Kees Cook
2022-10-06  4:45     ` Kees Cook
2022-10-06  4:45     ` Kees Cook
2022-10-06  4:48   ` Kees Cook
2022-10-06  4:48     ` Kees Cook
2022-10-06  4:48     ` Kees Cook
2022-10-06  4:48     ` Kees Cook
2022-10-06  4:48     ` Kees Cook
2022-10-06  4:48     ` [f2fs-dev] " Kees Cook
2022-10-05 21:48 ` [f2fs-dev] [PATCH v1 5/5] prandom: remove unused functions Jason A. Donenfeld via Linux-f2fs-devel
2022-10-05 21:48   ` Jason A. Donenfeld via dev
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-05 21:48   ` Jason A. Donenfeld
2022-10-06  4:39   ` [f2fs-dev] " Kees Cook
2022-10-06  4:39     ` Kees Cook
2022-10-06  4:39     ` Kees Cook
2022-10-06  4:39     ` Kees Cook
2022-10-06  4:39     ` Kees Cook
2022-10-06  4:39     ` Kees Cook
2022-10-06  4:55 ` [PATCH v1 0/5] treewide cleanup of random integer usage Kees Cook
2022-10-06  4:55   ` Kees Cook
2022-10-06  4:55   ` Kees Cook
2022-10-06  4:55   ` Kees Cook
2022-10-06  4:55   ` Kees Cook
2022-10-06  4:55   ` [f2fs-dev] " Kees Cook
2022-10-06  5:40   ` Kees Cook
2022-10-06  5:40     ` Kees Cook
2022-10-06  5:40     ` Kees Cook
2022-10-06  5:40     ` Kees Cook
2022-10-06  5:40     ` Kees Cook
2022-10-06  5:40     ` Kees Cook
2022-10-06 12:53   ` [f2fs-dev] " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:53     ` Jason A. Donenfeld via dev
2022-10-06 12:53     ` Jason A. Donenfeld
2022-10-06 12:53     ` Jason A. Donenfeld
2022-10-06 12:53     ` Jason A. Donenfeld
2022-10-06 12:53     ` Jason A. Donenfeld
2022-10-06  6:15 ` Kees Cook
2022-10-06 12:58   ` Jason A. Donenfeld
2022-10-06  8:17 ` Yann Droneaud [this message]
2022-10-06 13:49 ` [f2fs-dev] " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 13:49   ` Jason A. Donenfeld
2022-10-06 13:49   ` 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=125581881ad4aa85b2dadfe0d7338af9901caa03@opteya.com \
    --to=ydroneaud@opteya.com \
    --cc=Jason@zx2c4.com \
    --cc=Julia.Lawall@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.palix@imag.fr \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.