From: Theodore Ts'o Date: Sat, 25 Feb 2017 22:21:33 +0000 (-0400) Subject: random: use a tighter cap in credit_entropy_bits_safe() X-Git-Tag: v4.1.52~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0783df1065bdc483ababf31e35338cac0e9b789a;p=thirdparty%2Fkernel%2Fstable.git random: use a tighter cap in credit_entropy_bits_safe() [ Upstream commit 9f886f4d1d292442b2f22a0a33321eae821bde40 ] 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 Reported-by: Chen Feng Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- diff --git a/drivers/char/random.c b/drivers/char/random.c index 6fa0efa48cc51..4ba5c7e4e2546 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -704,7 +704,7 @@ retry: 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);