From patchwork Mon Mar 6 07:17:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9605175 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 163B5602B4 for ; Mon, 6 Mar 2017 07:17:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0878127813 for ; Mon, 6 Mar 2017 07:17:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED6BA27CF3; Mon, 6 Mar 2017 07:17:52 +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 766CC27813 for ; Mon, 6 Mar 2017 07:17:52 +0000 (UTC) Received: from localhost ([::1]:42138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckmty-0001b8-WE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Mar 2017 02:17:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckmth-0001Zq-QQ for qemu-devel@nongnu.org; Mon, 06 Mar 2017 02:17:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckmtg-00006w-OS for qemu-devel@nongnu.org; Mon, 06 Mar 2017 02:17:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckmtg-00006S-Hw for qemu-devel@nongnu.org; Mon, 06 Mar 2017 02:17:32 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95F748553E; Mon, 6 Mar 2017 07:17:32 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-62.sin2.redhat.com [10.67.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25E022D655; Mon, 6 Mar 2017 07:17:29 +0000 (UTC) From: P J P To: Qemu Developers Date: Mon, 6 Mar 2017 12:47:20 +0530 Message-Id: <20170306071721.26708-2-ppandit@redhat.com> In-Reply-To: <20170306071721.26708-1-ppandit@redhat.com> References: <20170306071721.26708-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 06 Mar 2017 07:17:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] linux-user: limit number of arguments to execve 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: Peter Maydell , Riku Voipio , Prasad J Pandit , Jann Horn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit Limit the number of arguments passed to execve(2) call from a user program, as large number of them could lead to a bad guest address error. Reported-by: Jann Horn Signed-off-by: Prasad J Pandit --- linux-user/syscall.c | 6 ++++++ 1 file changed, 6 insertions(+) Update per: use gemu_log() to report error -> https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg00750.html diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9be8e95..86a4a9c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7766,6 +7766,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #endif case TARGET_NR_execve: { +#define ARG_MAX 65535 char **argp, **envp; int argc, envc; abi_ulong gp; @@ -7794,6 +7795,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, envc++; } + if (argc > ARG_MAX || envc > ARG_MAX) { + gemu_log("argc(%d), envc(%d) exceed %d\n", argc, envc, ARG_MAX); + ret = -TARGET_E2BIG; + break; + } argp = alloca((argc + 1) * sizeof(void *)); envp = alloca((envc + 1) * sizeof(void *));