From patchwork Wed May 31 13:08:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9756981 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 B56E7602F0 for ; Wed, 31 May 2017 13:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEE5C281F9 for ; Wed, 31 May 2017 13:10:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1E8C2836F; Wed, 31 May 2017 13:10:02 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 205D9281F9 for ; Wed, 31 May 2017 13:10:02 +0000 (UTC) Received: from localhost ([::1]:59323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Nx-0007a7-3g for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 May 2017 09:10:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Me-0007U5-Cz for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG3Md-0003dC-CP for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:40 -0400 Received: from mail-lf0-x233.google.com ([2a00:1450:4010:c07::233]:34434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG3Md-0003cx-4W for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:39 -0400 Received: by mail-lf0-x233.google.com with SMTP id 99so8619103lfu.1 for ; Wed, 31 May 2017 06:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sVUFJPyhoMVfwU6dfdh6SzS9wv74DR0CHue3CQwsChU=; b=UWXUTODk7Fp4ibPSVA0psydCh19Qp7uXGTDNHsBRp3p72+YxsNSo+K/6BSBBwt8bHp zBZfXpFeBcOQgNcGO2/FqY1axdA6UvGEm+1jnMsbJw9AL4HHbGuFRbZrUGPNQOxZuCPD arprKqFGE11Mzp732owvcHA2eJ/VxBYUaYlds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sVUFJPyhoMVfwU6dfdh6SzS9wv74DR0CHue3CQwsChU=; b=HoeM67tl1BOwjRZMyUxo6i2JblkoCTUDeZPxUNqIO8JBKTBAicMB04tDsnWfkDroZ/ e9o5CrCYRaIHCsrmGNwSyNRWhbXu4cWII3iUejDn+kL1dSPh/R6TgA6qCV40p4uI2cUr LqOains9b7+ioBrbtRsOsrUAEWlCLYiipHnso4LTRXgLMH0FNlbRhS0kxf0sc9FYGSzw uZ9a0JYlp7jET7WnjSbeB+MLSC9dhOoy20smY3BwWBLJdh3S4hgJki9R7DrznkClv2D8 3/9o4n0g/s7KOvASxLET5A/2dLrpwSocvtAzuHEkZDIYBx2YuBilrW7a6rTVJ10c9ymF W5jQ== X-Gm-Message-State: AODbwcA7S6ulQMy14E9CfoHSbg7aeQccAHXtniPW6pZAlBR7gGbV5WiU Uezf4Wd4iLJN7PTuStHNwQ== X-Received: by 10.25.160.75 with SMTP id j72mr7617882lfe.97.1496236117714; Wed, 31 May 2017 06:08:37 -0700 (PDT) Received: from localhost.localdomain (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id o101sm3741766lfg.3.2017.05.31.06.08.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 06:08:36 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 16:08:17 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::233 Subject: [Qemu-devel] [PULL 05/15] 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@linaro.org, Prasad J Pandit , stefanha@redhat.com 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_new0' to allocate memory for such arguments. Reported-by: Jann Horn Signed-off-by: Prasad J Pandit Reviewed-by: Eric Blake Signed-off-by: Riku Voipio --- linux-user/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 32aba195c5..c8f6efc89c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7985,8 +7985,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, envc++; } - argp = alloca((argc + 1) * sizeof(void *)); - envp = alloca((envc + 1) * sizeof(void *)); + argp = g_new0(char *, argc + 1); + envp = g_new0(char *, envc + 1); for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) { @@ -8047,6 +8047,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: