From patchwork Thu May 26 15:54:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9137201 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 709F76075A for ; Thu, 26 May 2016 15:56:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A33927D11 for ; Thu, 26 May 2016 15:56:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E282282F7; Thu, 26 May 2016 15:56:24 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BD14327D11 for ; Thu, 26 May 2016 15:56:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5xbw-0006cr-QI; Thu, 26 May 2016 15:54:12 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5xbv-0006ci-MK for xen-devel@lists.xenproject.org; Thu, 26 May 2016 15:54:11 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id E1/4F-19820-22C17475; Thu, 26 May 2016 15:54:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsXitHRDpK6SjHu 4wZRFShbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aM6y4FW1QqjjbuYmxg/CzTxcjJISHgLzFn 5WdGEJtFQFXi4p5mJhCbTUBZ4mdnLxuILSKgLbH/3Wswm1mgSuLS9g/MILawgLvEwqbN7CA2r 4C+xMHrm4FquDiEBA4wSlx+t4wZIiEocXLmExaIZh2JBbs/ARVxANnSEsv/cYCYnAIGEk8Om4 NUiAqoSFyZ8BZspJCAgkTH9GNMICUSAtwSf7vtJzDyz0IycxaSmbMQZi5gZF7FqF6cWlSWWqR rqJdUlJmeUZKbmJmja2hgppebWlycmJ6ak5hUrJecn7uJERh6DECwg3Hnc6dDjJIcTEqivOLi buFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHgvHQDKCRalpqdWpGXmAKMAJi3BwaMkwjtbyj1ci Le4IDG3ODMdInWKUVFKnDcMJCEAksgozYNrg0XeJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKg nz/gGZwpOZVwI3/RXQYiagxf5fnEEWlyQipKQaGBV+tVxzi69K60qfvDjwmZHsjOTjE8T7Gmz T22oq/ivWHObXLEosnmncvDr9qFRY1NN16ams9scubjf8HPgudqZb4IO4gHvPdjurP/4TmWr7 4Rv/1uYdx5rDgqJ02m0Sbu1eXJSjsyPlavRUk5zOa/vT7+xYbJSc3Oe8jTXsctQdqZCFNd0Pl FiKMxINtZiLihMBd9DPUbcCAAA= X-Env-Sender: prvs=947cb6223=wei.liu2@citrix.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1464278049!15967835!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9075 invoked from network); 26 May 2016 15:54:10 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 26 May 2016 15:54:10 -0000 X-IronPort-AV: E=Sophos;i="5.26,367,1459814400"; d="scan'208";a="356848689" Date: Thu, 26 May 2016 16:54:07 +0100 From: Wei Liu To: Ian Jackson Message-ID: <20160526155407.GA22076@citrix.com> References: <20160526151957.GX22076@citrix.com> <1464276116-8412-1-git-send-email-wei.liu2@citrix.com> <22343.6465.655026.60692@mariner.uk.xensource.com> <20160526154759.GZ22076@citrix.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160526154759.GZ22076@citrix.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-DLP: MIA1 Cc: Anthony PERARD , Xen-devel , Wei Liu Subject: Re: [Xen-devel] [PATCH for-4.7] libxl: set XEN_QEMU_CONSOLE_LIMIT for QEMU X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Thu, May 26, 2016 at 04:47:59PM +0100, Wei Liu wrote: > On Thu, May 26, 2016 at 04:41:53PM +0100, Ian Jackson wrote: > > Wei Liu writes ("[PATCH for-4.7] libxl: set XEN_QEMU_CONSOLE_LIMIT for QEMU"): > > > XSA-180 provides a patch to QEMU to bodge QEMU logging issue. We > > > explicitly set the limit in libxl for 4.7. > > ... > > > + unsigned long limit = 0; > > > + const char *s = getenv("XEN_QEMU_CONSOLE_LIMIT"); > > > + > > > + limit = s ? strtoul(s,0,0) : 1*1024*1024; > > > + flexarray_append_pair(dm_envs, "XEN_QEMU_CONSOLE_LIMIT", > > > + GCSPRINTF("%lu", limit)); > > > > This is rather more complex than it needs to be. What would be wrong > > with > > if (getenv("XEN_QEMU_CONSOLE_LIMIT")) return; > > flexarray_append_pair(dm_envs, "XEN_QEMU_CONSOLE_LIMIT", "1048576"); > > ? > > > > Nice, this is simpler. I will use this version and keep your ack. > I will push this patch soon. ---8<--- From 1d915bc7805bde9fe90341e9bcea01bf50154d87 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 26 May 2016 16:11:42 +0100 Subject: [PATCH] libxl: set XEN_QEMU_CONSOLE_LIMIT for QEMU XSA-180 provides a patch to QEMU to bodge QEMU logging issue. We explicitly set the limit in libxl for 4.7. Introduce a function for setting the environment variable and call it in the right places. Signed-off-by: Wei Liu Acked-by: Ian Jackson --- tools/libxl/libxl_dm.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 6bbc7c3..155a653 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -365,6 +365,20 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, return ERROR_FAIL; } +/* XSA-180 / CVE-2014-3672 + * + * The QEMU shipped with Xen has a bodge. It checks for + * XEN_QEMU_CONSOLE_LIMIT to see how much data QEMU is allowed + * to write to stderr. We set that to 1MB if it is not set by + * system administrator. + */ +static void libxl__set_qemu_env_for_xsa_180(libxl__gc *gc, + flexarray_t *dm_envs) +{ + if (getenv("XEN_QEMU_CONSOLE_LIMIT")) return; + flexarray_append_pair(dm_envs, "XEN_QEMU_CONSOLE_LIMIT", "1048576"); +} + const libxl_vnc_info *libxl__dm_vnc(const libxl_domain_config *guest_config) { const libxl_vnc_info *vnc = NULL; @@ -415,6 +429,8 @@ static int libxl__build_device_model_args_old(libxl__gc *gc, dm_args = flexarray_make(gc, 16, 1); dm_envs = flexarray_make(gc, 16, 1); + libxl__set_qemu_env_for_xsa_180(gc, dm_envs); + flexarray_vappend(dm_args, dm, "-d", GCSPRINTF("%d", domid), NULL); @@ -913,6 +929,8 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, dm_args = flexarray_make(gc, 16, 1); dm_envs = flexarray_make(gc, 16, 1); + libxl__set_qemu_env_for_xsa_180(gc, dm_envs); + flexarray_vappend(dm_args, dm, "-xen-domid", GCSPRINTF("%d", guest_domid), NULL); @@ -2193,8 +2211,8 @@ static void device_model_spawn_outcome(libxl__egc *egc, void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) { STATE_AO_GC(dmss->spawn.ao); - flexarray_t *dm_args; - char **args; + flexarray_t *dm_args, *dm_envs; + char **args, **envs; const char *dm; int logfile_w, null = -1, rc; uint32_t domid = dmss->guest_domid; @@ -2203,6 +2221,8 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) dm = qemu_xen_path(gc); dm_args = flexarray_make(gc, 15, 1); + dm_envs = flexarray_make(gc, 1, 1); + flexarray_vappend(dm_args, dm, "-xen-domid", GCSPRINTF("%d", domid), NULL); flexarray_append(dm_args, "-xen-attach"); @@ -2216,6 +2236,9 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) flexarray_append(dm_args, NULL); args = (char **) flexarray_contents(dm_args); + libxl__set_qemu_env_for_xsa_180(gc, dm_envs); + envs = (char **) flexarray_contents(dm_envs); + logfile_w = libxl__create_qemu_logfile(gc, GCSPRINTF("qdisk-%u", domid)); if (logfile_w < 0) { rc = logfile_w; @@ -2253,7 +2276,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) goto out; if (!rc) { /* inner child */ setsid(); - libxl__exec(gc, null, logfile_w, logfile_w, dm, args, NULL); + libxl__exec(gc, null, logfile_w, logfile_w, dm, args, envs); } rc = 0;