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. 15 8月, 2014 1 次提交
  3. 06 8月, 2014 3 次提交
    • S
      hwrng: Pass entropy to add_hwgenerator_randomness() in bits, not bytes · e02b8765
      Stephen Boyd 提交于
      rng_get_data() returns the number of bytes read from the hardware.
      The entropy argument to add_hwgenerator_randomness() is passed
      directly to credit_entropy_bits() so we should be passing the
      number of bits, not bytes here.
      
      Fixes: be4000bc "hwrng: create filler thread"
      Acked-by: NTorsten Duwe <duwe@suse.de>
      Signed-off-by: NStephen Boyd <sboyd@codeaurora.org>
      Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
      e02b8765
    • 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
  4. 02 8月, 2014 1 次提交
  5. 30 7月, 2014 5 次提交
  6. 27 7月, 2014 5 次提交
  7. 24 7月, 2014 1 次提交
  8. 19 7月, 2014 1 次提交
  9. 18 7月, 2014 1 次提交
  10. 15 7月, 2014 10 次提交
  11. 14 7月, 2014 2 次提交
    • A
      hwrng: virtio - ensure reads happen after successful probe · e052dbf5
      Amit Shah 提交于
      The hwrng core asks for random data in the hwrng_register() call itself
      from commit d9e79726.  This doesn't play well with virtio -- the
      DRIVER_OK bit is only set by virtio core on a successful probe, and
      we're not yet out of our probe routine when this call is made.  This
      causes the host to not acknowledge any requests we put in the virtqueue,
      and the insmod or kernel boot process just waits for data to arrive from
      the host, which never happens.
      
      CC: Kees Cook <keescook@chromium.org>
      CC: Jason Cooper <jason@lakedaemon.net>
      CC: Herbert Xu <herbert@gondor.apana.org.au>
      CC: <stable@vger.kernel.org> # For v3.15+
      Reviewed-by: NJason Cooper <jason@lakedaemon.net>
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      e052dbf5
    • A
      hwrng: fetch randomness only after device init · d3cc7996
      Amit Shah 提交于
      Commit d9e79726 "hwrng: add randomness to system from rng sources"
      added a call to rng_get_data() from the hwrng_register() function.
      However, some rng devices need initialization before data can be read
      from them.
      
      This commit makes the call to rng_get_data() depend on no init fn
      pointer being registered by the device.  If an init function is
      registered, this call is made after device init.
      
      CC: Kees Cook <keescook@chromium.org>
      CC: Jason Cooper <jason@lakedaemon.net>
      CC: Herbert Xu <herbert@gondor.apana.org.au>
      CC: <stable@vger.kernel.org> # For v3.15+
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Reviewed-by: NJason Cooper <jason@lakedaemon.net>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d3cc7996
  12. 11 7月, 2014 2 次提交
    • P
      char: synclink: Remove WARN_ON for bad port count · 69fee688
      Peter Hurley 提交于
      tty_port_close_start() already validates the port counts and issues
      a diagnostic if validation fails.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69fee688
    • P
      tty: Remove tty_hung_up_p() tests from tty drivers' open() · e359a4e3
      Peter Hurley 提交于
      Since at least before 2.6.30, it has not been possible to observe
      a hung up file pointer in a tty driver's open() method unless/until
      the driver open() releases the tty_lock() (eg., before blocking).
      
      This is because tty_open() adds the file pointer while holding
      the tty_lock() _and_ doesn't release the lock until after calling
      the tty driver's open() method. [ Before tty_lock(), this was
      lock_kernel(). ]
      
      Since __tty_hangup() first waits on the tty_lock() before
      enumerating and hanging up the open file pointers, either
      __tty_hangup() will wait for the tty_lock() or tty_open() will
      not yet have added the file pointer. For example,
      
      CPU 0                          |  CPU 1
                                     |
      tty_open                       |  __tty_hangup
        ..                           |    ..
        tty_lock                     |    ..
        tty_reopen                   |    tty_lock  / blocks
        ..                           |
        tty_add_file(tty, filp)      |
        ..                           |
        tty->ops->open(tty, filp)    |
          tty_port_open              |
            tty_port_block_til_ready |
              ..                     |
              while (1)              |
                ..                   |
                tty_unlock           |    / unblocks
                schedule             |    for each filp on tty->tty_files
                                     |      f_ops = tty_hung_up_fops;
                                     |    ..
                                     |    tty_unlock
                tty_lock             |
        ..                           |
        tty_unlock                   |
      
      Note that since tty_port_block_til_ready() and similar drop
      the tty_lock while blocking, when woken, the file pointer
      must then be tested for having been hung up.
      
      Also, fix bit-rotted drivers that used extra_count to track the
      port->count bump.
      
      CC: Mikael Starvik <starvik@axis.com>
      CC: Samuel Ortiz <samuel@sortiz.org>
      CC: "David S. Miller" <davem@davemloft.net>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Acked-by: NJesper Nilsson <jesper.nilsson@axis.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e359a4e3
  13. 10 7月, 2014 6 次提交
  14. 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