From owner-dev-commits-src-branches@freebsd.org Tue Jun 29 19:59:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1D8376515FF; Tue, 29 Jun 2021 19:59:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GDwKj0Lqgz3qLr; Tue, 29 Jun 2021 19:59:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E88391F1BA; Tue, 29 Jun 2021 19:59:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15TJxKnc066961; Tue, 29 Jun 2021 19:59:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15TJxKEl066960; Tue, 29 Jun 2021 19:59:20 GMT (envelope-from git) Date: Tue, 29 Jun 2021 19:59:20 GMT Message-Id: <202106291959.15TJxKEl066960@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f80ee27f447a - stable/11 - linux(4): Prevent integer overflow in futex_requeue. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/11 X-Git-Reftype: branch X-Git-Commit: f80ee27f447abc7baeb413cc0a7b7c21f9d32f8b Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jun 2021 19:59:21 -0000 The branch stable/11 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f80ee27f447abc7baeb413cc0a7b7c21f9d32f8b commit f80ee27f447abc7baeb413cc0a7b7c21f9d32f8b Author: Dmitry Chagin AuthorDate: 2021-06-10 11:23:11 +0000 Commit: Mark Johnston CommitDate: 2021-06-29 18:47:53 +0000 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. (cherry picked from commit 25b09d6f398ea8a260ee8e2e8209fd76c61e13ee) --- sys/compat/linux/linux_futex.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index 686d2f7d2ec7..0be0483f4496 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -596,18 +596,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; @@ -633,7 +634,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; } } @@ -744,7 +745,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; @@ -888,6 +889,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) { @@ -938,8 +948,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;