Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 12 Feb 2018 16:57:21 +0000 (08:57 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 12 Feb 2018 16:57:21 +0000 (08:57 -0800)
Pull crypto fixes from Herbert Xu:
 "This fixes the following issues:

   - oversize stack frames on mn10300 in sha3-generic

   - warning on old compilers in sha3-generic

   - API error in sun4i_ss_prng

   - potential dead-lock in sun4i_ss_prng

   - null-pointer dereference in sha512-mb

   - endless loop when DECO acquire fails in caam

   - kernel oops when hashing empty message in talitos"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
  crypto: sun4i_ss_prng - convert lock to _bh in sun4i_ss_prng_generate
  crypto: sun4i_ss_prng - fix return value of sun4i_ss_prng_generate
  crypto: caam - fix endless loop when DECO acquire fails
  crypto: sha3-generic - Use __optimize to support old compilers
  compiler-gcc.h: __nostackprotector needs gcc-4.4 and up
  compiler-gcc.h: Introduce __optimize function attribute
  crypto: sha3-generic - deal with oversize stack frames
  crypto: talitos - fix Kernel Oops on hashing an empty file
  crypto: sha512-mb - initialize pending lengths correctly

1  2 
include/linux/compiler-gcc.h
include/linux/compiler.h

index 631354acfa7204757a4ec29e74581dc2ee723a13,bf09213895f7a90559eb53161e99b6c959541401..73bc63e0a1c4b664f233f176c7694fa8e54e34aa
  
  #if GCC_VERSION >= 40100
  # define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
- #define __nostackprotector    __attribute__((__optimize__("no-stack-protector")))
  #endif
  
  #if GCC_VERSION >= 40300
  #endif /* __CHECKER__ */
  #endif /* GCC_VERSION >= 40300 */
  
+ #if GCC_VERSION >= 40400
+ #define __optimize(level)     __attribute__((__optimize__(level)))
+ #define __nostackprotector    __optimize("no-stack-protector")
+ #endif /* GCC_VERSION >= 40400 */
  #if GCC_VERSION >= 40500
  
  #ifndef __CHECKER__
  /* Mark a function definition as prohibited from being cloned. */
  #define __noclone     __attribute__((__noclone__, __optimize__("no-tracer")))
  
 -#ifdef RANDSTRUCT_PLUGIN
 +#if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__)
  #define __randomize_layout __attribute__((randomize_layout))
  #define __no_randomize_layout __attribute__((no_randomize_layout))
  #endif
diff --combined include/linux/compiler.h
index c2cc57a2f508f46dd815d79a9626119436486e51,cdc629f20e20253ec2c0b088f8e9fd131459221d..e835fc0423eccf7f66cca38c9dcbfa4f6d065ce3
@@@ -185,21 -185,23 +185,21 @@@ void __read_once_size(const volatile vo
  
  #ifdef CONFIG_KASAN
  /*
 - * This function is not 'inline' because __no_sanitize_address confilcts
 + * We can't declare function 'inline' because __no_sanitize_address confilcts
   * with inlining. Attempt to inline it may cause a build failure.
   *    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
   * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
   */
 -static __no_sanitize_address __maybe_unused
 -void __read_once_size_nocheck(const volatile void *p, void *res, int size)
 -{
 -      __READ_ONCE_SIZE;
 -}
 +# define __no_kasan_or_inline __no_sanitize_address __maybe_unused
  #else
 -static __always_inline
 +# define __no_kasan_or_inline __always_inline
 +#endif
 +
 +static __no_kasan_or_inline
  void __read_once_size_nocheck(const volatile void *p, void *res, int size)
  {
        __READ_ONCE_SIZE;
  }
 -#endif
  
  static __always_inline void __write_once_size(volatile void *p, void *res, int size)
  {
  /*
   * Prevent the compiler from merging or refetching reads or writes. The
   * compiler is also forbidden from reordering successive instances of
 - * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
 - * compiler is aware of some particular ordering.  One way to make the
 - * compiler aware of ordering is to put the two invocations of READ_ONCE,
 - * WRITE_ONCE or ACCESS_ONCE() in different C statements.
 + * READ_ONCE and WRITE_ONCE, but only when the compiler is aware of some
 + * particular ordering. One way to make the compiler aware of ordering is to
 + * put the two invocations of READ_ONCE or WRITE_ONCE in different C
 + * statements.
   *
 - * In contrast to ACCESS_ONCE these two macros will also work on aggregate
 - * data types like structs or unions. If the size of the accessed data
 - * type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
 - * READ_ONCE() and WRITE_ONCE() will fall back to memcpy(). There's at
 - * least two memcpy()s: one for the __builtin_memcpy() and then one for
 - * the macro doing the copy of variable - '__u' allocated on the stack.
 + * These two macros will also work on aggregate data types like structs or
 + * unions. If the size of the accessed data type exceeds the word size of
 + * the machine (e.g., 32 bits or 64 bits) READ_ONCE() and WRITE_ONCE() will
 + * fall back to memcpy(). There's at least two memcpy()s: one for the
 + * __builtin_memcpy() and then one for the macro doing the copy of variable
 + * - '__u' allocated on the stack.
   *
   * Their two major use cases are: (1) Mediating communication between
   * process-level code and irq/NMI handlers, all running on the same CPU,
 - * and (2) Ensuring that the compiler does not  fold, spindle, or otherwise
 + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise
   * mutilate accesses that either do not require ordering or that interact
   * with an explicit memory barrier or atomic instruction that provides the
   * required ordering.
   */
  #include <asm/barrier.h>
 +#include <linux/kasan-checks.h>
  
  #define __READ_ONCE(x, check)                                         \
  ({                                                                    \
   */
  #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
  
 +static __no_kasan_or_inline
 +unsigned long read_word_at_a_time(const void *addr)
 +{
 +      kasan_check_read(addr, 1);
 +      return *(unsigned long *)addr;
 +}
 +
  #define WRITE_ONCE(x, val) \
  ({                                                    \
        union { typeof(x) __val; char __c[1]; } __u =   \
  
  #endif /* __ASSEMBLY__ */
  
+ #ifndef __optimize
+ # define __optimize(level)
+ #endif
  /* Compile time object size, -1 for unknown */
  #ifndef __compiletime_object_size
  # define __compiletime_object_size(obj) -1
        compiletime_assert(__native_word(t),                            \
                "Need native word sized stores/loads for atomicity.")
  
 -/*
 - * Prevent the compiler from merging or refetching accesses.  The compiler
 - * is also forbidden from reordering successive instances of ACCESS_ONCE(),
 - * but only when the compiler is aware of some particular ordering.  One way
 - * to make the compiler aware of ordering is to put the two invocations of
 - * ACCESS_ONCE() in different C statements.
 - *
 - * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE
 - * on a union member will work as long as the size of the member matches the
 - * size of the union and the size is smaller than word size.
 - *
 - * The major use cases of ACCESS_ONCE used to be (1) Mediating communication
 - * between process-level code and irq/NMI handlers, all running on the same CPU,
 - * and (2) Ensuring that the compiler does not  fold, spindle, or otherwise
 - * mutilate accesses that either do not require ordering or that interact
 - * with an explicit memory barrier or atomic instruction that provides the
 - * required ordering.
 - *
 - * If possible use READ_ONCE()/WRITE_ONCE() instead.
 - */
 -#define __ACCESS_ONCE(x) ({ \
 -       __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
 -      (volatile typeof(x) *)&(x); })
 -#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
 -
  #endif /* __LINUX_COMPILER_H */