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: 100747 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp292920obc; Wed, 31 May 2017 06:09:10 -0700 (PDT) X-Received: by 10.55.58.67 with SMTP id h64mr9092226qka.9.1496236150162; Wed, 31 May 2017 06:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496236150; cv=none; d=google.com; s=arc-20160816; b=jeAOSsEf9ziAKp1PtGhjCkmwMzVUrEp7GQv74Y5vm3x2srPwnwd1PJstdLvwlX4kQF KBRC8VjirZZbedNt4vC7R8sjbI2W2CtXieVz5mVR6JNumqsdHjfZQ3BRWxDRVwiU3rM+ cdYJC7Iyl0ncRBHI0/Kw5fIQP4vWmNLWQlrfQ+SwSGL2h65zljcUHhFodrMLR1TiWSmr aPKBZnX2Hi0WKT58WyNRdp4hmAICLmXUYGtQNUKckPPTFgnODrLzuEQmL+ajj/KOXflk uDjv2aOCyqRPZGdwOwt8zZBJv79R2M5C5cj+LW12zyDDSoEvik2I5ujBl3vIs+O5awRz ZDew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=sVUFJPyhoMVfwU6dfdh6SzS9wv74DR0CHue3CQwsChU=; b=NJ+iY205hqeRiYHt9LjiSZm3zyE7ue/tALr5m2t60cQgSmvbtttznAx51tj8W1dffW jZEMnnNhJZWaNxWNHlOm7yMT2tHPUK55R7zMxvSm6yN5fYIaMUR/I/4qlMJbgLkz6fmS KKTSBktsAe8TP9YvjfobhE+NP7sCtnetOvfpCTeXnsgr0ZeG7iiHM1k0JWNCZvwjnmko lDeAlvmyHDoASSum3GaAWsJT6scT4dyrLfU8CLJynhY3SBrnWg+inwt0qbZ7jw83q7D8 8Zg1MksihM4cF282CPn7tW9nRNMZqz5BCLf+8Is9mhz7uuuYtF6NHfQz1j/cGwYQVwfH WiYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o23si16059755qka.170.2017.05.31.06.09.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 31 May 2017 06:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3N5-0007a7-IE for patch@linaro.org; Wed, 31 May 2017 09:09:07 -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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.11.0 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: