diff options
author | Dmitry Chagin <dchagin@FreeBSD.org> | 2021-06-10 11:23:11 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2021-06-29 20:06:09 +0000 |
commit | d1fffaed2309d8bd9dd840de422647c5c83f8411 (patch) | |
tree | 4a85f464c76c5bd03d4ca206a3e2caa836d2dd7c | |
parent | 4647d115ff849534c9d6712cc2da32509721e20e (diff) | |
download | src-d1fffaed2309d8bd9dd840de422647c5c83f8411.tar.gz src-d1fffaed2309d8bd9dd840de422647c5c83f8411.zip |
linux(4): Prevent integer overflow in futex_requeue.
To prevent a signed integer overflow in futex_requeue add a sanity check
to catch negative values of nrwake or nrrequeue.
Approved by: so
Security: EN-21:22.linux_futex
(cherry picked from commit 25b09d6f398ea8a260ee8e2e8209fd76c61e13ee)
(cherry picked from commit 7a37d13b6cfa5235c88678f96ede6bfca74b28e8)
-rw-r--r-- | sys/compat/linux/linux_futex.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index 43ac318d2b51..75fdddb203b7 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -587,18 +587,19 @@ futex_wake(struct futex *f, int n, uint32_t bitset) } static int -futex_requeue(struct futex *f, int n, struct futex *f2, int n2) +futex_requeue(struct futex *f, int nrwake, struct futex *f2, + int nrrequeue) { struct waiting_proc *wp, *wpt; int count = 0; - LIN_SDT_PROBE4(futex, futex_requeue, entry, f, n, f2, n2); + LIN_SDT_PROBE4(futex, futex_requeue, entry, f, nrwake, f2, nrrequeue); FUTEX_ASSERT_LOCKED(f); FUTEX_ASSERT_LOCKED(f2); TAILQ_FOREACH_SAFE(wp, &f->f_waiting_proc, wp_list, wpt) { - if (++count <= n) { + if (++count <= nrwake) { LINUX_CTR2(sys_futex, "futex_req_wake uaddr %p wp %p", f->f_uaddr, wp); wp->wp_flags |= FUTEX_WP_REMOVED; @@ -624,7 +625,7 @@ futex_requeue(struct futex *f, int n, struct futex *f2, int n2) FUTEXES_LOCK; ++f2->f_refcount; FUTEXES_UNLOCK; - if (count - n >= n2) + if (count - nrwake >= nrrequeue) break; } } @@ -736,7 +737,7 @@ futex_atomic_op(struct thread *td, int encoded_op, uint32_t *uaddr) int linux_sys_futex(struct thread *td, struct linux_sys_futex_args *args) { - int clockrt, nrwake, op_ret, ret; + int clockrt, nrwake, nrrequeue, op_ret, ret; struct linux_pemuldata *pem; struct waiting_proc *wp; struct futex *f, *f2; @@ -880,6 +881,15 @@ retry0: return (EINVAL); } + nrrequeue = (int)(unsigned long)args->timeout; + nrwake = args->val; + /* + * Sanity check to prevent signed integer overflow, + * see Linux CVE-2018-6927 + */ + if (nrwake < 0 || nrrequeue < 0) + return (EINVAL); + retry1: error = futex_get(args->uaddr, NULL, &f, flags | FUTEX_DONTLOCK); if (error) { @@ -930,8 +940,7 @@ retry1: return (EAGAIN); } - nrwake = (int)(unsigned long)args->timeout; - td->td_retval[0] = futex_requeue(f, args->val, f2, nrwake); + td->td_retval[0] = futex_requeue(f, nrwake, f2, nrrequeue); futex_put(f2, NULL); futex_put(f, NULL); break; |