Commit 5ee22bee authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random

Pull randomness bugfix from Ted Ts'o:
 "random: fix entropy accounting bug introduced in v3.15"

* tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
  random: fix nasty entropy accounting bug
parents 5cfb277d e33ba5fa
...@@ -980,7 +980,6 @@ static void push_to_pool(struct work_struct *work) ...@@ -980,7 +980,6 @@ static void push_to_pool(struct work_struct *work)
static size_t account(struct entropy_store *r, size_t nbytes, int min, static size_t account(struct entropy_store *r, size_t nbytes, int min,
int reserved) int reserved)
{ {
int have_bytes;
int entropy_count, orig; int entropy_count, orig;
size_t ibytes; size_t ibytes;
...@@ -989,17 +988,19 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min, ...@@ -989,17 +988,19 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
/* Can we pull enough? */ /* Can we pull enough? */
retry: retry:
entropy_count = orig = ACCESS_ONCE(r->entropy_count); entropy_count = orig = ACCESS_ONCE(r->entropy_count);
have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
ibytes = nbytes; ibytes = nbytes;
/* If limited, never pull more than available */ /* If limited, never pull more than available */
if (r->limit) if (r->limit) {
ibytes = min_t(size_t, ibytes, have_bytes - reserved); int have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
if ((have_bytes -= reserved) < 0)
have_bytes = 0;
ibytes = min_t(size_t, ibytes, have_bytes);
}
if (ibytes < min) if (ibytes < min)
ibytes = 0; ibytes = 0;
if (have_bytes >= ibytes + reserved) if ((entropy_count -= ibytes << (ENTROPY_SHIFT + 3)) < 0)
entropy_count -= ibytes << (ENTROPY_SHIFT + 3); entropy_count = 0;
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