]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Jul 2017 19:44:02 +0000 (12:44 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Jul 2017 19:44:02 +0000 (12:44 -0700)
Pull random updates from Ted Ts'o:
 "Add wait_for_random_bytes() and get_random_*_wait() functions so that
  callers can more safely get random bytes if they can block until the
  CRNG is initialized.

  Also print a warning if get_random_*() is called before the CRNG is
  initialized. By default, only one single-line warning will be printed
  per boot. If CONFIG_WARN_ALL_UNSEEDED_RANDOM is defined, then a
  warning will be printed for each function which tries to get random
  bytes before the CRNG is initialized. This can get spammy for certain
  architecture types, so it is not enabled by default"

* tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
  random: reorder READ_ONCE() in get_random_uXX
  random: suppress spammy warnings about unseeded randomness
  random: warn when kernel uses unseeded randomness
  net/route: use get_random_int for random counter
  net/neighbor: use get_random_u32 for 32-bit hash random
  rhashtable: use get_random_u32 for hash_rnd
  ceph: ensure RNG is seeded before using
  iscsi: ensure RNG is seeded before use
  cifs: use get_random_u32 for 32-bit lock random
  random: add get_random_{bytes,u32,u64,int,long,once}_wait family
  random: add wait_for_random_bytes() API

1  2 
drivers/char/random.c
drivers/target/iscsi/iscsi_target_login.c
fs/cifs/cifsfs.c
include/linux/random.h
lib/Kconfig.debug
lib/rhashtable.c
net/ceph/ceph_common.c
net/core/neighbour.c
net/ipv4/route.c

Simple merge
Simple merge
index 1fa0dc880bd7878e70200264e2486a579dfe1332,4aecc339558d5ea1a30e73b8e9889b0cee34f961..eafea6a09361f8787bad4aa22d906dc17177d03f
@@@ -57,27 -58,31 +58,52 @@@ static inline unsigned long get_random_
  #endif
  }
  
 +/*
 + * On 64-bit architectures, protect against non-terminated C string overflows
 + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
 + */
 +#ifdef CONFIG_64BIT
 +# ifdef __LITTLE_ENDIAN
 +#  define CANARY_MASK 0xffffffffffffff00UL
 +# else /* big endian, 64 bits: */
 +#  define CANARY_MASK 0x00ffffffffffffffUL
 +# endif
 +#else /* 32 bits: */
 +# define CANARY_MASK 0xffffffffUL
 +#endif
 +
 +static inline unsigned long get_random_canary(void)
 +{
 +      unsigned long val = get_random_long();
 +
 +      return val & CANARY_MASK;
 +}
 +
+ /* Calls wait_for_random_bytes() and then calls get_random_bytes(buf, nbytes).
+  * Returns the result of the call to wait_for_random_bytes. */
+ static inline int get_random_bytes_wait(void *buf, int nbytes)
+ {
+       int ret = wait_for_random_bytes();
+       if (unlikely(ret))
+               return ret;
+       get_random_bytes(buf, nbytes);
+       return 0;
+ }
+ #define declare_get_random_var_wait(var) \
+       static inline int get_random_ ## var ## _wait(var *out) { \
+               int ret = wait_for_random_bytes(); \
+               if (unlikely(ret)) \
+                       return ret; \
+               *out = get_random_ ## var(); \
+               return 0; \
+       }
+ declare_get_random_var_wait(u32)
+ declare_get_random_var_wait(u64)
+ declare_get_random_var_wait(int)
+ declare_get_random_var_wait(long)
+ #undef declare_get_random_var
  unsigned long randomize_page(unsigned long start, unsigned long range);
  
  u32 prandom_u32(void);
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge