From nobody Sun Apr 28 08:46:55 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 149037480291787.58729392838177; Fri, 24 Mar 2017 10:00:02 -0700 (PDT) Received: from localhost ([::1]:34135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crSZB-0008Sx-8F for importer@patchew.org; Fri, 24 Mar 2017 12:59:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crSY2-0007x5-27 for qemu-devel@nongnu.org; Fri, 24 Mar 2017 12:58:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1crSXz-0002cC-0V for qemu-devel@nongnu.org; Fri, 24 Mar 2017 12:58:46 -0400 Received: from smtp.citrix.com ([66.165.176.89]:38855) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1crSXy-0002bb-O1 for qemu-devel@nongnu.org; Fri, 24 Mar 2017 12:58:42 -0400 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 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH] xen: additionally restrict xenforeignmemory operations 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: Anthony Perard , Paul Durrant , Stefano Stabellini 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 Content-Type: text/plain; charset="utf-8" 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=3Dxen.git;a=3Dcommit;h=3D5823d6eb 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, u= int64_t first_pfn, return xendevicemodel_modified_memory(xen_dmod, domid, first_pfn, nr); } =20 -static inline int xen_restrict(domid_t domid) -{ - int rc =3D xendevicemodel_restrict(xen_dmod, domid); - - trace_xen_domid_restrict(errno); - - if (errno =3D=3D ENOTTY) { - return 0; - } - - return rc; -} - /* Xen 4.2 through 4.6 */ #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40701 =20 @@ -276,8 +263,47 @@ static inline void *xenforeignmemory_map(xc_interface = *h, uint32_t dom, =20 #endif =20 +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 + +static inline int xenforeignmemory_restrict( + xenforeignmemory_handle *fmem, domid_t domid) +{ + errno =3D ENOTTY; + return -1; +} + +#endif + extern xenforeignmemory_handle *xen_fmem; =20 +static inline int xen_restrict(domid_t domid) +{ + int rc; + + /* Attempt to restrict devicemodel operations */ + rc =3D 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 =3D=3D ENOTTY) { + return 0; + } + + return rc; + } + + /* Restrict foreignmemory operations */ + rc =3D xenforeignmemory_restrict(xen_fmem, domid); + trace_xen_domid_restrict(rc ? errno : 0); + + return rc; +} + void destroy_hvm_domain(bool reboot); =20 /* shutdown/destroy current domain because of an error */ --=20 2.1.4