Skip to content

Commit 5a021e9

Browse files
Matt MackallLinus Torvalds
authored andcommitted
random: fix bound check ordering (CVE-2007-3105)
If root raised the default wakeup threshold over the size of the output pool, the pool transfer function could overflow the stack with RNG bytes, causing a DoS or potential privilege escalation. (Bug reported by the PaX Team <pageexec@freemail.hu>) Cc: Theodore Tso <tytso@mit.edu> Cc: Willy Tarreau <w@1wt.eu> Signed-off-by: Matt Mackall <mpm@selenic.com> Signed-off-by: Chris Wright <chrisw@sous-sol.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f745bb1 commit 5a021e9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎drivers/char/random.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,14 @@ static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
693693

694694
if (r->pull && r->entropy_count < nbytes * 8 &&
695695
r->entropy_count < r->poolinfo->POOLBITS) {
696-
int bytes = max_t(int, random_read_wakeup_thresh / 8,
697-
min_t(int, nbytes, sizeof(tmp)));
696+
/* If we're limited, always leave two wakeup worth's BITS */
698697
int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4;
698+
int bytes = nbytes;
699+
700+
/* pull at least as many as BYTES as wakeup BITS */
701+
bytes = max_t(int, bytes, random_read_wakeup_thresh / 8);
702+
/* but never more than the buffer size */
703+
bytes = min_t(int, bytes, sizeof(tmp));
699704

700705
DEBUG_ENT("going to reseed %s with %d bits "
701706
"(%d of %d requested)\n",

0 commit comments

Comments
 (0)