Skip to contentSkip to conversation

refpolicy: Infiniband pkeys and endports

PATCH New Dan Jurgens 2 participants 5 messages May 17, 2017 – May 23, 2017 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 refpolicy: Infiniband pkeys and endports

From: Daniel Jurgens <[email protected]>

Every Infiniband network will have a default pkey, so that is labeled. The rest of the pkey configuration is network specific. The policy allows access to the default and unlabeled pkeys for sysadm and staff users. kernel_t is allowed access to all pkeys, which it needs to process and route management datagrams.

Endports are all unlabeled by default, sysadm users are allowed to manage the subnet on unlabeled endports. kernel_t is allowed to manage the subnet on all ibendports, which is required for configuring the HCA.

This patch requires selinux series: "SELinux user space support for Infiniband RDMA", due to the new ipkeycon labeling mechanism.

---
 Makefile                                |   2 +-
 Rules.modular                           |   2 +
 Rules.monolithic                        |   2 +
 policy/flask/access_vectors             |  10 ++
 policy/flask/security_classes           |   4 +
 policy/modules/kernel/corenetwork.if.in | 156 ++++++++++++++++++++++++++++++++
 policy/modules/kernel/corenetwork.if.m4 |  64 +++++++++++++
 policy/modules/kernel/corenetwork.te.in |  17 ++++
 policy/modules/kernel/corenetwork.te.m4 |  26 ++++++
 policy/modules/kernel/kernel.te         |   5 +
 policy/modules/roles/staff.te           |   5 +
 policy/modules/roles/sysadm.te          |   6 ++
 support/comment_move_decl.sed           |   2 +-
 13 files changed, 299 insertions(+), 2 deletions(-)
Makefile +1 -1
index d19985eb..b4b2d43a 100644
@@ -370,7 +370,7 @@ $(moddir)/kernel/corenetwork.if: $(moddir)/kernel/corenetwork.te.in $(moddir)/ke
 	@echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
 	@echo "#" >> $@
 	$(verbose) cat [email protected] >> $@
-	$(verbose) $(GREP) "^[[:blank:]]*network_(interface|node|port|packet)(_controlled)?\(.*\)" $< \
+	$(verbose) $(GREP) "^[[:blank:]]*(network_(interface|node|port|packet)(_controlled)?)|ib_(pkey|endport)\(.*\)" $< \
 		| $(M4) -D self_contained_policy $(M4PARAM) $(m4divert) [email protected] $(m4undivert) - \
 		| $(SED) -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
 
Rules.modular +2 -0
index 49d3cca9..331a979d 100644
@@ -170,6 +170,8 @@ $(tmpdir)/all_post.conf: $(tmpdir)/all_te_files.conf $(tmpdir)/post_te_files.con
 	$(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibpkeycon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibendportcon $(tmpdir)/all_te_files.conf >> $@ || true
 
 $(tmpdir)/only_te_rules.conf: $(tmpdir)/all_te_files.conf
 	$(verbose) $(comment_move_decl) $^ > $@
Rules.monolithic +2 -0
index ce112d78..80e00821 100644
@@ -150,6 +150,8 @@ $(tmpdir)/all_post.conf: $(tmpdir)/all_te_files.conf $(tmpdir)/post_te_files.con
 	$(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibpkeycon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibendportcon $(tmpdir)/all_te_files.conf >> $@ || true
 
 $(tmpdir)/only_te_rules.conf: $(tmpdir)/all_te_files.conf
 	$(verbose) $(comment_move_decl) $^ > $@
policy/flask/access_vectors +10 -0
index 69f69af8..520a3c28 100644
@@ -926,6 +926,16 @@ inherits database
 	set_value
 }
 
+class infiniband_pkey
+{
+	access
+}
+
+class infiniband_endport
+{
+	manage_subnet
+}
+
 class db_language
 inherits database
 {
policy/flask/security_classes +4 -0
index 18f18fd8..393621bf 100644
@@ -139,6 +139,10 @@ class netlink_crypto_socket
 class x_pointer			# userspace
 class x_keyboard		# userspace
 
+# Infiniband
+class infiniband_pkey
+class infiniband_endport
+
 # More Database stuff
 class db_schema			# userspace
 class db_view			# userspace
policy/modules/kernel/corenetwork.if.in +156 -0

159 lines not on this page · raw message

policy/modules/kernel/corenetwork.if.m4 +64 -0

73 lines not on this page · raw message

policy/modules/kernel/corenetwork.te.in +17 -0
index 1ca96d38..bc8ee090 100644
@@ -16,6 +16,8 @@ attribute port_type;
 attribute reserved_port_type;
 attribute rpc_port_type;
 attribute server_packet_type;
+attribute ibpkey_type;
+attribute ibendport_type;
 # This is an optimization for { port_type -reserved_port_type }
 attribute unreserved_port_type;
 
@@ -346,6 +348,15 @@ typealias netif_t alias { lo_netif_t netif_lo_t };
 
 ########################################
 #
+# Infiniband Pkeys
+#
+#
+# unlabeled_t is the default type of infiniband pkeys.
+#
+ib_pkey(default, fe80::,0xFFFF,s1)
+
+########################################
+#
 # Unconfined access to this module
 #
 
@@ -358,3 +369,9 @@ allow corenet_unconfined_type port_type:udp_socket { send_msg recv_msg };
 # Bind to any network address.
 allow corenet_unconfined_type port_type:{ tcp_socket udp_socket rawip_socket } name_bind;
 allow corenet_unconfined_type node_type:{ tcp_socket udp_socket rawip_socket } node_bind;
+
+# Infiniband
+optional_policy(`
+	corenet_ibpkey_access_all_pkeys(corenet_unconfined_type)
+	corenet_ibendport_manage_subnet_all_endports(corenet_unconfined_type)
+')
policy/modules/kernel/corenetwork.te.m4 +26 -0
index 3f6e1688..380e64f3 100644
@@ -111,3 +111,29 @@ define(`network_packet',`
 type $1_client_packet_t, packet_type, client_packet_type;
 type $1_server_packet_t, packet_type, server_packet_type;
 ')
+
+define(`declare_ibpkeycons',`dnl
+ibpkeycon $2 $3 gen_context(system_u:object_r:$1,$4)
+ifelse(`$5',`',`',`declare_ibpkeycons($1,shiftn(4,$*))')dnl
+')
+
+#
+# ib_pkey(nam, subnet_prefix, pkey_num, mls_sensitivity [,subnet_prefix, pkey_num, mls_sensitivity[,...]])
+#
+define(`ib_pkey',`
+type $1_ibpkey_t, ibpkey_type;
+ifelse(`$2',`',`',`declare_ibpkeycons($1_ibpkey_t,shift($*))')dnl
+')
+
+define(`declare_ibendportcons',`dnl
+ibendportcon $2 $3 gen_context(system_u:object_r:$1,$4)
+ifelse(`$5',`',`',`declare_ibendportcons($1,shiftn(4,$*))')dnl
+')
+
+#
+# ib_endport (name, dev_name, port_num, mls_sensitivity [, dev_name, port_num mls_sensitivity[,...]])
+#
+define(`ib_endport',`
+type $1_ibendport_t, ibendport_type;
+ifelse(`$2',`',`',`declare_ibendportcons($1_ibendport_t,shift($*))')dnl
+')
policy/modules/kernel/kernel.te +5 -0
index 89923242..e107feca 100644
@@ -449,6 +449,11 @@ optional_policy(`
 	unconfined_domain_noaudit(kernel_t)
 ')
 
+optional_policy(`
+	corenet_ibpkey_access_all_pkeys(kernel_t)
+	corenet_ibendport_manage_subnet_all_endports(kernel_t)
+')
+
 ########################################
 #
 # Unlabeled process local policy
policy/modules/roles/staff.te +5 -0
index 27c2fffa..91a1a555 100644
@@ -15,6 +15,11 @@ userdom_unpriv_user_template(staff)
 #
 
 optional_policy(`
+	corenet_ibpkey_access_default_pkey(staff_t)
+	corenet_ibpkey_access_unlabeled_pkeys(staff_t)
+')
+
+optional_policy(`
 	apache_role(staff_r, staff_t)
 ')
 
policy/modules/roles/sysadm.te +6 -0
index 54df4354..dbc5d08f 100644
@@ -277,6 +277,12 @@ optional_policy(`
 ')
 
 optional_policy(`
+	corenet_ibpkey_access_default_pkey(sysadm_t)
+	corenet_ibpkey_access_unlabeled_pkeys(sysadm_t)
+	corenet_ibendport_manage_subnet_unlabeled_endports(sysadm_t)
+')
+
+optional_policy(`
 	couchdb_admin(sysadm_t, sysadm_r)
 ')
 
support/comment_move_decl.sed +1 -1
index 00b94b6a..90813480 100644
@@ -6,7 +6,7 @@
 /optional \{/,/} # end optional/b nextline
 
 /^[[:blank:]]*(attribute(_role)?|type(alias)?) /s/^/# this line was moved by the build process: &/
-/^[[:blank:]]*(port|node|netif|genfs)con /s/^/# this line was moved by the build process: &/
+/^[[:blank:]]*(port|node|netif|genfs|ibpkey|ibendport)con /s/^/# this line was moved by the build process: &/
 /^[[:blank:]]*fs_use_(xattr|task|trans) /s/^/# this line was moved by the build process: &/
 /^[[:blank:]]*sid /s/^/# this line was moved by the build process: &/
 /^[[:blank:]]*bool /s/^/# this line was moved by the build process: &/
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/1 refpolicy: Infiniband pkeys and endports

Quoted 144 lines · Dan Jurgens via refpolicy

From: Daniel Jurgens <[email protected]>

Every Infiniband network will have a default pkey, so that is labeled. The rest of the pkey configuration is network specific. The policy allows access to the default and unlabeled pkeys for sysadm and staff users. kernel_t is allowed access to all pkeys, which it needs to process and route management datagrams.

Endports are all unlabeled by default, sysadm users are allowed to manage the subnet on unlabeled endports. kernel_t is allowed to manage the subnet on all ibendports, which is required for configuring the HCA.

This patch requires selinux series: "SELinux user space support for Infiniband RDMA", due to the new ipkeycon labeling mechanism.

---
 Makefile                                |   2 +-
 Rules.modular                           |   2 +
 Rules.monolithic                        |   2 +
 policy/flask/access_vectors             |  10 ++
 policy/flask/security_classes           |   4 +
 policy/modules/kernel/corenetwork.if.in | 156 ++++++++++++++++++++++++++++++++
 policy/modules/kernel/corenetwork.if.m4 |  64 +++++++++++++
 policy/modules/kernel/corenetwork.te.in |  17 ++++
 policy/modules/kernel/corenetwork.te.m4 |  26 ++++++
 policy/modules/kernel/kernel.te         |   5 +
 policy/modules/roles/staff.te           |   5 +
 policy/modules/roles/sysadm.te          |   6 ++
 support/comment_move_decl.sed           |   2 +-
 13 files changed, 299 insertions(+), 2 deletions(-)
Makefile +1 -1
index d19985eb..b4b2d43a 100644
@@ -370,7 +370,7 @@ $(moddir)/kernel/corenetwork.if: $(moddir)/kernel/corenetwork.te.in $(moddir)/ke
 	@echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
 	@echo "#" >> $@
 	$(verbose) cat [email protected] >> $@
-	$(verbose) $(GREP) "^[[:blank:]]*network_(interface|node|port|packet)(_controlled)?\(.*\)" $< \
+	$(verbose) $(GREP) "^[[:blank:]]*(network_(interface|node|port|packet)(_controlled)?)|ib_(pkey|endport)\(.*\)" $< \
 		| $(M4) -D self_contained_policy $(M4PARAM) $(m4divert) [email protected] $(m4undivert) - \
 		| $(SED) -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
 
Rules.modular +2 -0
index 49d3cca9..331a979d 100644
@@ -170,6 +170,8 @@ $(tmpdir)/all_post.conf: $(tmpdir)/all_te_files.conf $(tmpdir)/post_te_files.con
 	$(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibpkeycon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibendportcon $(tmpdir)/all_te_files.conf >> $@ || true
 
 $(tmpdir)/only_te_rules.conf: $(tmpdir)/all_te_files.conf
 	$(verbose) $(comment_move_decl) $^ > $@
Rules.monolithic +2 -0
index ce112d78..80e00821 100644
@@ -150,6 +150,8 @@ $(tmpdir)/all_post.conf: $(tmpdir)/all_te_files.conf $(tmpdir)/post_te_files.con
 	$(verbose) $(GREP) ^portcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^netifcon $(tmpdir)/all_te_files.conf >> $@ || true
 	$(verbose) $(GREP) ^nodecon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibpkeycon $(tmpdir)/all_te_files.conf >> $@ || true
+	$(verbose) $(GREP) ^ibendportcon $(tmpdir)/all_te_files.conf >> $@ || true
 
 $(tmpdir)/only_te_rules.conf: $(tmpdir)/all_te_files.conf
 	$(verbose) $(comment_move_decl) $^ > $@
policy/flask/access_vectors +10 -0
index 69f69af8..520a3c28 100644
@@ -926,6 +926,16 @@ inherits database
 	set_value
 }
 
+class infiniband_pkey
+{
+	access
+}
+
+class infiniband_endport
+{
+	manage_subnet
+}
+
 class db_language
 inherits database
 {
policy/flask/security_classes +4 -0
index 18f18fd8..393621bf 100644
@@ -139,6 +139,10 @@ class netlink_crypto_socket
 class x_pointer			# userspace
 class x_keyboard		# userspace
 
+# Infiniband
+class infiniband_pkey
+class infiniband_endport
+
 # More Database stuff
 class db_schema			# userspace
 class db_view			# userspace
policy/modules/kernel/corenetwork.if.in +29 -0
index 2101ea1b..62d90c6c 100644
@@ -3134,3 +3134,159 @@ interface(`corenet_unconfined',`
 
 	typeattribute $1 corenet_unconfined_type;
 ')
+
+########################################
+## <summary>
+##	Define type to be an infiniband pkey type
+## </summary>
+## <desc>
+##	<p>
+##	Define type to be an infiniband pkey type
+##	</p>
+##	<p>
+##	This is for supporting third party modules and its
+##	use is not allowed in upstream reference policy.
+##	</p>
+## </desc>
+## <param name="domain">
+##	<summary>
+##	Type to be used for network ports.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey',`
+	gen_require(`
+		attribute ibpkey_type;
+	')
+
+	typeattribute $1 ibpkey_type;
+')
+
+########################################

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3175

Quoted 10 lines
policy/modules/kernel/corenetwork.if.in +10 -0
+## <summary>
+##	Access unlabeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_unlabeled_pkeys',`

I'm wondering if we could simplify these interface names a little, such as corenet_ib_access_unlabeled_pkeys(). It would also change the above and below interface names to corenet_ib_pkey() and corenet_ib_endport()

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3180

Quoted 5 lines
policy/modules/kernel/corenetwork.if.in +5 -0
+	gen_require(`
+		type unlabeled_t;
+	')
+
+	allow $1 unlabeled_t:infiniband_pkey { access };

Here and below the patch, I'd prefer to skip the unnecessary braces around the single permission, to keep the visual clutter down.

Additionally, the challenge is that unlabeled_t doesn't belong to this module, so it shouldn't be referenced directly.

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3193

Quoted 13 lines
policy/modules/kernel/corenetwork.if.in +13 -0
+')
+
+########################################
+## <summary>
+##	Access all labeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_all_labeled_pkeys',`

I think the "labeled" should be dropped here and latter interfaces, as it is inconsistent with how we handle interface naming for accessing attributes.

Quoted 10 lines
policy/modules/kernel/corenetwork.if.in +10 -0
+	gen_require(`
+		attribute ibpkey_type;
+	')
+
+	allow $1 ibpkey_type:infiniband_pkey { access };
+')
+
+########################################
+## <summary>
+##	Access all infiniband pkeys.

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3213

Quoted 10 lines
policy/modules/kernel/corenetwork.if.in +10 -0
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_all_pkeys',`
+	corenet_ibpkey_access_all_labeled_pkeys($1)
+	corenet_ibpkey_access_unlabeled_pkeys($1)

This would drop with the above revision.

Quoted 294 lines
policy/modules/kernel/corenetwork.if.in +79 -0
+')
+
+########################################
+## <summary>
+##	Define type to be an infiniband endport
+## </summary>
+## <desc>
+##	<p>
+##	Define type to be an infiniband endport
+##	</p>
+##	<p>
+##	This is for supporting third party modules and its
+##	use is not allowed in upstream reference policy.
+##	</p>
+## </desc>
+## <param name="domain">
+##	<summary>
+##	Type to be used for infiniband endports.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibendport',`
+	gen_require(`
+		attribute ibendport_type;
+	')
+
+	typeattribute $1 ibendport_type;
+')
+
+########################################
+## <summary>
+##	Manage subnets on all labeled Infiniband endports
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibendport_manage_subnet_all_labeled_endports',`
+	gen_require(`
+		attribute ibendport_type;
+	')
+
+	allow $1 ibendport_type:infiniband_endport { manage_subnet };
+')
+
+########################################
+## <summary>
+##	Manage subnet on all unlabeled Infiniband endports
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibendport_manage_subnet_unlabeled_endports',`
+	gen_require(`
+		type unlabeled_t;
+	')
+
+	allow $1 unlabeled_t:infiniband_endport { manage_subnet };
+')
+
+########################################
+## <summary>
+##	Manage subnet on all infiniband endports.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibendport_manage_subnet_all_endports',`
+	corenet_ibendport_manage_subnet_unlabeled_endports($1)
+	corenet_ibendport_manage_subnet_all_labeled_endports($1)
+')
policy/modules/kernel/corenetwork.if.m4 +64 -0
index 468fb344..12050937 100644
@@ -776,6 +776,48 @@ interface(`corenet_relabelto_$1_packets',`
 ')
 '') dnl end create_port_interfaces
 
+define(`create_ibpkey_interfaces',``
+########################################
+## <summary>
+##	Access the infiniband fabric on the $1 ibpkey.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+## <infoflow type="both" weight="10"/>
+#
+interface(`corenet_ibpkey_access_$1_pkey',`
+	gen_require(`
+		$3 $1_$2;
+	')
+
+	allow dollarsone $1_$2:infiniband_pkey { access };
+')
+'') dnl end create_ibpkey_interfaces
+
+define(`create_ibendport_interfaces',``
+########################################
+## <summary>
+##	Manage the subnet on $1 ibendport.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+## <infoflow type="both" weight="10"/>
+#
+interface(`corenet_ibendport_manage_subnet_$1_endport',`
+	gen_require(`
+		$3 $1_$2;
+	')
+
+	allow dollarsone $1_$2:infiniband_endport { manage_subnet };
+')
+'') dnl end create_ibendport_interfaces
+
 #
 # create_netif_*_interfaces(linux_interfacename)
 #
@@ -851,3 +893,25 @@ define(`network_packet',`
 create_packet_interfaces($1_client)
 create_packet_interfaces($1_server)
 ')
+
+# create_ibpkey_*_interfaces(name, subnet_prefix, pkeynum,mls_sensitivity)
+# (these wrap create_port_interfaces to handle attributes and types)
+define(`create_ibpkey_type_interfaces',`create_ibpkey_interfaces($1,ibpkey_t,type,determine_reserved_capability(shift($*)))')
+
+#
+# ib_pkey(name,subnet_prefix pkeynum mls_sensitivity)
+#
+define(`ib_pkey',`
+create_ibpkey_type_interfaces($*)
+')
+
+# create_ibendport_*_interfaces(name, devname, portnum,mls_sensitivity)
+# (these wrap create_port_interfaces to handle attributes and types)
+define(`create_ibendport_type_interfaces',`create_ibendport_interfaces($1,ibendport_t,type,determine_reserved_capability(shift($*)))')
+
+#
+# ib_endport(name,device_name, portnum mls_sensitivity)
+#
+define(`ib_endport',`
+create_ibendport_type_interfaces($*)
+')
policy/modules/kernel/corenetwork.te.in +17 -0
index 1ca96d38..bc8ee090 100644
@@ -16,6 +16,8 @@ attribute port_type;
 attribute reserved_port_type;
 attribute rpc_port_type;
 attribute server_packet_type;
+attribute ibpkey_type;
+attribute ibendport_type;
 # This is an optimization for { port_type -reserved_port_type }
 attribute unreserved_port_type;
 
@@ -346,6 +348,15 @@ typealias netif_t alias { lo_netif_t netif_lo_t };
 
 ########################################
 #
+# Infiniband Pkeys
+#
+#
+# unlabeled_t is the default type of infiniband pkeys.
+#
+ib_pkey(default, fe80::,0xFFFF,s1)
+
+########################################
+#
 # Unconfined access to this module
 #
 
@@ -358,3 +369,9 @@ allow corenet_unconfined_type port_type:udp_socket { send_msg recv_msg };
 # Bind to any network address.
 allow corenet_unconfined_type port_type:{ tcp_socket udp_socket rawip_socket } name_bind;
 allow corenet_unconfined_type node_type:{ tcp_socket udp_socket rawip_socket } node_bind;
+
+# Infiniband
+optional_policy(`
+	corenet_ibpkey_access_all_pkeys(corenet_unconfined_type)
+	corenet_ibendport_manage_subnet_all_endports(corenet_unconfined_type)
+')
policy/modules/kernel/corenetwork.te.m4 +26 -0
index 3f6e1688..380e64f3 100644
@@ -111,3 +111,29 @@ define(`network_packet',`
 type $1_client_packet_t, packet_type, client_packet_type;
 type $1_server_packet_t, packet_type, server_packet_type;
 ')
+
+define(`declare_ibpkeycons',`dnl
+ibpkeycon $2 $3 gen_context(system_u:object_r:$1,$4)
+ifelse(`$5',`',`',`declare_ibpkeycons($1,shiftn(4,$*))')dnl
+')
+
+#
+# ib_pkey(nam, subnet_prefix, pkey_num, mls_sensitivity [,subnet_prefix, pkey_num, mls_sensitivity[,...]])
+#
+define(`ib_pkey',`
+type $1_ibpkey_t, ibpkey_type;
+ifelse(`$2',`',`',`declare_ibpkeycons($1_ibpkey_t,shift($*))')dnl
+')
+
+define(`declare_ibendportcons',`dnl
+ibendportcon $2 $3 gen_context(system_u:object_r:$1,$4)
+ifelse(`$5',`',`',`declare_ibendportcons($1,shiftn(4,$*))')dnl
+')
+
+#
+# ib_endport (name, dev_name, port_num, mls_sensitivity [, dev_name, port_num mls_sensitivity[,...]])
+#
+define(`ib_endport',`
+type $1_ibendport_t, ibendport_type;
+ifelse(`$2',`',`',`declare_ibendportcons($1_ibendport_t,shift($*))')dnl
+')
policy/modules/kernel/kernel.te +5 -0
index 89923242..e107feca 100644
@@ -449,6 +449,11 @@ optional_policy(`
 	unconfined_domain_noaudit(kernel_t)
 ')
 
+optional_policy(`
+	corenet_ibpkey_access_all_pkeys(kernel_t)
+	corenet_ibendport_manage_subnet_all_endports(kernel_t)
+')
+
 ########################################
 #
 # Unlabeled process local policy
policy/modules/roles/staff.te +5 -0
index 27c2fffa..91a1a555 100644
@@ -15,6 +15,11 @@ userdom_unpriv_user_template(staff)
 #
 
 optional_policy(`
+	corenet_ibpkey_access_default_pkey(staff_t)
+	corenet_ibpkey_access_unlabeled_pkeys(staff_t)
+')
+
+optional_policy(`
 	apache_role(staff_r, staff_t)
 ')
 
policy/modules/roles/sysadm.te +6 -0
index 54df4354..dbc5d08f 100644
@@ -277,6 +277,12 @@ optional_policy(`
 ')
 
 optional_policy(`
+	corenet_ibpkey_access_default_pkey(sysadm_t)
+	corenet_ibpkey_access_unlabeled_pkeys(sysadm_t)
+	corenet_ibendport_manage_subnet_unlabeled_endports(sysadm_t)
+')
+
+optional_policy(`
 	couchdb_admin(sysadm_t, sysadm_r)
 ')
 
support/comment_move_decl.sed +1 -1
index 00b94b6a..90813480 100644
@@ -6,7 +6,7 @@
 /optional \{/,/} # end optional/b nextline
 
 /^[[:blank:]]*(attribute(_role)?|type(alias)?) /s/^/# this line was moved by the build process: &/
-/^[[:blank:]]*(port|node|netif|genfs)con /s/^/# this line was moved by the build process: &/
+/^[[:blank:]]*(port|node|netif|genfs|ibpkey|ibendport)con /s/^/# this line was moved by the build process: &/
 /^[[:blank:]]*fs_use_(xattr|task|trans) /s/^/# this line was moved by the build process: &/
 /^[[:blank:]]*sid /s/^/# this line was moved by the build process: &/
 /^[[:blank:]]*bool /s/^/# this line was moved by the build process: &/
Signature · 1 line
Chris PeBenito
#2 lore raw

PATCH 1/1 refpolicy: Infiniband pkeys and endports

Quoted 17 lines · Chris PeBenito

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3175

Quoted 13 lines · Dan Jurgens via refpolicy

From: Daniel Jurgens <[email protected]>

policy/modules/kernel/corenetwork.if.in +11 -0
+########################################
+## <summary>
+##	Access unlabeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_unlabeled_pkeys',`

I'm wondering if we could simplify these interface names a little, such as corenet_ib_access_unlabeled_pkeys(). It would also change the above and below interface names to corenet_ib_pkey() and corenet_ib_endport()

I can shorten the names.

Quoted 11 lines

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3180

Quoted 6 lines
policy/modules/kernel/corenetwork.if.in +5 -0
+	gen_require(`
+		type unlabeled_t;
+	')
+
+	allow $1 unlabeled_t:infiniband_pkey { access };

Here and below the patch, I'd prefer to skip the unnecessary braces around the single permission, to keep the visual clutter down.

Additionally, the challenge is that unlabeled_t doesn't belong to this module, so it shouldn't be referenced directly.

I'd like to allow access to all unlabeled pkeys out of the box, most infiniband users will want that type of behavior. Since there's no initial SID for pkeys they are unlabeled_t by default.

Can you suggest a way to do this without a direct reference to unlabeled_t?

Quoted 18 lines
Quoted 4 lines

+')

policy/modules/kernel/corenetwork.if.in +2 -0
+
+########################################

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3193

Quoted 10 lines
policy/modules/kernel/corenetwork.if.in +10 -0
+## <summary>
+##	Access all labeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_all_labeled_pkeys',`

I think the "labeled" should be dropped here and latter interfaces, as it is inconsistent with how we handle interface naming for accessing attributes.

Here I'd like to have a difference between all pkey (labeled or unlabeled, which kernel_t needs permission for) and only those that are unlabeled (for sysadm and staff roles). The resolution of this comment is related to the question I asked above.

#3 lore raw

PATCH 1/1 refpolicy: Infiniband pkeys and endports

Quoted 29 lines · Daniel Jurgens
Quoted 17 lines · Chris PeBenito

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3175

Quoted 13 lines · Dan Jurgens via refpolicy

From: Daniel Jurgens <[email protected]>

policy/modules/kernel/corenetwork.if.in +11 -0
+########################################
+## <summary>
+##	Access unlabeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_unlabeled_pkeys',`

I'm wondering if we could simplify these interface names a little, such as corenet_ib_access_unlabeled_pkeys(). It would also change the above and below interface names to corenet_ib_pkey() and corenet_ib_endport()

I can shorten the names.

Quoted 9 lines

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3180

Quoted 6 lines
policy/modules/kernel/corenetwork.if.in +5 -0
+	gen_require(`
+		type unlabeled_t;
+	')
+
+	allow $1 unlabeled_t:infiniband_pkey { access };

Here and below the patch, I'd prefer to skip the unnecessary braces around the single permission, to keep the visual clutter down.

Quoted 6 lines
Quoted 2 lines

Additionally, the challenge is that unlabeled_t doesn't belong to this module, so it shouldn't be referenced directly.

I'd like to allow access to all unlabeled pkeys out of the box, most infiniband users will want that type of behavior. Since there's no initial SID for pkeys they are unlabeled_t by default.

Can you suggest a way to do this without a direct reference to unlabeled_t?

See the unlabeled packet interface in corenetwork for an example.

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines

+')

policy/modules/kernel/corenetwork.if.in +7 -0
+
+########################################
+## <summary>
+##	Access all labeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
Quoted 9 lines

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3193

Quoted 5 lines
policy/modules/kernel/corenetwork.if.in +5 -0
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_all_labeled_pkeys',`

I think the "labeled" should be dropped here and latter interfaces, as it is inconsistent with how we handle interface naming for accessing attributes.

Quoted 1 line

Here I'd like to have a difference between all pkey (labeled or unlabeled, which kernel_t needs permission for) and only those that are unlabeled (for sysadm and staff roles). The resolution of this comment is related to the question I asked above.

The way to do that is to have an interface for unlabeled pkeys and one for all pkeys, which would be pkeys that have a specific label. Then if you need access to both, you call both interfaces.

Signature · 1 line
Chris PeBenito
#4 lore raw

PATCH 1/1 refpolicy: Infiniband pkeys and endports

Quoted 53 lines · Chris PeBenito
Quoted 28 lines · Daniel Jurgens
Quoted 17 lines · Chris PeBenito

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3175

Quoted 13 lines · Dan Jurgens via refpolicy

From: Daniel Jurgens <[email protected]>

policy/modules/kernel/corenetwork.if.in +11 -0
+########################################
+## <summary>
+##	Access unlabeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_unlabeled_pkeys',`

I'm wondering if we could simplify these interface names a little, such as corenet_ib_access_unlabeled_pkeys(). It would also change the above and below interface names to corenet_ib_pkey() and corenet_ib_endport()

I can shorten the names.

Quoted 8 lines

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3180

Quoted 5 lines
policy/modules/kernel/corenetwork.if.in +5 -0
+	gen_require(`
+		type unlabeled_t;
+	')
+
+	allow $1 unlabeled_t:infiniband_pkey { access };

Here and below the patch, I'd prefer to skip the unnecessary braces around the single permission, to keep the visual clutter down.

Quoted 5 lines
Quoted 2 lines

Additionally, the challenge is that unlabeled_t doesn't belong to this module, so it shouldn't be referenced directly.

I'd like to allow access to all unlabeled pkeys out of the box, most infiniband users will want that type of behavior. Since there's no initial SID for pkeys they are unlabeled_t by default.

Can you suggest a way to do this without a direct reference to unlabeled_t?

See the unlabeled packet interface in corenetwork for an example.

Quoted 17 lines
Quoted 17 lines

policy/modules/kernel/corenetwork.if.in interface(`corenet_unconfined',` · line 3193

Quoted 13 lines

+')

policy/modules/kernel/corenetwork.if.in +12 -0
+
+########################################
+## <summary>
+##	Access all labeled infiniband pkeys.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`corenet_ibpkey_access_all_labeled_pkeys',`

I think the "labeled" should be dropped here and latter interfaces, as it is inconsistent with how we handle interface naming for accessing attributes.

Quoted 5 lines
Quoted 1 line

Here I'd like to have a difference between all pkey (labeled or unlabeled, which kernel_t needs permission for) and only those that are unlabeled (for sysadm and staff roles). The resolution of this comment is related to the question I asked above.

The way to do that is to have an interface for unlabeled pkeys and one for all pkeys, which would be pkeys that have a specific label. Then if you need access to both, you call both interfaces.

Thank you Chris, I've addressed your comments and sent v1.