From patchwork Wed Aug 10 15:00:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas Lengyel X-Patchwork-Id: 9273157 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 B9BC560231 for ; Wed, 10 Aug 2016 15:03:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A94832841A for ; Wed, 10 Aug 2016 15:03:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DA7E28420; Wed, 10 Aug 2016 15:03:13 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 93AB02841A for ; Wed, 10 Aug 2016 15:03:11 +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 1bXUzX-0006Go-Lh; Wed, 10 Aug 2016 15:00:23 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bXUzW-0006GU-JG for xen-devel@lists.xenproject.org; Wed, 10 Aug 2016 15:00:22 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 6E/4A-03032-5814BA75; Wed, 10 Aug 2016 15:00:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsVyMfSas26r4+p wgxM7uSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oy9T+UKjmVV/P36hLGB8VhQFyMXh5DADEaJ B7s2sIM4LALNrBKde98xgjgSAv2sEkeOdjJ3MXICOTESB1a8YIewqyS+Nv1kAbGFBDQlDm44w wwxagKTRPeVE4wgCTYBI4mrV3vYQGwRASWJe6smM4EUMQt8YpS4uGoTWEJYwFvi87enTCA2i4 CqxMsWiKm8Al4Sjy6cZYHYJidxefoDsHpOoPrfB3cyQ2z2kjj3ajrTBEaBBYwMqxg1ilOLylK LdI3M9JKKMtMzSnITM3N0DQ1M9XJTi4sT01NzEpOK9ZLzczcxAoOrnoGBcQfj7cl+hxglOZiU RHm9VVeHC/El5adUZiQWZ8QXleakFh9ilOHgUJLg5XEAygkWpaanVqRl5gDDHCYtwcGjJMJrC 5LmLS5IzC3OTIdInWI05tjy+9paJo5tU++tZRJiycvPS5US5/UFKRUAKc0ozYMbBIu/S4yyUs K8jAwMDEI8BalFuZklqPKvGMU5GJWEeeNApvBk5pXA7XsFdAoT0ClJqitATilJREhJNTDO/nT QSawpYLfnqmv7b6q1mqSea+vs1MqafTKFb17lrMRnzTH7NL7r1nLf0P+yMLAnbGOXCU/g89LO N7X/9qrGruO8sWHSnjm7Or6fZGh/8igicNIW1dRkoYgDkxduSVo5zfzpv86Gf2cnykb92y90d n2cJne5mfPnuyYbClq6hBp+lTNdeBSmxFKckWioxVxUnAgAHn3+aroCAAA= X-Env-Sender: tamas.lengyel@zentific.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1470841220!17525033!1 X-Originating-IP: [209.85.214.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1663 invoked from network); 10 Aug 2016 15:00:20 -0000 Received: from mail-it0-f67.google.com (HELO mail-it0-f67.google.com) (209.85.214.67) by server-12.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 Aug 2016 15:00:20 -0000 Received: by mail-it0-f67.google.com with SMTP id j124so3190266ith.3 for ; Wed, 10 Aug 2016 08:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zentific-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DjwcTMbN4HEXBTfAKL852hnoaw3smp81F06hXmLjTn8=; b=BM3kL7vZ0uPi+uCNRj6WgWX5525SyucM6D3TNe++6S0wQYOOrNj1aDeSWSB+0C+m4M fAR7VE3pNE12wsnt51kxJXBp9/G41T7p5H/ciQNXGDew0Y+hduX6P97P7aBMtmUtxRJW aXC2SBu7W/wgzP0x+jy3IRI1HwHiA67FeUHDKzn5IaWSyvxp+URQkuWRmOZ4Cp16jJyC 9gLDEkwhg3AGWogC9YScLrVg4DLyPer9yU2tz37sodPtM3NLYNm46xJg8kydnFvj7biS BOZ5MiCnKw9dW2GA5FNbrVodOoXe5CceFqBxBVwt3px51nLmceWNSvouPxVO6MEEt+tH Isgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DjwcTMbN4HEXBTfAKL852hnoaw3smp81F06hXmLjTn8=; b=OQBI5fsXZxYfMHCTueUL6XvTH9gegPJaHLj0fuw4k1el7K07oYRs3rkW08IhspsuNW XuA9GOEINtgCp9fhL3QUks2pUTTKNJDYhLRPPY0O29Seuzfz7WjQ3fqWj22pEy5r/yke 7SfiO7WXwH6QyHH66IfkV/JWFCQnwVYq2HzjqoQnqgd3vaXhgiZ2mbxW8FnBqnk7OcT7 UzNFpzwwici1+SVoVhjZPucwP9XN28OT9hLGyiG9Fer1yy2u66y/0DPnvOqtfavh4Brn 5CWSONlCLO8lvHQhLFy8gPT+36LuF6FHpjvIGTCGgL8ZU35PPJFL2tm4j0BCAdwXEpb4 O05w== X-Gm-Message-State: AEkoouuPBW4OiRSIWc7yELHalsh0hLvBl9oQaAswbjXh7ByRWdIe4H6xcUAAr2Vm0K2hCg== X-Received: by 10.36.209.196 with SMTP id w187mr4035192itg.47.1470841219607; Wed, 10 Aug 2016 08:00:19 -0700 (PDT) Received: from l1.lan (c-73-14-35-59.hsd1.co.comcast.net. [73.14.35.59]) by smtp.gmail.com with ESMTPSA id b66sm4095916itd.0.2016.08.10.08.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Aug 2016 08:00:19 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 10 Aug 2016 09:00:15 -0600 Message-Id: <1470841215-24450-2-git-send-email-tamas.lengyel@zentific.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1470841215-24450-1-git-send-email-tamas.lengyel@zentific.com> References: <1470841215-24450-1-git-send-email-tamas.lengyel@zentific.com> Cc: Wei Liu , Tamas K Lengyel , Ian Jackson , Jan Beulich , Andrew Cooper , Daniel De Graaf Subject: [Xen-devel] [PATCH v2 2/2] x86/altp2m: allow specifying external-only use-case 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently setting altp2mhvm=1 in the domain configuration allows access to the altp2m interface for both in-guest and external privileged tools. This poses a problem for use-cases where only external access should be allowed, requiring the user to compile Xen with XSM enabled to be able to appropriately restrict access. In this patch we deprecate the altp2mhvm domain configuration option and introduce the altp2m option, which allows specifying if by default the altp2m interface should be external-only. The information is stored in HVM_PARAM_ALTP2M which we now define with specific XEN_ALTP2M_* modes. If external_only mode is selected, the XSM check is shifted to use XSM_DM_PRIV type check, thus restricting access to the interface by the guest itself. Note that we keep the default XSM policy untouched. Users of XSM who wish to enforce external_only mode for altp2m can do so by adjusting their XSM policy directly, as this domain config option does not override an active XSM policy. Also, as part of this patch we adjust the hvmop handler to require HVM_PARAM_ALTP2M to be of a type other then disabled for all ops. This has been previously only required for get/set altp2m domain state, all other options were gated on altp2m_enabled. Since altp2m_enabled only gets set during set altp2m domain state, this change introduces no new requirements to the other ops but makes it more clear that it is required for all ops. Signed-off-by: Tamas K Lengyel --- Cc: Ian Jackson Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: Daniel De Graaf v2: Rename HVMALTP2M_* to XEN_ALTP2M_* Relax xsm check to XSM_DM_PRIV for external-only mode --- docs/man/xl.cfg.pod.5.in | 31 +++++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 5 ++--- tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_types.idl | 9 ++++++++- tools/libxl/xl_cmdimpl.c | 34 +++++++++++++++++++++++++++++++++- xen/arch/x86/hvm/hvm.c | 20 ++++++++++---------- xen/include/public/hvm/params.h | 10 +++++++++- xen/include/xsm/dummy.h | 14 +++++++++++--- xen/include/xsm/xsm.h | 6 +++--- xen/xsm/flask/hooks.c | 2 +- 10 files changed, 109 insertions(+), 24 deletions(-) diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in index 48c9c0d..0044b98 100644 --- a/docs/man/xl.cfg.pod.5.in +++ b/docs/man/xl.cfg.pod.5.in @@ -1268,6 +1268,37 @@ enabled by default and you should usually omit it. It may be necessary to disable the HPET in order to improve compatibility with guest Operating Systems (X86 only) +=item B + +Specifies access mode to the alternate-p2m capability for hvm guests. +Alternate-p2m allows a guest to manage multiple p2m guest physical +"memory views" (as opposed to a single p2m). You may want this option +if you want to access-control/isolate access to specific guest physical +memory pages accessed by the guest, e.g. for HVM domain memory +introspection or for isolation/access-control of memory between +components within a single guest hvm domain. + +The valid values are as follows: + +=over 4 + +=item B<"disabled"> + +Altp2m is disabled for the domain (default). + +=item B<"mixed"> + +The mixed mode allows access to the altp2m interface for both in-guest +and external tools as well. + +=item B<"external_only"> + +Enables access to the alternate-p2m capability for hvm guests only +by external privileged tools. Note: if XSM is enabled then the XSM policy +should be used to specify external-only access to the interface. + +=back + =item B Enables or disables hvm guest access to alternate-p2m capability. diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 04f8ae9..c9076da 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -319,7 +319,6 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_defbool_setdefault(&b_info->u.hvm.hpet, true); libxl_defbool_setdefault(&b_info->u.hvm.vpt_align, true); libxl_defbool_setdefault(&b_info->u.hvm.nested_hvm, false); - libxl_defbool_setdefault(&b_info->u.hvm.altp2m, false); libxl_defbool_setdefault(&b_info->u.hvm.usb, false); libxl_defbool_setdefault(&b_info->u.hvm.xen_platform_pci, true); @@ -918,8 +917,8 @@ static void initiate_domain_create(libxl__egc *egc, if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM && (libxl_defbool_val(d_config->b_info.u.hvm.nested_hvm) && - libxl_defbool_val(d_config->b_info.u.hvm.altp2m))) { - LOG(ERROR, "nestedhvm and altp2mhvm cannot be used together"); + d_config->b_info.u.hvm.altp2m != LIBXL_ALTP2M_MODE_DISABLED)) { + LOG(ERROR, "nestedhvm and altp2m cannot be used together"); goto error_out; } diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index eef5045..0b8b2a8 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -292,7 +292,7 @@ static void hvm_set_conf_params(xc_interface *handle, uint32_t domid, xc_hvm_param_set(handle, domid, HVM_PARAM_NESTEDHVM, libxl_defbool_val(info->u.hvm.nested_hvm)); xc_hvm_param_set(handle, domid, HVM_PARAM_ALTP2M, - libxl_defbool_val(info->u.hvm.altp2m)); + info->u.hvm.altp2m); } int libxl__build_pre(libxl__gc *gc, uint32_t domid, diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index ef614be..97948fd 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -439,6 +439,13 @@ libxl_rdm_reserve = Struct("rdm_reserve", [ ("policy", libxl_rdm_reserve_policy), ]) +# Consistent with the values defined for HVM_PARAM_ALTP2M +libxl_altp2m_mode = Enumeration("altp2m_mode", [ + (0, "disabled"), + (1, "mixed"), + (2, "external_only"), + ], init_val = "LIBXL_ALTP2M_MODE_DISABLED") + libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap), @@ -512,7 +519,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("mmio_hole_memkb", MemKB), ("timer_mode", libxl_timer_mode), ("nested_hvm", libxl_defbool), - ("altp2m", libxl_defbool), + ("altp2m", libxl_altp2m_mode), ("smbios_firmware", string), ("acpi_firmware", string), ("hdtype", libxl_hdtype), diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 7f961e3..a655296 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1667,7 +1667,39 @@ static void parse_config_data(const char *config_source, xlu_cfg_get_defbool(config, "nestedhvm", &b_info->u.hvm.nested_hvm, 0); - xlu_cfg_get_defbool(config, "altp2mhvm", &b_info->u.hvm.altp2m, 0); + /* + * The config parameter "altp2mhvm" is considered deprecated, however + * further considered because of legacy reasons. The config parameter + * "altp2m" shall be used instead. + */ + if (!xlu_cfg_get_long(config, "altp2mhvm", &l, 0)) { + fprintf(stderr, "WARNING: Specifying \"altp2mhvm\" is deprecated. " + "Please use a \"altp2m\" instead.\n"); + + if (l < LIBXL_ALTP2M_MODE_DISABLED || + l > LIBXL_ALTP2M_MODE_MIXED) { + fprintf(stderr, "ERROR: invalid value %ld for \"altp2mhvm\"\n", l); + exit (1); + } + + b_info->u.hvm.altp2m = l; + } + + if (!xlu_cfg_get_long(config, "altp2m", &l, 0)) { + if (l < LIBXL_ALTP2M_MODE_DISABLED || + l > LIBXL_ALTP2M_MODE_EXTERNAL_ONLY) { + fprintf(stderr, "ERROR: invalid value %ld for \"altp2m\"\n", l); + exit (1); + } + + b_info->u.hvm.altp2m = l; + } else if (!xlu_cfg_get_string(config, "altp2m", &buf, 0)) { + if (libxl_altp2m_mode_from_string(buf, &b_info->u.hvm.altp2m)) { + fprintf(stderr, "ERROR: invalid value \"%s\" for \"altp2m\"\n", + buf); + exit (1); + } + } xlu_cfg_replace_string(config, "smbios_firmware", &b_info->u.hvm.smbios_firmware, 0); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 893eff6..0d59940 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5042,7 +5042,7 @@ static int hvmop_set_param( rc = xsm_hvm_param_altp2mhvm(XSM_PRIV, d); if ( rc ) break; - if ( a.value > 1 ) + if ( a.value > XEN_ALTP2M_external_only ) rc = -EINVAL; if ( a.value && d->arch.hvm_domain.params[HVM_PARAM_NESTEDHVM] ) @@ -5238,18 +5238,19 @@ static int do_altp2m_op( goto out; } - if ( (rc = xsm_hvm_altp2mhvm_op(XSM_TARGET, d)) ) + if ( !d->arch.hvm_domain.params[HVM_PARAM_ALTP2M] ) + { + rc = -EINVAL; + goto out; + } + + if ( (rc = xsm_hvm_altp2mhvm_op(XSM_OTHER, d, + d->arch.hvm_domain.params[HVM_PARAM_ALTP2M])) ) goto out; switch ( a.cmd ) { case HVMOP_altp2m_get_domain_state: - if ( !d->arch.hvm_domain.params[HVM_PARAM_ALTP2M] ) - { - rc = -EINVAL; - break; - } - a.u.domain_state.state = altp2m_active(d); rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; break; @@ -5259,8 +5260,7 @@ static int do_altp2m_op( struct vcpu *v; bool_t ostate; - if ( !d->arch.hvm_domain.params[HVM_PARAM_ALTP2M] || - nestedhvm_enabled(d) ) + if ( nestedhvm_enabled(d) ) { rc = -EINVAL; break; diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h index f7338a3..3ffc33b 100644 --- a/xen/include/public/hvm/params.h +++ b/xen/include/public/hvm/params.h @@ -225,8 +225,16 @@ /* Location of the VM Generation ID in guest physical address space. */ #define HVM_PARAM_VM_GENERATION_ID_ADDR 34 -/* Boolean: Enable altp2m */ +/* + * Set mode for altp2m: + * disabled: don't activate altp2m (default) + * mixed: allow access to altp2m for both in-guest and external tools + * external_only: allow access to external privileged tools only + */ #define HVM_PARAM_ALTP2M 35 +#define XEN_ALTP2M_disabled 0 +#define XEN_ALTP2M_mixed 1 +#define XEN_ALTP2M_external_only 2 /* * Size of the x87 FPU FIP/FDP registers that the hypervisor needs to diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 406cd18..a0f6b70 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -554,10 +554,18 @@ static XSM_INLINE int xsm_hvm_param_altp2mhvm(XSM_DEFAULT_ARG struct domain *d) return xsm_default_action(action, current->domain, d); } -static XSM_INLINE int xsm_hvm_altp2mhvm_op(XSM_DEFAULT_ARG struct domain *d) +static XSM_INLINE int xsm_hvm_altp2mhvm_op(XSM_DEFAULT_ARG struct domain *d, int mode) { - XSM_ASSERT_ACTION(XSM_TARGET); - return xsm_default_action(action, current->domain, d); + XSM_ASSERT_ACTION(XSM_OTHER); + switch ( mode ) + { + case XEN_ALTP2M_mixed: + return xsm_default_action(XSM_TARGET, current->domain, d); + case XEN_ALTP2M_external_only: + return xsm_default_action(XSM_DM_PRIV, current->domain, d); + default: + return -EPERM; + }; } static XSM_INLINE int xsm_vm_event_control(XSM_DEFAULT_ARG struct domain *d, int mode, int op) diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 5dc59dd..4f53b27 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -140,7 +140,7 @@ struct xsm_operations { int (*hvm_control) (struct domain *d, unsigned long op); int (*hvm_param_nested) (struct domain *d); int (*hvm_param_altp2mhvm) (struct domain *d); - int (*hvm_altp2mhvm_op) (struct domain *d); + int (*hvm_altp2mhvm_op) (struct domain *d, int mode); int (*get_vnumainfo) (struct domain *d); int (*vm_event_control) (struct domain *d, int mode, int op); @@ -583,9 +583,9 @@ static inline int xsm_hvm_param_altp2mhvm (xsm_default_t def, struct domain *d) return xsm_ops->hvm_param_altp2mhvm(d); } -static inline int xsm_hvm_altp2mhvm_op (xsm_default_t def, struct domain *d) +static inline int xsm_hvm_altp2mhvm_op (xsm_default_t def, struct domain *d, int mode) { - return xsm_ops->hvm_altp2mhvm_op(d); + return xsm_ops->hvm_altp2mhvm_op(d, mode); } static inline int xsm_get_vnumainfo (xsm_default_t def, struct domain *d) diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index ec6f5b4..b97396e 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1197,7 +1197,7 @@ static int flask_hvm_param_altp2mhvm(struct domain *d) return current_has_perm(d, SECCLASS_HVM, HVM__ALTP2MHVM); } -static int flask_hvm_altp2mhvm_op(struct domain *d) +static int flask_hvm_altp2mhvm_op(struct domain *d, int mode) { return current_has_perm(d, SECCLASS_HVM, HVM__ALTP2MHVM_OP); }