1. 17 10月, 2014 1 次提交
    • D
      random: add and use memzero_explicit() for clearing data · d4c5efdb
      Daniel Borkmann 提交于
      zatimend has reported that in his environment (3.16/gcc4.8.3/corei7)
      memset() calls which clear out sensitive data in extract_{buf,entropy,
      entropy_user}() in random driver are being optimized away by gcc.
      
      Add a helper memzero_explicit() (similarly as explicit_bzero() variants)
      that can be used in such cases where a variable with sensitive data is
      being cleared out in the end. Other use cases might also be in crypto
      code. [ I have put this into lib/string.c though, as it's always built-in
      and doesn't need any dependencies then. ]
      
      Fixes kernel bugzilla: 82041
      
      Reported-by: zatimend@hotmail.co.uk
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Acked-by: NHannes Frederic Sowa <hannes@stressinduktion.org>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      Cc: stable@vger.kernel.org
      d4c5efdb
  2. 06 8月, 2014 2 次提交
    • T
      random: limit the contribution of the hw rng to at most half · 48d6be95
      Theodore Ts'o 提交于
      For people who don't trust a hardware RNG which can not be audited,
      the changes to add support for RDSEED can be troubling since 97% or
      more of the entropy will be contributed from the in-CPU hardware RNG.
      
      We now have a in-kernel khwrngd, so for those people who do want to
      implicitly trust the CPU-based system, we could create an arch-rng
      hw_random driver, and allow khwrng refill the entropy pool.  This
      allows system administrator whether or not they trust the CPU (I
      assume the NSA will trust RDRAND/RDSEED implicitly :-), and if so,
      what level of entropy derating they want to use.
      
      The reason why this is a really good idea is that if different people
      use different levels of entropy derating, it will make it much more
      difficult to design a backdoor'ed hwrng that can be generally
      exploited in terms of the output of /dev/random when different attack
      targets are using differing levels of entropy derating.
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      48d6be95
    • T
      random: introduce getrandom(2) system call · c6e9d6f3
      Theodore Ts'o 提交于
      The getrandom(2) system call was requested by the LibreSSL Portable
      developers.  It is analoguous to the getentropy(2) system call in
      OpenBSD.
      
      The rationale of this system call is to provide resiliance against
      file descriptor exhaustion attacks, where the attacker consumes all
      available file descriptors, forcing the use of the fallback code where
      /dev/[u]random is not available.  Since the fallback code is often not
      well-tested, it is better to eliminate this potential failure mode
      entirely.
      
      The other feature provided by this new system call is the ability to
      request randomness from the /dev/urandom entropy pool, but to block
      until at least 128 bits of entropy has been accumulated in the
      /dev/urandom entropy pool.  Historically, the emphasis in the
      /dev/urandom development has been to ensure that urandom pool is
      initialized as quickly as possible after system boot, and preferably
      before the init scripts start execution.
      
      This is because changing /dev/urandom reads to block represents an
      interface change that could potentially break userspace which is not
      acceptable.  In practice, on most x86 desktop and server systems, in
      general the entropy pool can be initialized before it is needed (and
      in modern kernels, we will printk a warning message if not).  However,
      on an embedded system, this may not be the case.  And so with this new
      interface, we can provide the functionality of blocking until the
      urandom pool has been initialized.  Any userspace program which uses
      this new functionality must take care to assure that if it is used
      during the boot process, that it will not cause the init scripts or
      other portions of the system startup to hang indefinitely.
      
      SYNOPSIS
      	#include <linux/random.h>
      
      	int getrandom(void *buf, size_t buflen, unsigned int flags);
      
      DESCRIPTION
      	The system call getrandom() fills the buffer pointed to by buf
      	with up to buflen random bytes which can be used to seed user
      	space random number generators (i.e., DRBG's) or for other
      	cryptographic uses.  It should not be used for Monte Carlo
      	simulations or other programs/algorithms which are doing
      	probabilistic sampling.
      
      	If the GRND_RANDOM flags bit is set, then draw from the
      	/dev/random pool instead of the /dev/urandom pool.  The
      	/dev/random pool is limited based on the entropy that can be
      	obtained from environmental noise, so if there is insufficient
      	entropy, the requested number of bytes may not be returned.
      	If there is no entropy available at all, getrandom(2) will
      	either block, or return an error with errno set to EAGAIN if
      	the GRND_NONBLOCK bit is set in flags.
      
      	If the GRND_RANDOM bit is not set, then the /dev/urandom pool
      	will be used.  Unlike using read(2) to fetch data from
      	/dev/urandom, if the urandom pool has not been sufficiently
      	initialized, getrandom(2) will block (or return -1 with the
      	errno set to EAGAIN if the GRND_NONBLOCK bit is set in flags).
      
      	The getentropy(2) system call in OpenBSD can be emulated using
      	the following function:
      
                  int getentropy(void *buf, size_t buflen)
                  {
                          int     ret;
      
                          if (buflen > 256)
                                  goto failure;
                          ret = getrandom(buf, buflen, 0);
                          if (ret < 0)
                                  return ret;
                          if (ret == buflen)
                                  return 0;
                  failure:
                          errno = EIO;
                          return -1;
                  }
      
      RETURN VALUE
             On success, the number of bytes that was filled in the buf is
             returned.  This may not be all the bytes requested by the
             caller via buflen if insufficient entropy was present in the
             /dev/random pool, or if the system call was interrupted by a
             signal.
      
             On error, -1 is returned, and errno is set appropriately.
      
      ERRORS
      	EINVAL		An invalid flag was passed to getrandom(2)
      
      	EFAULT		buf is outside the accessible address space.
      
      	EAGAIN		The requested entropy was not available, and
      			getentropy(2) would have blocked if the
      			GRND_NONBLOCK flag was not set.
      
      	EINTR		While blocked waiting for entropy, the call was
      			interrupted by a signal handler; see the description
      			of how interrupted read(2) calls on "slow" devices
      			are handled with and without the SA_RESTART flag
      			in the signal(7) man page.
      
      NOTES
      	For small requests (buflen <= 256) getrandom(2) will not
      	return EINTR when reading from the urandom pool once the
      	entropy pool has been initialized, and it will return all of
      	the bytes that have been requested.  This is the recommended
      	way to use getrandom(2), and is designed for compatibility
      	with OpenBSD's getentropy() system call.
      
      	However, if you are using GRND_RANDOM, then getrandom(2) may
      	block until the entropy accounting determines that sufficient
      	environmental noise has been gathered such that getrandom(2)
      	will be operating as a NRBG instead of a DRBG for those people
      	who are working in the NIST SP 800-90 regime.  Since it may
      	block for a long time, these guarantees do *not* apply.  The
      	user may want to interrupt a hanging process using a signal,
      	so blocking until all of the requested bytes are returned
      	would be unfriendly.
      
      	For this reason, the user of getrandom(2) MUST always check
      	the return value, in case it returns some error, or if fewer
      	bytes than requested was returned.  In the case of
      	!GRND_RANDOM and small request, the latter should never
      	happen, but the careful userspace code (and all crypto code
      	should be careful) should check for this anyway!
      
      	Finally, unless you are doing long-term key generation (and
      	perhaps not even then), you probably shouldn't be using
      	GRND_RANDOM.  The cryptographic algorithms used for
      	/dev/urandom are quite conservative, and so should be
      	sufficient for all purposes.  The disadvantage of GRND_RANDOM
      	is that it can block, and the increased complexity required to
      	deal with partially fulfilled getrandom(2) requests.
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      Reviewed-by: NZach Brown <zab@zabbo.net>
      c6e9d6f3
  3. 19 7月, 2014 1 次提交
  4. 15 7月, 2014 7 次提交
  5. 16 6月, 2014 1 次提交
    • T
      random: fix nasty entropy accounting bug · e33ba5fa
      Theodore Ts'o 提交于
      Commit 0fb7a01a "random: simplify accounting code", introduced in
      v3.15, has a very nasty accounting problem when the entropy pool has
      has fewer bytes of entropy than the number of requested reserved
      bytes.  In that case, "have_bytes - reserved" goes negative, and since
      size_t is unsigned, the expression:
      
             ibytes = min_t(size_t, ibytes, have_bytes - reserved);
      
      ... does not do the right thing.  This is rather bad, because it
      defeats the catastrophic reseeding feature in the
      xfer_secondary_pool() path.
      
      It also can cause the "BUG: spinlock trylock failure on UP" for some
      kernel configurations when prandom_reseed() calls get_random_bytes()
      in the early init, since when the entropy count gets corrupted,
      credit_entropy_bits() erroneously believes that the nonblocking pool
      has been fully initialized (when in fact it is not), and so it calls
      prandom_reseed(true) recursively leading to the spinlock BUG.
      
      The logic is *not* the same it was originally, but in the cases where
      it matters, the behavior is the same, and the resulting code is
      hopefully easier to read and understand.
      
      Fixes: 0fb7a01a "random: simplify accounting code"
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      Cc: Greg Price <price@mit.edu>
      Cc: stable@vger.kernel.org  #v3.15
      e33ba5fa
  6. 07 6月, 2014 1 次提交
  7. 17 5月, 2014 1 次提交
  8. 28 4月, 2014 1 次提交
  9. 20 3月, 2014 15 次提交
  10. 12 11月, 2013 1 次提交
  11. 04 11月, 2013 5 次提交
  12. 11 10月, 2013 4 次提交
    • T
      random: convert DEBUG_ENT to tracepoints · f80bbd8b
      Theodore Ts'o 提交于
      Instead of using the random driver's ad-hoc DEBUG_ENT() mechanism, use
      tracepoints instead.  This allows for a much more fine-grained control
      of which debugging mechanism which a developer might need, and unifies
      the debugging messages with all of the existing tracepoints.
      Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
      f80bbd8b
    • T
      random: push extra entropy to the output pools · 6265e169
      Theodore Ts'o 提交于
      As the input pool gets filled, start transfering entropy to the output
      pools until they get filled.  This allows us to use the output pools
      to store more system entropy.  Waste not, want not....
      Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
      6265e169
    • T
      random: drop trickle mode · 95b709b6
      Theodore Ts'o 提交于
      The add_timer_randomness() used to drop into trickle mode when entropy
      pool was estimated to be 87.5% full.  This was important when
      add_timer_randomness() was used to sample interrupts.  It's not used
      for this any more --- add_interrupt_randomness() now uses fast_mix()
      instead.  By elimitating trickle mode, it allows us to fully utilize
      entropy provided by add_input_randomness() and add_disk_randomness()
      even when the input pool is above the old trickle threshold of 87.5%.
      
      This helps to answer the criticism in [1] in their hypothetical
      scenario where our entropy estimator was inaccurate, even though the
      measurements in [2] seem to indicate that our entropy estimator given
      real-life entropy collection is actually pretty good, albeit on the
      conservative side (which was as it was designed).
      
      [1] http://eprint.iacr.org/2013/338.pdf
      [2] http://eprint.iacr.org/2012/251.pdfSigned-off-by: N"Theodore Ts'o" <tytso@mit.edu>
      95b709b6
    • T
      random: adjust the generator polynomials in the mixing function slightly · 6e9fa2c8
      Theodore Ts'o 提交于
      Our mixing functions were analyzed by Lacharme, Roeck, Strubel, and
      Videau in their paper, "The Linux Pseudorandom Number Generator
      Revisited" (see: http://eprint.iacr.org/2012/251.pdf).
      
      They suggested a slight change to improve our mixing functions
      slightly.  I also adjusted the comments to better explain what is
      going on, and to document why the polynomials were changed.
      Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
      6e9fa2c8