From nobody Tue May 7 07:56:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148878471335295.73888479647712; Sun, 5 Mar 2017 23:18:33 -0800 (PST) Received: from localhost ([::1]:42138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckmud-0001b8-G9 for importer@patchew.org; Mon, 06 Mar 2017 02:18:31 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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++; } =20 + if (argc > ARG_MAX || envc > ARG_MAX) { + gemu_log("argc(%d), envc(%d) exceed %d\n", argc, envc, ARG= _MAX); + ret =3D -TARGET_E2BIG; + break; + } argp =3D alloca((argc + 1) * sizeof(void *)); envp =3D alloca((envc + 1) * sizeof(void *)); =20 --=20 2.9.3 From nobody Tue May 7 07:56:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488784719215228.6944333061017; Sun, 5 Mar 2017 23:18:39 -0800 (PST) Received: from localhost ([::1]:42140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckmuj-0001dd-VY for importer@patchew.org; Mon, 06 Mar 2017 02:18:38 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D -TARGET_E2BIG; break; } - argp =3D alloca((argc + 1) * sizeof(void *)); - envp =3D alloca((envc + 1) * sizeof(void *)); + argp =3D g_malloc0((argc + 1) * sizeof(void *)); + envp =3D g_malloc0((envc + 1) * sizeof(void *)); =20 for (gp =3D guest_argp, q =3D argp; gp; gp +=3D 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: --=20 2.9.3