Commit f9c6d498 authored by Theodore Ts'o's avatar Theodore Ts'o

random: fix BUG_ON caused by accounting simplification

Commit ee1de406 ("random: simplify accounting logic") simplified
things too much, in that it allows the following to trigger an
overflow that results in a BUG_ON crash:

dd if=/dev/urandom of=/dev/zero bs=67108707 count=1

Thanks to Peter Zihlstra for discovering the crash, and Hannes
Frederic for analyizing the root cause.
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Reported-by: default avatarPeter Zijlstra <peterz@infradead.org>
Reported-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
Cc: Greg Price <price@mit.edu>
parent d6d211db
...@@ -995,8 +995,11 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min, ...@@ -995,8 +995,11 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
ibytes = min_t(size_t, ibytes, have_bytes - reserved); ibytes = min_t(size_t, ibytes, have_bytes - reserved);
if (ibytes < min) if (ibytes < min)
ibytes = 0; ibytes = 0;
entropy_count = max_t(int, 0, if (have_bytes >= ibytes + reserved)
entropy_count - (ibytes << (ENTROPY_SHIFT + 3))); entropy_count -= ibytes << (ENTROPY_SHIFT + 3);
else
entropy_count = reserved << (ENTROPY_SHIFT + 3);
if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
goto retry; goto retry;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment