From patchwork Mon May 23 15:05:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel De Graaf X-Patchwork-Id: 9131977 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 48CDB60761 for ; Mon, 23 May 2016 15:08:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EED9200F4 for ; Mon, 23 May 2016 15:08:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 332332822F; Mon, 23 May 2016 15:08:23 +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 6EA05200F4 for ; Mon, 23 May 2016 15:08:22 +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 1b4rQk-0000wq-U7; Mon, 23 May 2016 15:06:06 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b4rQj-0000wP-OE for xen-devel@lists.xenproject.org; Mon, 23 May 2016 15:06:05 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id BC/30-26575-D5C13475; Mon, 23 May 2016 15:06:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeJIrShJLcpLzFFi42Lh0Enl1I2RcQ4 32LlLzOL7lslMDowehz9cYQlgjGLNzEvKr0hgzdg46xFLwbGQis5P3YwNjCs9uhg5OSQE/CSe PD/BBmJzCuxhkehdz9PFyAUUP84oMWXyOlaQhJDAUkaJxm38IAkhgW2MEgefL2ECSbAJ6EosO LgSzBYRUJK4t2oymM0sUCRxefUiMFtYIFSi/fpTsA0sAqoSe5Z0gcV5BVwl2j+8YoW4Qk5i25 Y9jBBXuEnM3j8NyOYAWuYqMWWa8gRGvgWMDKsY1YtTi8pSi3SN9ZKKMtMzSnITM3N0DQ1M9XJ Ti4sT01NzEpOK9ZLzczcxAoOEAQh2MO7953SIUZKDSUmU9+QOp3AhvqT8lMqMxOKM+KLSnNTi Q4wyHBxKErxvpJzDhQSLUtNTK9Iyc4DhCpOW4OBREuH9A5LmLS5IzC3OTIdInWI05tiy4MZaJ o43C4GkEEtefl6qlDivoDRQqQBIaUZpHtwgWBxdYpSVEuZlBDpNiKcgtSg3swRV/hWjOAejkj CvG8gUnsy8Erh9r4BOYQI65aG0A8gpJYkIKakGxkDDj7qRygZ/UqebCOgv8ql0KJrf2uizcOH Jx+tWWtwM6Na+G3wq6ozUzy/SRivUTwQwXDq27zP33sL/EiHfhAyknK6m5Ok7bn+tJvPk7et3 sceinH9/4tm9fBNb4tk/jGtZTjDNnv1aeL9SWW34s3db7Bkn8Pst8gsUZF4sUKM14bgpR0ffB yWW4oxEQy3mouJEAKoyKZmeAgAA X-Env-Sender: dgdegra@tycho.nsa.gov X-Msg-Ref: server-15.tower-206.messagelabs.com!1464015962!29076698!2 X-Originating-IP: [8.44.101.9] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9703 invoked from network); 23 May 2016 15:06:04 -0000 Received: from emsm-gh1-uea11.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) (8.44.101.9) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 May 2016 15:06:04 -0000 X-IronPort-AV: E=Sophos;i="5.26,356,1459814400"; d="scan'208";a="16352619" IronPort-PHdr: =?us-ascii?q?9a23=3ArxaLUxCBWN1X7LYfHjduUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP79r8bcNUDSrc9gkEXOFd2CrakU2qyN4uu/BiQp2tWojjMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3Dwdp?= =?us-ascii?q?POO9QteU1JTmkbvjsMKMKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu?= =?us-ascii?q?5NznlpL1/A1zz158O34YIxu38I46FpytREGZneU+x4COYATWduD2dg9MDt8BXO?= =?us-ascii?q?UwaLzn8dSXkN1ApFBRDf6xP3VYu3tTH15cRn3yzPEcTwTL0wERivp4hxQRbmwH?= =?us-ascii?q?MLODI0/3veotBhh6Jc5hS6rlpwxJCCM9LdD+Z3Yq6IJYBSfmFGRMsEEnYZDw?= =?us-ascii?q?=3D=3D?= X-IPAS-Result: =?us-ascii?q?A2FeBADyG0NX/wHyM5BTCRsBAYMagVO3cYQUhhECgS9MAQE?= =?us-ascii?q?BAQEBAgJiJ4ItghYCBHkQGDlXGYgvxHoBAQEHAgEkjwwDhX4FiASFYYpSiHiFK?= =?us-ascii?q?AKJVoVEj0xihAkgMogTgT4BAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2016 15:05:38 +0000 Received: from moss-nexus.infosec.tycho.ncsc.mil (moss-nexus [192.168.25.48]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u4NF5YU6020519; Mon, 23 May 2016 11:05:37 -0400 From: Daniel De Graaf To: xen-devel@lists.xenproject.org Date: Mon, 23 May 2016 11:05:30 -0400 Message-Id: <1464015933-26891-3-git-send-email-dgdegra@tycho.nsa.gov> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464015933-26891-1-git-send-email-dgdegra@tycho.nsa.gov> References: <1464015933-26891-1-git-send-email-dgdegra@tycho.nsa.gov> Cc: steve@zentific.com, Daniel De Graaf , cardoe@cardoe.com Subject: [Xen-devel] [PATCH 2/5] flask/policy: move user definitions and constraints into modules 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 This also renames the example users created by vm_role. Signed-off-by: Daniel De Graaf --- docs/misc/xsm-flask.txt | 34 +++++++++++----------- tools/flask/policy/Makefile | 9 ++++-- tools/flask/policy/modules/default_role.te | 5 ---- tools/flask/policy/modules/modules.conf | 10 ++++++- .../{policy/constraints => modules/vm_role.cons} | 6 ++-- tools/flask/policy/modules/vm_role.te | 16 ++++++++++ tools/flask/policy/modules/xen.te | 9 ++++-- tools/flask/policy/policy/support/misc_macros.spt | 6 ++-- tools/flask/policy/policy/users | 12 +------- 9 files changed, 63 insertions(+), 44 deletions(-) rename tools/flask/policy/{policy/constraints => modules/vm_role.cons} (78%) create mode 100644 tools/flask/policy/modules/vm_role.te diff --git a/docs/misc/xsm-flask.txt b/docs/misc/xsm-flask.txt index d3015ca..2f42585 100644 --- a/docs/misc/xsm-flask.txt +++ b/docs/misc/xsm-flask.txt @@ -147,9 +147,11 @@ it relies on the SELinux compiler "checkpolicy"; run make -C tools/flask/policy to compile the example policy included with Xen. The policy is generated from -definition files under this directory. When creating or modifying security -policy, most modifications will be made to the xen type enforcement (.te) file -tools/flask/policy/policy/modules/xen/xen.te or the macro definitions in xen.if. +definition files under this directory. Most changes to security policy will +involve creating or modifying modules found in tools/flask/policy/modules/. The +modules.conf file there defines what modules are enabled and has short +descriptions of each module. + The XSM policy file needs to be copied to /boot and loaded as a module by grub. The exact position of the module does not matter as long as it is after the Xen kernel; it is normally placed either just above the dom0 kernel or at the end. @@ -210,17 +212,16 @@ Type transitions are also used to compute the labels of event channels. Users and roles --------------- -Users are defined in tools/flask/policy/policy/users. The example policy defines -two users (customer_1 and customer_2) in addition to the system user system_u. -Users are visible in the labels of domains and associated objects (event -channels); in the example policy, "customer_1:vm_r:domU_t" is a valid label for -the customer_1 user. +The default user and role used for domains is system_u and system_r. Users are +visible in the labels of domains and associated objects (event channels); when +the vm_role module is enabled, "user_1:vm_r:domU_t" is a valid label for a +domain created by the user_1 user. -Access control rules involving users and roles are defined in the policy -constraints file (tools/flask/policy/policy/constraints). The example policy -provides constraints that prevent different users from communicating using -grants or event channels, while still allowing communication with the system_u -user where dom0 resides. +Access control rules involving users and roles are defined in a module's +constraints file (for example, vm_rule.cons). The vm_role module defines one +role (vm_r) and three users (user_1 .. user_3), along with constraints that +prevent different users from communicating using grants or event channels, while +still allowing communication with the system_u user where dom0 resides. Resource Policy --------------- @@ -268,10 +269,9 @@ declare_domain and create_domain interfaces: Existing SELinux tools such as audit2allow can be applied to these denials, e.g. xl dmesg | audit2allow -The generated allow rules can then be fed back into the policy by -adding them to xen.te, although manual review is advised and will -often lead to adding parameterized rules to the interfaces in xen.if -to address the general case. +The generated allow rules can then be fed back into the policy by adding them to +a module, although manual review is advised and will often lead to adding +parameterized rules to the interfaces in xen.if to address the general case. Device Labeling in Policy diff --git a/tools/flask/policy/Makefile b/tools/flask/policy/Makefile index b2c2d06..693eb10 100644 --- a/tools/flask/policy/Makefile +++ b/tools/flask/policy/Makefile @@ -54,7 +54,6 @@ AVS += $(POLDIR)/access_vectors M4SUPPORT := $(wildcard $(POLDIR)/support/*.spt) MLSSUPPORT := $(POLDIR)/mls USERS := $(POLDIR)/users -CONSTRAINTS := $(POLDIR)/constraints ISID_DEFS := $(POLDIR)/initial_sids DEV_OCONS := $(POLDIR)/device_contexts @@ -90,8 +89,12 @@ MODENABLED := on # extract settings from modules.conf ENABLED_LIST := $(shell awk '/^[ \t]*[a-z]/{ if ($$3 == "$(MODENABLED)") print $$1 }' $(MOD_CONF) 2> /dev/null) +# Modules must provide a .te file, although it could be empty ALL_MODULES := $(foreach mod,$(ENABLED_LIST),$(MODDIR)/$(mod).te) + +# Modules may also provide interfaces and constraint definitions ALL_INTERFACES := $(wildcard $(ALL_MODULES:.te=.if)) +ALL_CONSTRAINTS := $(wildcard $(ALL_MODULES:.te=.cons)) # The order of these files is important POLICY_SECTIONS := $(SECCLASS) $(ISID_DECLS) $(AVS) @@ -99,7 +102,9 @@ POLICY_SECTIONS += $(M4SUPPORT) $(MLSSUPPORT) POLICY_SECTIONS += $(ALL_INTERFACES) POLICY_SECTIONS += $(GLOBALTUN) POLICY_SECTIONS += $(ALL_MODULES) -POLICY_SECTIONS += $(USERS) $(CONSTRAINTS) $(ISID_DEFS) $(DEV_OCONS) +POLICY_SECTIONS += $(USERS) +POLICY_SECTIONS += $(ALL_CONSTRAINTS) +POLICY_SECTIONS += $(ISID_DEFS) $(DEV_OCONS) all: $(POLICY_FILENAME) diff --git a/tools/flask/policy/modules/default_role.te b/tools/flask/policy/modules/default_role.te index 74f870f..3018540 100644 --- a/tools/flask/policy/modules/default_role.te +++ b/tools/flask/policy/modules/default_role.te @@ -1,8 +1,3 @@ # Allow all domains to use system_r so that systems that are not using the # user/role separation feature will work properly. role system_r types domain_type; - -# The vm role is used as part of user separation. Allow all domain types to use -# this role except dom0. -role vm_r; -role vm_r types { domain_type -dom0_t }; diff --git a/tools/flask/policy/modules/modules.conf b/tools/flask/policy/modules/modules.conf index 5a1d905..2dfc011 100644 --- a/tools/flask/policy/modules/modules.conf +++ b/tools/flask/policy/modules/modules.conf @@ -33,5 +33,13 @@ nomigrate = on # Example device policy. Also see policy/device_contexts. nic_dev = on -# Example roles. Also see policy/users. +# Allow all domains to use system_u:system_r: instead of requiring explicit +# roles. This is not required for dom0_t, domU_t, and dm_dom_t. default_role = on + +# Example users, roles, and constraints for user-based separation. +# +# The three users defined here can set up grant/event channel communication +# (vchan, device frontend/backend) between their own VMs, but cannot set up a +# channel to a VM under a different user. +vm_role = on diff --git a/tools/flask/policy/policy/constraints b/tools/flask/policy/modules/vm_role.cons similarity index 78% rename from tools/flask/policy/policy/constraints rename to tools/flask/policy/modules/vm_role.cons index 765ed4d..3847ec1 100644 --- a/tools/flask/policy/policy/constraints +++ b/tools/flask/policy/modules/vm_role.cons @@ -1,6 +1,5 @@ - # -# Define the constraints +# Constraints are defined by: # # constrain class_set perm_set expression ; # @@ -25,8 +24,9 @@ # name_list : name | name_list name # -# Prevent event channels and grants between different customers +# Prevent event channels and grants between different users. This could be +# further limited to only restricting those domains using the vm_r role. constrain event bind ( u1 == system_u or u2 == system_u or diff --git a/tools/flask/policy/modules/vm_role.te b/tools/flask/policy/modules/vm_role.te new file mode 100644 index 0000000..f816de1 --- /dev/null +++ b/tools/flask/policy/modules/vm_role.te @@ -0,0 +1,16 @@ +# The vm role is used as part of user separation. Allow all domain types to use +# this role except dom0. +role vm_r; +role vm_r types { domain_type -dom0_t }; + +# Define some users that must use this role (full type "user_1:vm_r:domU_t"). +gen_user(user_1,, vm_r, s0, s0) +gen_user(user_2,, vm_r, s0, s0) +gen_user(user_3,, vm_r, s0, s0) + +# Alternate: define and use a macro to generate 1000 users +define(`def_vm_users',`gen_user(user_$1,, vm_r, s0, s0) +ifelse(`$1',`$2',,`def_vm_users(incr($1),$2)')dnl +') + +# def_vm_users(0,999) diff --git a/tools/flask/policy/modules/xen.te b/tools/flask/policy/modules/xen.te index f374dc5..b52edc2 100644 --- a/tools/flask/policy/modules/xen.te +++ b/tools/flask/policy/modules/xen.te @@ -71,14 +71,17 @@ neverallow * ~event_type:event { create send status }; ################################################################################ # -# Roles +# Users and Roles # ################################################################################ # The object role (object_r) is used for devices, resources, and event channels; # it does not need to be defined here and should not be used for domains. -# The system role is used for utility domains and pseudo-domains. If roles are -# not being used for separation, all domains can use the system role. +# The system user and role are used for utility domains and pseudo-domains. In +# systems where users and roles are not being used for separation, all domains +# can use the system user and role. +gen_user(system_u,, system_r, s0, s0 - mls_systemhigh) + role system_r; role system_r types { xen_type dom0_t }; diff --git a/tools/flask/policy/policy/support/misc_macros.spt b/tools/flask/policy/policy/support/misc_macros.spt index 2b27955..344f5c4 100644 --- a/tools/flask/policy/policy/support/misc_macros.spt +++ b/tools/flask/policy/policy/support/misc_macros.spt @@ -49,9 +49,11 @@ define(`refpolicyerr',`errprint(__file__:__line__: Error: `$1'__endline__)') # # gen_user(username, prefix, role_set, mls_defaultlevel, mls_range) # -define(`gen_user',`dnl +define(`gen_user',`define(`gen_all_users', gen_all_users `dnl user $1 roles { $3 }`'ifdef(`enable_mls', ` level $4 range $5')`'; -') +')') + +define(`gen_all_users',`') ######################################## # diff --git a/tools/flask/policy/policy/users b/tools/flask/policy/policy/users index 35ed8a9..af6acbd 100644 --- a/tools/flask/policy/policy/users +++ b/tools/flask/policy/policy/users @@ -1,11 +1 @@ -################################## -# -# System User configuration. -# - -# system_u is the user identity for system domains and objects -gen_user(system_u,, system_r, s0, s0 - mls_systemhigh) - -# Other users are defined using the vm role -gen_user(customer_1,, vm_r, s0, s0) -gen_user(customer_2,, vm_r, s0, s0) +gen_all_users()