Skip to content

Commit

Permalink
random: fix BUG_ON caused by accounting simplification
Browse files Browse the repository at this point in the history
Commit ee1de40 ("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: "Theodore Ts'o" <tytso@mit.edu>
Reported-by: Peter Zijlstra <peterz@infradead.org>
Reported-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Cc: Greg Price <price@mit.edu>
  • Loading branch information
Theodore Ts'o committed May 17, 2014
1 parent d6d211d commit f9c6d49
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
if (ibytes < min)
ibytes = 0;
entropy_count = max_t(int, 0,
entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
if (have_bytes >= ibytes + reserved)
entropy_count -= ibytes << (ENTROPY_SHIFT + 3);
else
entropy_count = reserved << (ENTROPY_SHIFT + 3);

if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
goto retry;

Expand Down

0 comments on commit f9c6d49

Please sign in to comment.