Skip to content

Commit dc39969

Browse files
zx2c4gregkh
authored andcommitted
random: always mix cycle counter in add_latent_entropy()
[ Upstream commit d7bf7f3 ] add_latent_entropy() is called every time a process forks, in kernel_clone(). This in turn calls add_device_randomness() using the latent entropy global state. add_device_randomness() does two things: 2) Mixes into the input pool the latent entropy argument passed; and 1) Mixes in a cycle counter, a sort of measurement of when the event took place, the high precision bits of which are presumably difficult to predict. (2) is impossible without CONFIG_GCC_PLUGIN_LATENT_ENTROPY=y. But (1) is always possible. However, currently CONFIG_GCC_PLUGIN_LATENT_ENTROPY=n disables both (1) and (2), instead of just (2). This commit causes the CONFIG_GCC_PLUGIN_LATENT_ENTROPY=n case to still do (1) by passing NULL (len 0) to add_device_randomness() when add_latent_ entropy() is called. Cc: Dominik Brodowski <[email protected]> Cc: PaX Team <[email protected]> Cc: Emese Revfy <[email protected]> Fixes: 38addce ("gcc-plugins: Add latent_entropy plugin") Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent eff0e02 commit dc39969

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/linux/random.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ void add_input_randomness(unsigned int type, unsigned int code,
1919
void add_interrupt_randomness(int irq) __latent_entropy;
2020
void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy);
2121

22-
#if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__)
2322
static inline void add_latent_entropy(void)
2423
{
24+
#if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__)
2525
add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
26-
}
2726
#else
28-
static inline void add_latent_entropy(void) { }
27+
add_device_randomness(NULL, 0);
2928
#endif
29+
}
3030

3131
void get_random_bytes(void *buf, size_t len);
3232
size_t __must_check get_random_bytes_arch(void *buf, size_t len);

0 commit comments

Comments
 (0)