From patchwork Thu Mar 19 19:29:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46114 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DF1F921515 for ; Thu, 19 Mar 2015 19:33:09 +0000 (UTC) Received: by widex7 with SMTP id ex7sf14619770wid.2 for ; Thu, 19 Mar 2015 12:33:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=GgbnBeO6miFUpP0o5UG/p7KrYLPCVrhttZxQUkMsVg0=; b=CewtfQXUFUaXp+WvxeHExo9i8wWxQShCBuqCJR7Rxewez31ALrVOncrZkx031GPKen Z6TmaU0NhPARBkn0loqL0zaKRutp62fhdWq9OXHw0QIu2lM4h7SkRO1pI2PL8gew9BwE yblMmEOvxRFU2j1798UXXwXNFDP5PlyleUOaHWkx7XVsbNcEGt9bsTrf7zn9EhBNcSQM OcTFgYV5Wsu/LPshtADZm50bTsvOhVVvUf79b3GVLdHb73UMzmRN21PoPo49RZerKdmB 8XDANXkHTCtWPw7EMih7KzaOmWMEA3y2BmpVpVnAoGi6T7ZOtAhjRddRKVfeDO7o03QN eIEQ== X-Gm-Message-State: ALoCoQkTCMhnU9vIcbWzTfkg7j2RnhHQLtfUdddJ9o80n1q2Px8kjCAVUW2Fim9Vg7ymSXILZjZd X-Received: by 10.180.80.132 with SMTP id r4mr2064962wix.4.1426793589241; Thu, 19 Mar 2015 12:33:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.140 with SMTP id ay12ls386951lab.2.gmail; Thu, 19 Mar 2015 12:33:08 -0700 (PDT) X-Received: by 10.152.180.202 with SMTP id dq10mr67622377lac.74.1426793588878; Thu, 19 Mar 2015 12:33:08 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id z5si1644749lbf.103.2015.03.19.12.33.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:33:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbnq5 with SMTP id q5so32346432lbn.0 for ; Thu, 19 Mar 2015 12:33:08 -0700 (PDT) X-Received: by 10.152.5.194 with SMTP id u2mr70341483lau.88.1426793588768; Thu, 19 Mar 2015 12:33:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp597946lbj; Thu, 19 Mar 2015 12:33:07 -0700 (PDT) X-Received: by 10.55.17.222 with SMTP id 91mr124022939qkr.17.1426793567095; Thu, 19 Mar 2015 12:32:47 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id d79si2244567qhc.7.2015.03.19.12.32.46 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:47 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYgA3-00058j-0c; Thu, 19 Mar 2015 19:31:19 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYgA1-00054i-RO for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:31:18 +0000 Received: from [193.109.254.147] by server-2.bemta-14.messagelabs.com id B4/17-30447-5042B055; Thu, 19 Mar 2015 19:31:17 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-9.tower-27.messagelabs.com!1426793476!14396244!1 X-Originating-IP: [209.85.212.170] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1536 invoked from network); 19 Mar 2015 19:31:16 -0000 Received: from mail-wi0-f170.google.com (HELO mail-wi0-f170.google.com) (209.85.212.170) by server-9.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:31:16 -0000 Received: by wibdy8 with SMTP id dy8so126871070wib.0 for ; Thu, 19 Mar 2015 12:31:16 -0700 (PDT) X-Received: by 10.194.78.231 with SMTP id e7mr151506599wjx.33.1426793475350; Thu, 19 Mar 2015 12:31:15 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.31.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:31:14 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:51 +0000 Message-Id: <1426793399-6283-26-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Daniel De Graaf , Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v4 25/33] xen/xsm: Add helpers to check permission for device tree passthrough X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This is a follow-up of commit 525ee49 "xsm: add device tree labeling support" which add support for device tree labelling in flask. Those helpers will be use latter when non-pci passthrough (i.e device tree) will be added. Signed-off-by: Julien Grall Cc: Daniel De Graaf --- Changes in v4: - Patch added --- xen/include/xsm/dummy.h | 23 +++++++++++++ xen/include/xsm/xsm.h | 27 +++++++++++++++ xen/xsm/dummy.c | 6 ++++ xen/xsm/flask/avc.c | 3 ++ xen/xsm/flask/hooks.c | 69 ++++++++++++++++++++++++++++++++++++- xen/xsm/flask/include/avc.h | 2 ++ xen/xsm/flask/policy/access_vectors | 2 +- 7 files changed, 130 insertions(+), 2 deletions(-) diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index da414c7..8157252 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -350,6 +350,29 @@ static XSM_INLINE int xsm_deassign_device(XSM_DEFAULT_ARG struct domain *d, uint #endif /* HAS_PASSTHROUGH && HAS_PCI */ +#if defined(HAS_PASSTHROUGH) && defined(HAS_DEVICE_TREE) +static XSM_INLINE int xsm_test_assign_dtdevice(XSM_DEFAULT_ARG const char *dtpath) +{ + XSM_ASSERT_ACTION(XSM_HOOK); + return xsm_default_action(action, current->domain, NULL); +} + +static XSM_INLINE int xsm_assign_dtdevice(XSM_DEFAULT_ARG struct domain *d, + const char *dtpath) +{ + XSM_ASSERT_ACTION(XSM_HOOK); + return xsm_default_action(action, current->domain, d); +} + +static XSM_INLINE int xsm_deassign_dtdevice(XSM_DEFAULT_ARG struct domain *d, + const char *dtpath) +{ + XSM_ASSERT_ACTION(XSM_HOOK); + return xsm_default_action(action, current->domain, d); +} + +#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE */ + static XSM_INLINE int xsm_resource_plug_core(XSM_DEFAULT_VOID) { XSM_ASSERT_ACTION(XSM_HOOK); diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 99a59d0..a0eaaa1 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -121,6 +121,12 @@ struct xsm_operations { int (*deassign_device) (struct domain *d, uint32_t machine_bdf); #endif +#if defined(HAS_PASSTHROUGH) && defined(HAS_DEVICE_TREE) + int (*test_assign_dtdevice) (const char *dtpath); + int (*assign_dtdevice) (struct domain *d, const char *dtpath); + int (*deassign_dtdevice) (struct domain *d, const char *dtpath); +#endif + int (*resource_plug_core) (void); int (*resource_unplug_core) (void); int (*resource_plug_pci) (uint32_t machine_bdf); @@ -473,6 +479,27 @@ static inline int xsm_deassign_device(xsm_default_t def, struct domain *d, uint3 } #endif /* HAS_PASSTHROUGH && HAS_PCI) */ +#if defined(HAS_PASSTHROUGH) && defined(HAS_DEVICE_TREE) +static inline int xsm_assign_dtdevice(xsm_default_t def, struct domain *d, + const char *dtpath) +{ + return xsm_ops->assign_dtdevice(d, dtpath); +} + +static inline int xsm_test_assign_dtdevice(xsm_default_t def, + const char *dtpath) +{ + return xsm_ops->test_assign_dtdevice(dtpath); +} + +static inline int xsm_deassign_dtdevice(xsm_default_t def, struct domain *d, + const char *dtpath) +{ + return xsm_ops->deassign_dtdevice(d, dtpath); +} + +#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE */ + static inline int xsm_resource_plug_pci (xsm_default_t def, uint32_t machine_bdf) { return xsm_ops->resource_plug_pci(machine_bdf); diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index b69a019..cd88e76 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -96,6 +96,12 @@ void xsm_fixup_ops (struct xsm_operations *ops) set_to_dummy_if_null(ops, deassign_device); #endif +#if defined(HAS_PASSTHROUGH) && defined(HAS_DEVICE_TREE) + set_to_dummy_if_null(ops, test_assign_dtdevice); + set_to_dummy_if_null(ops, assign_dtdevice); + set_to_dummy_if_null(ops, deassign_dtdevice); +#endif + set_to_dummy_if_null(ops, resource_plug_core); set_to_dummy_if_null(ops, resource_unplug_core); set_to_dummy_if_null(ops, resource_plug_pci); diff --git a/xen/xsm/flask/avc.c b/xen/xsm/flask/avc.c index b1a4f8a..31bc702 100644 --- a/xen/xsm/flask/avc.c +++ b/xen/xsm/flask/avc.c @@ -600,6 +600,9 @@ void avc_audit(u32 ssid, u32 tsid, u16 tclass, u32 requested, case AVC_AUDIT_DATA_MEMORY: avc_printk(&buf, "pte=%#lx mfn=%#lx ", a->memory.pte, a->memory.mfn); break; + case AVC_AUDIT_DATA_DTDEV: + avc_printk(&buf, "dtdevice=%s ", a->dtdev); + break; } avc_dump_query(&buf, ssid, tsid, tclass); diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index e1cc16a..9652034 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -589,7 +589,12 @@ static int flask_domctl(struct domain *d, int cmd) case XEN_DOMCTL_shadow_op: case XEN_DOMCTL_ioport_permission: case XEN_DOMCTL_ioport_mapping: - /* These have individual XSM hooks (drivers/passthrough/iommu.c) */ +#endif +#ifdef HAS_PASSTHROUGH + /* + * These have individual XSM hooks + * (drivers/passthrough/{pci,device_tree.c) + */ case XEN_DOMCTL_get_device_group: case XEN_DOMCTL_test_assign_device: case XEN_DOMCTL_assign_device: @@ -1231,6 +1236,62 @@ static int flask_deassign_device(struct domain *d, uint32_t machine_bdf) } #endif /* HAS_PASSTHROUGH && HAS_PCI */ +#if defined(HAS_PASSTHROUGH) && defined(HAS_DEVICE_TREE) +static int flask_test_assign_dtdevice(const char *dtpath) +{ + u32 rsid; + int rc = -EPERM; + + rc = security_devicetree_sid(dtpath, &rsid); + if ( rc ) + return rc; + + return avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__STAT_DEVICE, + NULL); +} + +static int flask_assign_dtdevice(struct domain *d, const char *dtpath) +{ + u32 dsid, rsid; + int rc = -EPERM; + struct avc_audit_data ad; + + rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD); + if ( rc ) + return rc; + + rc = security_devicetree_sid(dtpath, &rsid); + if ( rc ) + return rc; + + AVC_AUDIT_DATA_INIT(&ad, DTDEV); + ad.dtdev = dtpath; + rc = avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__ADD_DEVICE, &ad); + if ( rc ) + return rc; + + dsid = domain_sid(d); + return avc_has_perm(dsid, rsid, SECCLASS_RESOURCE, RESOURCE__USE, &ad); +} + +static int flask_deassign_dtdevice(struct domain *d, const char *dtpath) +{ + u32 rsid; + int rc = -EPERM; + + rc = current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE); + if ( rc ) + return rc; + + rc = security_devicetree_sid(dtpath, &rsid); + if ( rc ) + return rc; + + return avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__REMOVE_DEVICE, + NULL); +} +#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE */ + #ifdef HAS_MEM_ACCESS static int flask_mem_event_control(struct domain *d, int mode, int op) { @@ -1598,6 +1659,12 @@ static struct xsm_operations flask_ops = { .deassign_device = flask_deassign_device, #endif +#if defined(HAS_PASSTHROUGH) && defined(HAS_DEVICE_TREE) + .test_assign_dtdevice = flask_test_assign_dtdevice, + .assign_dtdevice = flask_assign_dtdevice, + .deassign_dtdevice = flask_deassign_dtdevice, +#endif + #ifdef HAS_MEM_ACCESS .mem_event_control = flask_mem_event_control, .mem_event_op = flask_mem_event_op, diff --git a/xen/xsm/flask/include/avc.h b/xen/xsm/flask/include/avc.h index c7a99fc..4283562 100644 --- a/xen/xsm/flask/include/avc.h +++ b/xen/xsm/flask/include/avc.h @@ -39,6 +39,7 @@ struct avc_audit_data { #define AVC_AUDIT_DATA_IRQ 2 #define AVC_AUDIT_DATA_RANGE 3 #define AVC_AUDIT_DATA_MEMORY 4 +#define AVC_AUDIT_DATA_DTDEV 5 struct domain *sdom; struct domain *tdom; union { @@ -52,6 +53,7 @@ struct avc_audit_data { unsigned long pte; unsigned long mfn; } memory; + const char *dtdev; }; }; diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors index 3451f8f..739d62d 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -416,7 +416,7 @@ class resource remove_iomem # XEN_DOMCTL_get_device_group, XEN_DOMCTL_test_assign_device: # source = domain making the hypercall -# target = PCI device being queried +# target = device being queried stat_device # XEN_DOMCTL_assign_device add_device