1. 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
  2. 15 7月, 2014 10 次提交
  3. 10 7月, 2014 1 次提交
  4. 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
  5. 07 6月, 2014 1 次提交
  6. 28 5月, 2014 2 次提交
    • D
      applicom: dereferencing NULL on error path · 8bab797c
      Dan Carpenter 提交于
      This is a static checker fix.  The "dev" variable is always NULL after
      the while statement so we would be dereferencing a NULL pointer here.
      
      Fixes: 819a3eba ('[PATCH] applicom: fix error handling')
      Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8bab797c
    • L
      ACPI: Clean up acpi_os_map/unmap_memory() to eliminate __iomem. · a238317c
      Lv Zheng 提交于
      ACPICA doesn't include protections around address space checking, Linux
      build tests always complain increased sparse warnings around ACPICA
      internal acpi_os_map/unmap_memory() invocations.  This patch tries to fix
      this issue permanently.
      
      There are 2 choices left for us to solve this issue:
       1. Add __iomem address space awareness into ACPICA.
       2. Remove sparse checker of __iomem from ACPICA source code.
      
      This patch chooses solution 2, because:
       1.  Most of the acpi_os_map/unmap_memory() invocations are used for ACPICA.
           table mappings, which in fact are not IO addresses.
       2.  The only IO addresses usage is for "system memory space" mapping code in:
            drivers/acpi/acpica/exregion.c
            drivers/acpi/acpica/evrgnini.c
            drivers/acpi/acpica/exregion.c
          The mapped address is accessed in the handler of "system memory space"
          - acpi_ex_system_memory_space_handler().  This function in fact can be
          changed to invoke acpi_os_read/write_memory() so that __iomem can
          always be type-casted in the OSL layer.
      
      According to the above investigation, we drew the following conclusion:
      It is not a good idea to introduce __iomem address space awareness into
      ACPICA mostly in order to protect non-IO addresses.
      
      We can simply remove __iomem for acpi_os_map/unmap_memory() to remove
      __iomem checker for ACPICA code. Then we need to enforce external usages
      to invoke other APIs that are aware of __iomem address space.
      The external usages are:
       drivers/acpi/apei/einj.c
       drivers/acpi/acpi_extlog.c
       drivers/char/tpm/tpm_acpi.c
       drivers/acpi/nvs.c
      
      This patch thus performs cleanups in this way:
       1. Add acpi_os_map/unmap_iomem() to be invoked by non-ACPICA code.
       2. Remove __iomem from acpi_os_map/unmap_memory().
      Signed-off-by: NLv Zheng <lv.zheng@intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      a238317c
  7. 19 5月, 2014 2 次提交
  8. 17 5月, 2014 1 次提交
  9. 14 5月, 2014 1 次提交
    • A
      virtio-rng: support multiple virtio-rng devices · 08e53fbd
      Amos Kong 提交于
      Current hwrng core supports to register multiple hwrng devices,
      and there is only one device really works in the same time.
      QEMU alsu supports to have multiple virtio-rng backends.
      
      This patch changes virtio-rng driver to support multiple
      virtio-rng devices.
      
      ]# cat /sys/class/misc/hw_random/rng_available
      virtio_rng.0 virtio_rng.1
      ]# cat /sys/class/misc/hw_random/rng_current
      virtio_rng.0
      ]# echo -n virtio_rng.1 > /sys/class/misc/hw_random/rng_current
      ]# dd if=/dev/hwrng of=/dev/null
      Signed-off-by: NAmos Kong <akong@redhat.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      08e53fbd
  10. 13 5月, 2014 1 次提交
    • H
      hwrng: n2-drv - Introduce the use of the managed version of kzalloc · 0118a552
      Himangi Saraogi 提交于
      This patch moves data allocated using kzalloc to managed data allocated
      using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
      functions. The NULL assignment to np->units is removed as there is no
      interaction between this field and sun4v_hvapi_unregister. Also, the
      labels out_free_units and out_free are removed as they are no longer
      required.
      
      The following Coccinelle semantic patch was used for making the change:
      
      @platform@
      identifier p, probefn, removefn;
      @@
      struct platform_driver p = {
        .probe = probefn,
        .remove = removefn,
      };
      
      @prb@
      identifier platform.probefn, pdev;
      expression e, e1, e2;
      @@
      probefn(struct platform_device *pdev, ...) {
        <+...
      - e = kzalloc(e1, e2)
      + e = devm_kzalloc(&pdev->dev, e1, e2)
        ...
      ?-kfree(e);
        ...+>
      }
      
      @rem depends on prb@
      identifier platform.removefn;
      expression e;
      @@
      removefn(...) {
        <...
      - kfree(e);
        ...>
      }
      Signed-off-by: NHimangi Saraogi <himangi774@gmail.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      0118a552
  11. 12 5月, 2014 1 次提交
    • R
      ACPI / TPM: Fix resume regression on Chromebooks · f7595464
      Rafael J. Wysocki 提交于
      Chromebooks (at least Acer C720 and Pixel) implement an ACPI object
      for TPM, but don't implement the _DSM method to support PPI.  As
      a result, the TPM driver fails to load on those machines after
      commit 1569a4c4 (ACPI / TPM: detect PPI features by checking
      availability of _DSM functions) which causes them to fail to
      resume from system suspend, becuase they require the TPM hardware
      to be put into the right state during resume and the TPM driver
      is necessary for that.
      
      Fix the problem by making tpm_add_ppi() return 0 when tpm_ppi_handle
      is still NULL after walking the ACPI namespace in search for the PPI
      _DSM, which allows the TPM driver to load and operate the hardware
      (during system resume in particular), but avoid creating the PPI
      sysfs group in that case.
      
      This change is based on a prototype patch from Jiang Liu.
      
      Fixes: 1569a4c4 (ACPI / TPM: detect PPI features by checking availability of _DSM functions)
      References: https://bugzilla.kernel.org/show_bug.cgi?id=74021Reported-by: NJames Duley <jagduley@gmail.com>
      Reported-by: NPhillip Dixon <phil@dixon.gen.nz>
      Tested-by: NBrandon Casey <drafnel@gmail.com>
      Cc: 3.14+ <stable@vger.kernel.org> # 3.14+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      f7595464
  12. 08 5月, 2014 2 次提交
  13. 07 5月, 2014 3 次提交
  14. 05 5月, 2014 1 次提交
  15. 28 4月, 2014 1 次提交
  16. 18 4月, 2014 7 次提交
  17. 17 4月, 2014 3 次提交