Skip to content

Commit 6d4952d

Browse files
amlutoherbertx
authored andcommitted
hwrng: core - Don't use a stack buffer in add_early_randomness()
hw_random carefully avoids using a stack buffer except in add_early_randomness(). This causes a crash in virtio_rng if CONFIG_VMAP_STACK=y. Reported-by: Matt Mullins <[email protected]> Tested-by: Matt Mullins <[email protected]> Fixes: d3cc799 ("hwrng: fetch randomness only after device init") Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 1001354 commit 6d4952d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/char/hw_random/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ static size_t rng_buffer_size(void)
8484

8585
static void add_early_randomness(struct hwrng *rng)
8686
{
87-
unsigned char bytes[16];
8887
int bytes_read;
88+
size_t size = min_t(size_t, 16, rng_buffer_size());
8989

9090
mutex_lock(&reading_mutex);
91-
bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1);
91+
bytes_read = rng_get_data(rng, rng_buffer, size, 1);
9292
mutex_unlock(&reading_mutex);
9393
if (bytes_read > 0)
94-
add_device_randomness(bytes, bytes_read);
94+
add_device_randomness(rng_buffer, bytes_read);
9595
}
9696

9797
static inline void cleanup_rng(struct kref *kref)

0 commit comments

Comments
 (0)