1. 17 Oct, 2014 2 commits
    • Daniel Borkmann's avatar
      crypto: memzero_explicit - make sure to clear out sensitive data · 7185ad26
      Daniel Borkmann authored
      Recently, in commit 13aa93c70e71 ("random: add and use memzero_explicit()
      for clearing data"), we have found that GCC may optimize some memset()
      cases away when it detects a stack variable is not being used anymore
      and going out of scope. This can happen, for example, in cases when we
      are clearing out sensitive information such as keying material or any
      e.g. intermediate results from crypto computations, etc.
      
      With the help of Coccinelle, we can figure out and fix such occurences
      in the crypto subsytem as well. Julia Lawall provided the following
      Coccinelle program:
      
        @@
        type T;
        identifier x;
        @@
      
        T x;
        ... when exists
            when any
        -memset
        +memzero_explicit
           (&x,
        -0,
           ...)
        ... when != x
            when strict
      
        @@
        type T;
        identifier x;
        @@
      
        T x[...];
        ... when exists
            when any
        -memset
        +memzero_explicit
           (x,
        -0,
           ...)
        ... when != x
            when strict
      
      Therefore, make use of the drop-in replacement memzero_explicit() for
      exactly such cases instead of using memset().
      Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
      Cc: Julia Lawall <julia.lawall@lip6.fr>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: Theodore Ts'o <tytso@mit.edu>
      Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
      Acked-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
      Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      7185ad26
    • Daniel Borkmann's avatar
      random: add and use memzero_explicit() for clearing data · d4c5efdb
      Daniel Borkmann authored
      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: default avatarDaniel Borkmann <dborkman@redhat.com>
      Acked-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Cc: stable@vger.kernel.org
      d4c5efdb
  2. 16 Aug, 2014 38 commits