From patchwork Mon Jul 18 15:30:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9234793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EEE4060756 for ; Mon, 18 Jul 2016 15:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFCD520246 for ; Mon, 18 Jul 2016 15:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D42DE2094F; Mon, 18 Jul 2016 15:31:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6985620246 for ; Mon, 18 Jul 2016 15:31:08 +0000 (UTC) Received: from localhost ([::1]:48346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPAVe-0004TA-Qn for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jul 2016 11:31:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPAVF-0004RH-VD for qemu-devel@nongnu.org; Mon, 18 Jul 2016 11:30:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPAVD-0004oG-NT for qemu-devel@nongnu.org; Mon, 18 Jul 2016 11:30:40 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58349) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPAVD-0004o9-AC for qemu-devel@nongnu.org; Mon, 18 Jul 2016 11:30:39 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bPAVB-0002Ta-4p; Mon, 18 Jul 2016 16:30:37 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 18 Jul 2016 16:30:36 +0100 Message-Id: <1468855836-11964-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] linux-user: Range check the nfds argument to ppoll syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Do an initial range check on the ppoll syscall's nfds argument, to avoid possible overflow in the calculation of the lock_user() size argument. The host kernel will later apply the rather lower limit based on RLIMIT_NOFILE as appropriate. Signed-off-by: Peter Maydell --- This fixes an LTP test case which passes -1 for nfds. The test is kind of bogus in that it should ideally pass a valid-but-over-the-rlimit nfds for this corner case rather than assuming EINVAL is checked before EFAULT, but in any case QEMU should protect itself against the overflow. --- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 721d7b1..4da7822 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9180,6 +9180,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, pfd = NULL; target_pfd = NULL; if (nfds) { + if (nfds > (INT_MAX / sizeof(struct target_pollfd))) { + ret = -TARGET_EINVAL; + break; + } + target_pfd = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_pollfd) * nfds, 1); if (!target_pfd) {