Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: lib/sha256 - Use memzero_explicit() for clearing state

Without the barrier_data() inside memzero_explicit(), the compiler may
optimize away the state-clearing if it can tell that the state is not
used afterwards. At least in lib/crypto/sha256.c:__sha256_final(), the
function can get inlined into sha256(), in which case the memset is
optimized away.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Arvind Sankar and committed by
Herbert Xu
1762818f 383e8a82

+1 -1
+1 -1
lib/crypto/sha256.c
··· 265 265 put_unaligned_be32(sctx->state[i], &dst[i]); 266 266 267 267 /* Zeroize sensitive information. */ 268 - memset(sctx, 0, sizeof(*sctx)); 268 + memzero_explicit(sctx, sizeof(*sctx)); 269 269 } 270 270 271 271 void sha256_final(struct sha256_state *sctx, u8 *out)