Skip to content

Commit 2cc7515

Browse files
smuellerDDherbertx
authored andcommitted
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 <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent d7db7a8 commit 2cc7515

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/char/hw_random/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static void add_early_randomness(struct hwrng *rng)
9292
mutex_unlock(&reading_mutex);
9393
if (bytes_read > 0)
9494
add_device_randomness(rng_buffer, bytes_read);
95+
memset(rng_buffer, 0, size);
9596
}
9697

9798
static inline void cleanup_rng(struct kref *kref)
@@ -287,6 +288,7 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
287288
}
288289
}
289290
out:
291+
memset(rng_buffer, 0, rng_buffer_size());
290292
return ret ? : err;
291293

292294
out_unlock_reading:
@@ -425,6 +427,7 @@ static int hwrng_fillfn(void *unused)
425427
/* Outside lock, sure, but y'know: randomness. */
426428
add_hwgenerator_randomness((void *)rng_fillbuf, rc,
427429
rc * current_quality * 8 >> 10);
430+
memset(rng_fillbuf, 0, rng_buffer_size());
428431
}
429432
hwrng_fill = NULL;
430433
return 0;

0 commit comments

Comments
 (0)