From patchwork Mon Jul 18 14:35:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9234775 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 1BC406075D for ; Mon, 18 Jul 2016 14:54:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E0F41FEC1 for ; Mon, 18 Jul 2016 14:54:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02F01269E2; Mon, 18 Jul 2016 14:54:43 +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 7EB611FEC1 for ; Mon, 18 Jul 2016 14:54:43 +0000 (UTC) Received: from localhost ([::1]:48120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP9wQ-0006Lv-KG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jul 2016 10:54:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP9w3-0006Ii-RO for qemu-devel@nongnu.org; Mon, 18 Jul 2016 10:54:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bP9w3-00046U-0h for qemu-devel@nongnu.org; Mon, 18 Jul 2016 10:54:19 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP9w2-000468-P0 for qemu-devel@nongnu.org; Mon, 18 Jul 2016 10:54:18 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bP9eL-0002S7-Jg; Mon, 18 Jul 2016 15:36:01 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 18 Jul 2016 15:35:59 +0100 Message-Id: <1468852560-9054-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468852560-9054-1-git-send-email-peter.maydell@linaro.org> References: <1468852560-9054-1-git-send-email-peter.maydell@linaro.org> 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 1/2] linux-user: Check for bad event numbers in epoll_wait 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 The kernel checks that the maxevents parameter to epoll_wait is non-negative and not larger than EP_MAX_EVENTS. Add this check to our implementation, so that: * we fail these cases EINVAL rather than EFAULT * we don't pass negative or overflowing values to the lock_user() size calculation Signed-off-by: Peter Maydell --- This fixes an LTP epoll_wait03 test case that checks a negative max_events argument. --- linux-user/syscall.c | 5 +++++ linux-user/syscall_defs.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fe72abe..3552295 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11024,6 +11024,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, int maxevents = arg3; int timeout = arg4; + if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) { + ret = -TARGET_EINVAL; + break; + } + target_ep = lock_user(VERIFY_WRITE, arg2, maxevents * sizeof(struct target_epoll_event), 1); if (!target_ep) { diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index d9dea0e..dbf6a38 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2585,6 +2585,9 @@ struct target_epoll_event { abi_uint events; target_epoll_data_t data; } TARGET_EPOLL_PACKED; + +#define TARGET_EP_MAX_EVENTS (INT_MAX / sizeof(struct target_epoll_event)) + #endif struct target_rlimit64 { uint64_t rlim_cur;