Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1660059

Re: [PATCH v3 03/13] random: invalidate batched entropy after crng init

From "Jason A. Donenfeld" <Jason@zx2c4.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3 03/13] random: invalidate batched entropy after crng init
Date 2017-06-07 20:20 +0200
Message-ID <tPNIJ-1Ge-7@gated-at.bofh.it> (permalink)
References <tPb0M-1BU-91@gated-at.bofh.it> <tPNfH-1eJ-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Strange, not all compilers do this warning. Fixing with:

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 12758db..5252690 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2061,8 +2061,8 @@ static DEFINE_PER_CPU(struct batched_entropy,
batched_entropy_u64);
u64 get_random_u64(void)
{
       u64 ret;
-       bool use_lock = crng_init < 2;
-       unsigned long flags;
+       const bool use_lock = READ_ONCE(crng_init) < 2;
+       unsigned long flags = 0;
       struct batched_entropy *batch;

#if BITS_PER_LONG == 64
@@ -2099,8 +2099,8 @@ static DEFINE_PER_CPU(struct batched_entropy,
batched_entropy_u32);
u32 get_random_u32(void)
{
       u32 ret;
-       bool use_lock = crng_init < 2;
-       unsigned long flags;
+       const bool use_lock = READ_ONCE(crng_init) < 2;
+       unsigned long flags = 0;
       struct batched_entropy *batch;

       if (arch_get_random_int(&ret))

Const, because it's more correct. READ_ONCE to be certain that the
compiler doesn't try to paste the expression into both uses. And
finally flags=0 to shutup the compiler.

If anybody has a better way of approaching this, feel free to chime in.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/13] Unseeded In-Kernel Randomness Fixes "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
  [PATCH v3 10/13] net/neighbor: use get_random_u32 for 32-bit hash random "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
  [PATCH v3 03/13] random: invalidate batched entropy after crng init "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
    Re: [PATCH v3 03/13] random: invalidate batched entropy after crng  init kbuild test robot <lkp@intel.com> - 2017-06-07 19:50 +0200
      Re: [PATCH v3 03/13] random: invalidate batched entropy after crng init "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-07 20:20 +0200
  [PATCH v3 09/13] rhashtable: use get_random_u32 for hash_rnd "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
  [PATCH v3 05/13] security/keys: ensure RNG is seeded before use "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
    Re: [PATCH v3 05/13] security/keys: ensure RNG is seeded before use David Howells <dhowells@redhat.com> - 2017-06-06 12:10 +0200
      Re: [PATCH v3 05/13] security/keys: ensure RNG is seeded before use "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 14:30 +0200
  [PATCH v3 01/13] random: add synchronous API for the urandom pool "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
  [PATCH v3 11/13] net/route: use get_random_int for random counter "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
  [PATCH v3 07/13] ceph: ensure RNG is seeded before using "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
  [PATCH v3 02/13] random: add get_random_{bytes,u32,u64,int,long,once}_wait family "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 03:00 +0200
    Re: [PATCH v3 02/13] random: add get_random_{bytes,u32,u64,int,long,once}_wait  family Jeffrey Walton <noloader@gmail.com> - 2017-06-06 07:20 +0200
      Re: [PATCH v3 02/13] random: add get_random_{bytes,u32,u64,int,long,once}_wait  family "Jason A. Donenfeld" <Jason@zx2c4.com> - 2017-06-06 14:30 +0200

csiph-web