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

hwrng: core - zeroize buffers with random data

The HWRNG core allocates two buffers during initialization which are
used to obtain random data. After that data is processed, it is now
zeroized as it is possible that the HWRNG core will not be asked to
produce more random data for a long time. This prevents leaving such
sensitive data in memory.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Stephan Mueller and committed by
Herbert Xu
2cc75154 d7db7a88

+3
+3
drivers/char/hw_random/core.c
··· 92 92 mutex_unlock(&reading_mutex); 93 93 if (bytes_read > 0) 94 94 add_device_randomness(rng_buffer, bytes_read); 95 + memset(rng_buffer, 0, size); 95 96 } 96 97 97 98 static inline void cleanup_rng(struct kref *kref) ··· 288 287 } 289 288 } 290 289 out: 290 + memset(rng_buffer, 0, rng_buffer_size()); 291 291 return ret ? : err; 292 292 293 293 out_unlock_reading: ··· 427 425 /* Outside lock, sure, but y'know: randomness. */ 428 426 add_hwgenerator_randomness((void *)rng_fillbuf, rc, 429 427 rc * current_quality * 8 >> 10); 428 + memset(rng_fillbuf, 0, rng_buffer_size()); 430 429 } 431 430 hwrng_fill = NULL; 432 431 return 0;