random: fix entropy accounting bug introduced in v3.15
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABCAAGBQJToH5YAAoJENNvdpvBGATwtuIQAOHsQAPDHbo7iSullr/tOTRd BZhFfdiG47tS4FkVYsrqSFCloROkneSCIIN0HLeTRbt4hA4SjN+jEkM2mtQ0dA/t ++DVgzFxMUvb7yOIA4uQk1C3kxlvPdx9EeGMHnSZ9u/uNUwfgqvlQ7r+k+kldtGp J+Ouaoy7w+XeXPy3JrFnKmvvFTjC94h0T7VWPJlqXRFmu8fN6sCxgXPfsdQkxcXw q75sD11nuVhUDy8CQbFfT1IHDshiBnFMm6muIipZcY0zu/ecutBkwpA+//ommxnM xPWf1vt3hJj3IGqgz9I0pJhBTHkpmmqVlW8pDMgNVwbAu7kEVrJ0YKfQLkP1JRbF lJe5G0Iy27y1Lx+UBw8WnGe/BxAE+8Ljq1p2gE5qbVZfB7w5/zgZDbREGdZG/+8K kZrYth4gKNVJEZBu1S6g0NSYG6DkF3voMRSan5U+t6pXR7PhEDMl+m4ablUnZjCQ tNK4rPKVtbisfOHcAEd5FNmHOat3hJ6WNAa3dzv7LEH6v2PPU7q1JVDr5tbvmhZr qW63+TvIpfX2kA0DkPnMnj8f3gXrRtZdUXeQF4RTMZRe26Sg262/bx2nR9h4H77n +x75tswu0epo9x/Ip/m9sC6MOzB2s4MUrCEZjpBVzvbgueIo7A16kMKsJbHRRtos 4nMa2AnoMMkfoDn7uQtm =UeTe -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
5ee22beeb2
|
@ -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,
|
||||
int reserved)
|
||||
{
|
||||
int have_bytes;
|
||||
int entropy_count, orig;
|
||||
size_t ibytes;
|
||||
|
||||
|
@ -989,17 +988,19 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
|
|||
/* Can we pull enough? */
|
||||
retry:
|
||||
entropy_count = orig = ACCESS_ONCE(r->entropy_count);
|
||||
have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
|
||||
ibytes = nbytes;
|
||||
/* If limited, never pull more than available */
|
||||
if (r->limit)
|
||||
ibytes = min_t(size_t, ibytes, have_bytes - reserved);
|
||||
if (r->limit) {
|
||||
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)
|
||||
ibytes = 0;
|
||||
if (have_bytes >= ibytes + reserved)
|
||||
entropy_count -= ibytes << (ENTROPY_SHIFT + 3);
|
||||
else
|
||||
entropy_count = reserved << (ENTROPY_SHIFT + 3);
|
||||
if ((entropy_count -= ibytes << (ENTROPY_SHIFT + 3)) < 0)
|
||||
entropy_count = 0;
|
||||
|
||||
if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
|
||||
goto retry;
|
||||
|
|
Loading…
Reference in New Issue