From patchwork Fri Mar 24 16:58:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9643361 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 B741C602C9 for ; Fri, 24 Mar 2017 17:01:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5F73212BE for ; Fri, 24 Mar 2017 17:01:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A99E25404; Fri, 24 Mar 2017 17:01:09 +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 2769D212BE for ; Fri, 24 Mar 2017 17:01:09 +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 1crSY5-0007Zl-KC; Fri, 24 Mar 2017 16:58:49 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1crSY3-0007Zd-ED for xen-devel@lists.xenproject.org; Fri, 24 Mar 2017 16:58:47 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id DE/76-00654-64055D85; Fri, 24 Mar 2017 16:58:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsXitHRDpK5zwNU Ig+fP2S2+b5nM5MDocfjDFZYAxijWzLyk/IoE1owHVyazFcwQrXj9/DhrA+N0wS5GTg4JAX+J TY+fsYLYbAI6ElOfXgKzRQRsJfq/fweyuTiYBVoYJU58mM4IkhAWcJd4/uEyE4jNIqAq0bv6F zOIzSvgKrH09A1WiKFyEueP/wSLCwmoSKyfOosNokZQ4uTMJywgNrOAhMTBFy+YJzByz0KSmo UktYCRaRWjRnFqUVlqka6RoV5SUWZ6RkluYmaOrqGBqV5uanFxYnpqTmJSsV5yfu4mRmA41DM wMO5gvDvZ7xCjJAeTkiiv27YrEUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeFu8r0YICRalpqdW pGXmAAMTJi3BwaMkwvsMJM1bXJCYW5yZDpE6xajLMWf27jdMQix5+XmpUuK8+SBFAiBFGaV5c CNgUXKJUVZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjBvpQfQFJ7MvBK4Ta+AjmACOmL2hisgR5 QkIqSkGhg32+3fwD6H/8Ur3QLG9g6RwhKbNfy/nRWbP+3sfZ6h/vTdMZ75WheEA/ped2yZzNZ +fWXs7XcxO1541AW8iSlhaH8cyHuocHOeya097mV53n/e6FVZ1fcYT1K6uMgviJubRUDg5dSb WwpS84Q6vrRZTbilet+3gO3+8w13C5pXtEzt+Sy5/YkSS3FGoqEWc1FxIgBqnVpUjQIAAA== X-Env-Sender: prvs=249263d75=Paul.Durrant@citrix.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1490374720!91374264!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: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18846 invoked from network); 24 Mar 2017 16:58:42 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-9.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 24 Mar 2017 16:58:42 -0000 X-IronPort-AV: E=Sophos;i="5.36,215,1486425600"; d="scan'208";a="415771479" From: Paul Durrant To: , Date: Fri, 24 Mar 2017 16:58:08 +0000 Message-ID: <1490374688-488-1-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Cc: Anthony Perard , Paul Durrant , Stefano Stabellini Subject: [Xen-devel] [PATCH] xen: additionally restrict xenforeignmemory operations 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 Commit f0f272baf3a7 "xen: use libxendevice model to restrict operations" added a command-line option (-xen-domid-restrict) to limit operations using the libxendevicemodel API to a specified domid. The commit also noted that the restriction would be extended to cover operations issued via other xen libraries by subsequent patches. My recent Xen patch [1] added a call to the xenforeignmemory API to allow it to be restricted. This patch now makes use of that new call when the -xen-domid-restrict option is passed. [1] http://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=5823d6eb Signed-off-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Anthony Perard --- include/hw/xen/xen_common.h | 52 +++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 4f3bd35..6f13e8c 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -213,19 +213,6 @@ static inline int xen_modified_memory(domid_t domid, uint64_t first_pfn, return xendevicemodel_modified_memory(xen_dmod, domid, first_pfn, nr); } -static inline int xen_restrict(domid_t domid) -{ - int rc = xendevicemodel_restrict(xen_dmod, domid); - - trace_xen_domid_restrict(errno); - - if (errno == ENOTTY) { - return 0; - } - - return rc; -} - /* Xen 4.2 through 4.6 */ #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40701 @@ -276,8 +263,47 @@ static inline void *xenforeignmemory_map(xc_interface *h, uint32_t dom, #endif +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 + +static inline int xenforeignmemory_restrict( + xenforeignmemory_handle *fmem, domid_t domid) +{ + errno = ENOTTY; + return -1; +} + +#endif + extern xenforeignmemory_handle *xen_fmem; +static inline int xen_restrict(domid_t domid) +{ + int rc; + + /* Attempt to restrict devicemodel operations */ + rc = xendevicemodel_restrict(xen_dmod, domid); + trace_xen_domid_restrict(rc ? errno : 0); + + if (rc < 0) { + /* + * If errno is ENOTTY then restriction is not implemented so + * there's no point in trying to restrict other types of + * operation, but it should not be treated as a failure. + */ + if (errno == ENOTTY) { + return 0; + } + + return rc; + } + + /* Restrict foreignmemory operations */ + rc = xenforeignmemory_restrict(xen_fmem, domid); + trace_xen_domid_restrict(rc ? errno : 0); + + return rc; +} + void destroy_hvm_domain(bool reboot); /* shutdown/destroy current domain because of an error */