Skip to content

Commit

Permalink
random: use a tighter cap in credit_entropy_bits_safe()
Browse files Browse the repository at this point in the history
commit 9f886f4d1d292442b2f22a0a33321eae821bde40 upstream.

This fixes a harmless UBSAN where root could potentially end up
causing an overflow while bumping the entropy_total field (which is
ignored once the entropy pool has been initialized, and this generally
is completed during the boot sequence).

This is marginal for the stable kernel series, but it's a really
trivial patch, and it fixes UBSAN warning that might cause security
folks to get overly excited for no reason.

Signed-off-by: Theodore Ts'o <[email protected]>
Reported-by: Chen Feng <[email protected]>
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
tytso authored and scafroglia93 committed Apr 24, 2018
1 parent 58c00c3 commit 9d030dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)

static void credit_entropy_bits_safe(struct entropy_store *r, int nbits)
{
const int nbits_max = (int)(~0U >> (ENTROPY_SHIFT + 1));
const int nbits_max = r->poolinfo->poolwords * 32;

/* Cap the value to avoid overflows */
nbits = min(nbits, nbits_max);
Expand Down

0 comments on commit 9d030dd

Please sign in to comment.