From patchwork Mon Mar 6 07:17:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9605177 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 DDF19602B4 for ; Mon, 6 Mar 2017 07:17:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D220E27813 for ; Mon, 6 Mar 2017 07:17:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C70DE27F4B; Mon, 6 Mar 2017 07:17:58 +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 574C727813 for ; Mon, 6 Mar 2017 07:17:58 +0000 (UTC) Received: from localhost ([::1]:42140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckmu5-0001dd-2F for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Mar 2017 02:17:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckmtk-0001bb-MW for qemu-devel@nongnu.org; Mon, 06 Mar 2017 02:17:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckmtj-000092-KB for qemu-devel@nongnu.org; Mon, 06 Mar 2017 02:17:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43818) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckmtj-00008b-E9 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 02:17:35 -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 9F4A43DD47; Mon, 6 Mar 2017 07:17:35 +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 2D75D2D653; Mon, 6 Mar 2017 07:17:32 +0000 (UTC) From: P J P To: Qemu Developers Date: Mon, 6 Mar 2017 12:47:21 +0530 Message-Id: <20170306071721.26708-3-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.29]); Mon, 06 Mar 2017 07:17:35 +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 2/2] linux-user: allocate heap memory for execve arguments 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 Arguments passed to execve(2) call from user program could be large, allocating stack memory for them via alloca(3) call would lead to bad behaviour. Use 'g_malloc0' to allocate memory for such arguments. Signed-off-by: Prasad J Pandit --- linux-user/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) Update per: replace alloca() with g_malloc0() -> 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 86a4a9c..404fb0b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7800,8 +7800,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret = -TARGET_E2BIG; break; } - argp = alloca((argc + 1) * sizeof(void *)); - envp = alloca((envc + 1) * sizeof(void *)); + argp = g_malloc0((argc + 1) * sizeof(void *)); + envp = g_malloc0((envc + 1) * sizeof(void *)); for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) { @@ -7862,6 +7862,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, break; unlock_user(*q, addr, 0); } + + g_free(argp); + g_free(envp); } break; case TARGET_NR_chdir: