Avoid overflowing FDSET when using select(2).
authorPauli <paul.dale@oracle.com>
Sat, 24 Aug 2019 06:13:24 +0000 (16:13 +1000)
committerPauli <paul.dale@oracle.com>
Sat, 24 Aug 2019 06:45:53 +0000 (16:45 +1000)
There is a problem in the rand_unix.c code when the random seed fd is greater
than or equal to FD_SETSIZE and the FDSET overruns its limit and walks the
stack.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9686)

(cherry picked from commit e1f8584d47a499301fba781086af6885fcf21fec)

crypto/rand/rand_unix.c

index 0d449d235afaeeb287b1c2d5de75bc9994da130a..258fef7eb0854cd74bba770384fc049e62d284e9 100644 (file)
@@ -411,7 +411,7 @@ static int wait_random_seeded(void)
             }
             /* Open /dev/random and wait for it to be readable */
             if ((fd = open(DEVRANDOM_WAIT, O_RDONLY)) != -1) {
-                if (DEVRANDM_WAIT_USE_SELECT) {
+                if (DEVRANDM_WAIT_USE_SELECT && fd < FD_SETSIZE) {
                     FD_ZERO(&fds);
                     FD_SET(fd, &fds);
                     while ((r = select(fd + 1, &fds, NULL, NULL, NULL)) < 0