Skip to contentSkip to conversation

SELinux user space support for Infiniband RDMA

PATCH Superseded Dan Jurgens 4 participants 28 messages May 15, 2017 – May 18, 2017 SELinux security module

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover SELinux user space support for Infiniband RDMA

From: Daniel Jurgens <[email protected]>

Infiniband applications access HW from user-space -- traffic is generated directly by HW, bypassing the kernel. Consequently, Infiniband Partitions, which are associated directly with HW transport endpoints, are a natural choice for enforcing granular mandatory access control for Infiniband. QPs may only send or receives packets tagged with the corresponding partition key (PKey). The PKey is not a cryptographic key; it's a 16 bit number identifying the partition.

Every Infiniband fabric is controlled by a central Subnet Manager (SM). The SM provisions the partitions by assigning each port with the partitions it can access. In addition, the SM tags each port with a subnet prefix, which identifies the subnet. Determining which users are allowed to access which partition keys on a given subnet forms an effective policy for isolating users on the fabric. Any application that attempts to send traffic on a given subnet is automatically subject to the policy, regardless of which device and port it uses. SM software configures the subnet through a privileged Subnet Management Interface (SMI), which is presented by each Infiniband port. Thus, the SMI must also be controlled to prevent unauthorized changes to fabric configuration and partitioning.

To support access control for IB partitions and subnet management, security contexts must be provided for two new types of objects - PKeys and IB end ports.

A PKey label consists of a subnet prefix and a range of PKey values and is similar to the labeling mechanism for netports. Each Infiniband port can reside on a different subnet. So labeling the PKey values for specific subnet prefixes provides the user maximum flexibility, as PKey values may be determined independently for different subnets. There is a single access vector for PKeys called "access".

An Infiniband port is labeled by device name and port number. There is a single access vector for IB end ports called "manage_subnet".

This series adds support for parsing the new labeling mechanisms and generating the policy. It also adds support for runtime labling of PKeys and IB end ports via semanage.

This series is quite large, but most of the code is very similar to existing code for the other *con labels.

Example label syntax:
ibpkeycon fe80:: 0xFFFF gen_context(system_u:object_r:default_ibpkey_t,s0) ibpkeycon fe80:: 0-0x10 gen_context(system_u:object_r:public_ibpkey_t,s0)

ibendportcon mlx5_0 1 gen_context(system_u:object_r:opensm_ibendport_t,s0)

Example semanage commands:
semanage ibpkey -l
semanage ibpkey -a -t default_ibpkey_t -x fe80:: 0x8FFF semanage ibpkey -D

semanage ibendport -l
semanage ibendport -a -t opensm_ibendport_t -z mlx4_0 2 semanage ibenpdort -d -z mlx4_0 2

---
v1:
- Fixed seobject ibpkey delete all name bug (pkey vs ibpkey).

Stephen Smalley:
- Always use s6_addr vs s6_addr32, remove DARWIN #ifdefs.
- Removed unused parameters from new sepol_*_sid functions.
- Got rid of variable length subnet prefix handling, it never varied.

James Carter:
- Add kernel_to_cil and kernel_to_conf implementations for new OCONs.

Jason Zaman:
- Use SETools directly to query types by attribute in seobject.py.

- See individual patches for more detailed changes.

Daniel Jurgens (9):
checkpolicy: Add support for ibpkeycon labels
libsepol: Add ibpkey ocontext handling
libsepol: Add Infiniband Pkey handling to CIL
checkpolicy: Add support for ibendportcon labels
libsepol: Add ibendport ocontext handling
libsepol: Add IB end port handling to CIL
semanage: Update semanage to allow runtime labeling of Infiniband
Pkeys
semanage: Update semanage to allow runtime labeling of ibendports
semanage: Update man pages for infiniband

 checkpolicy/checkpolicy.c                        |  45 +++
 checkpolicy/policy_define.c                      | 180 +++++++++
 checkpolicy/policy_define.h                      |   2 +
 checkpolicy/policy_parse.y                       |  27 +-
 checkpolicy/policy_scan.l                        |   5 +
 libsemanage/include/semanage/ibendport_record.h  |  62 +++
 libsemanage/include/semanage/ibendports_local.h  |  36 ++
 libsemanage/include/semanage/ibendports_policy.h |  28 ++
 libsemanage/include/semanage/ibpkey_record.h     |  76 ++++
 libsemanage/include/semanage/ibpkeys_local.h     |  36 ++
 libsemanage/include/semanage/ibpkeys_policy.h    |  28 ++
 libsemanage/include/semanage/semanage.h          |   6 +
 libsemanage/src/direct_api.c                     |  57 ++-
 libsemanage/src/handle.h                         |  50 ++-
 libsemanage/src/ibendport_internal.h             |  48 +++
 libsemanage/src/ibendport_record.c               | 154 +++++++
 libsemanage/src/ibendports_file.c                | 157 +++++++
 libsemanage/src/ibendports_local.c               | 153 +++++++
 libsemanage/src/ibendports_policy.c              |  55 +++
 libsemanage/src/ibendports_policydb.c            |  62 +++
 libsemanage/src/ibpkey_internal.h                |  52 +++
 libsemanage/src/ibpkey_record.c                  | 185 +++++++++
 libsemanage/src/ibpkeys_file.c                   | 181 +++++++++
 libsemanage/src/ibpkeys_local.c                  | 178 ++++++++
 libsemanage/src/ibpkeys_policy.c                 |  52 +++
 libsemanage/src/ibpkeys_policydb.c               |  62 +++
 libsemanage/src/libsemanage.map                  |   2 +
 libsemanage/src/policy_components.c              |   9 +-
 libsemanage/src/semanage_store.c                 |   2 +
 libsemanage/src/semanage_store.h                 |   2 +
 libsemanage/src/semanageswig.i                   |   6 +
 libsemanage/src/semanageswig_python.i            |  86 ++++
 libsemanage/utils/semanage_migrate_store         |   4 +-
 libsepol/cil/src/cil.c                           |  37 ++
 libsepol/cil/src/cil_binary.c                    |  68 ++++
 libsepol/cil/src/cil_binary.h                    |  24 ++
 libsepol/cil/src/cil_build_ast.c                 | 151 +++++++
 libsepol/cil/src/cil_build_ast.h                 |   4 +
 libsepol/cil/src/cil_copy_ast.c                  |  51 +++
 libsepol/cil/src/cil_copy_ast.h                  |   1 +
 libsepol/cil/src/cil_flavor.h                    |   2 +
 libsepol/cil/src/cil_internal.h                  |  20 +
 libsepol/cil/src/cil_policy.c                    |  31 ++
 libsepol/cil/src/cil_post.c                      |  87 ++++
 libsepol/cil/src/cil_post.h                      |   2 +
 libsepol/cil/src/cil_reset_ast.c                 |  19 +
 libsepol/cil/src/cil_resolve_ast.c               |  55 +++
 libsepol/cil/src/cil_resolve_ast.h               |   2 +
 libsepol/cil/src/cil_tree.c                      |  29 +-
 libsepol/cil/src/cil_verify.c                    |  46 +++
 libsepol/include/sepol/ibendport_record.h        |  68 ++++
 libsepol/include/sepol/ibendports.h              |  45 +++
 libsepol/include/sepol/ibpkey_record.h           |  77 ++++
 libsepol/include/sepol/ibpkeys.h                 |  44 ++
 libsepol/include/sepol/policydb/policydb.h       |  39 +-
 libsepol/include/sepol/policydb/services.h       |  16 +
 libsepol/include/sepol/sepol.h                   |   4 +
 libsepol/src/expand.c                            |  17 +
 libsepol/src/ibendport_internal.h                |  18 +
 libsepol/src/ibendport_record.c                  | 298 ++++++++++++++
 libsepol/src/ibendports.c                        | 255 ++++++++++++
 libsepol/src/ibpkey_internal.h                   |  21 +
 libsepol/src/ibpkey_record.c                     | 448 ++++++++++++++++++++
 libsepol/src/ibpkeys.c                           | 263 ++++++++++++
 libsepol/src/kernel_to_cil.c                     | 100 +++++
 libsepol/src/kernel_to_conf.c                    | 100 +++++
 libsepol/src/libsepol.map.in                     |   2 +
 libsepol/src/module_to_cil.c                     |  52 +++
 libsepol/src/policydb.c                          |  59 ++-
 libsepol/src/services.c                          |  88 ++++
 libsepol/src/write.c                             |  30 ++
 python/semanage/semanage                         | 116 +++++-
 python/semanage/semanage-ibendport.8             |  66 +++
 python/semanage/semanage-ibpkey.8                |  66 +++
 python/semanage/semanage.8                       |  16 +-
 python/semanage/seobject.py                      | 494 +++++++++++++++++++++++
 76 files changed, 5482 insertions(+), 37 deletions(-)
 create mode 100644 libsemanage/include/semanage/ibendport_record.h
 create mode 100644 libsemanage/include/semanage/ibendports_local.h
 create mode 100644 libsemanage/include/semanage/ibendports_policy.h
 create mode 100644 libsemanage/include/semanage/ibpkey_record.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_local.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h
 create mode 100644 libsemanage/src/ibendport_internal.h
 create mode 100644 libsemanage/src/ibendport_record.c
 create mode 100644 libsemanage/src/ibendports_file.c
 create mode 100644 libsemanage/src/ibendports_local.c
 create mode 100644 libsemanage/src/ibendports_policy.c
 create mode 100644 libsemanage/src/ibendports_policydb.c
 create mode 100644 libsemanage/src/ibpkey_internal.h
 create mode 100644 libsemanage/src/ibpkey_record.c
 create mode 100644 libsemanage/src/ibpkeys_file.c
 create mode 100644 libsemanage/src/ibpkeys_local.c
 create mode 100644 libsemanage/src/ibpkeys_policy.c
 create mode 100644 libsemanage/src/ibpkeys_policydb.c
 create mode 100644 libsepol/include/sepol/ibendport_record.h
 create mode 100644 libsepol/include/sepol/ibendports.h
 create mode 100644 libsepol/include/sepol/ibpkey_record.h
 create mode 100644 libsepol/include/sepol/ibpkeys.h
 create mode 100644 libsepol/src/ibendport_internal.h
 create mode 100644 libsepol/src/ibendport_record.c
 create mode 100644 libsepol/src/ibendports.c
 create mode 100644 libsepol/src/ibpkey_internal.h
 create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c
 create mode 100644 python/semanage/semanage-ibendport.8
 create mode 100644 python/semanage/semanage-ibpkey.8
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/9 checkpolicy: Add support for ibpkeycon labels

From: Daniel Jurgens <[email protected]>

Add checkpolicy support for scanning and parsing ibpkeycon labels. Also create a new ocontext for Infiniband Pkeys and define a new policydb version for infiniband support.

---
v1:
Stephen Smalley:
- Always use s6_addr instead of s6_addr32.
- Add comment about POLICYDB_VERSION_INFINIBAND being linux specific.

---
 checkpolicy/policy_define.c                | 105 +++++++++++++++++++++++++++++
 checkpolicy/policy_define.h                |   1 +
 checkpolicy/policy_parse.y                 |  15 ++++-
 checkpolicy/policy_scan.l                  |   3 +
 libsepol/include/sepol/policydb/policydb.h |  32 +++++----
 5 files changed, 143 insertions(+), 13 deletions(-)
checkpolicy/policy_define.c +105 -0
index 8fab214..ffdc5f8 100644
@@ -20,6 +20,7 @@
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2008 Tresys Technology, LLC
  * Copyright (C) 2007 Red Hat Inc.
+ * Copyright (C) 2017 Mellanox Techonologies Inc.
  *	This program is free software; you can redistribute it and/or modify
  *  	it under the terms of the GNU General Public License as published by
  *	the Free Software Foundation, version 2.
@@ -5057,6 +5058,110 @@ int define_port_context(unsigned int low, unsigned int high)
 	return -1;
 }
 
+int define_ibpkey_context(unsigned int low, unsigned int high)
+{
+	ocontext_t *newc, *c, *l, *head;
+	struct in6_addr subnet_prefix;
+	char *id;
+	int rc = 0;
+
+	if (policydbp->target_platform != SEPOL_TARGET_SELINUX) {
+		yyerror("ibpkeycon not supported for target");
+		return -1;
+	}
+
+	if (pass == 1) {
+		id = (char *)queue_remove(id_queue);
+		free(id);
+		parse_security_context(NULL);
+		return 0;
+	}
+
+	newc = malloc(sizeof(*newc));
+	if (!newc) {
+		yyerror("out of memory");
+		return -1;
+	}
+	memset(newc, 0, sizeof(*newc));
+
+	id = queue_remove(id_queue);
+	if (!id) {
+		yyerror("failed to read the subnet prefix");
+		rc = -1;
+		goto out;
+	}
+
+	rc = inet_pton(AF_INET6, id, &subnet_prefix);
+	free(id);
+	if (rc < 1) {
+		yyerror("failed to parse the subnet prefix");
+		if (rc == 0)
+			rc = -1;
+		goto out;
+	}
+
+	if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
+		yyerror("subnet prefix should be 0's in the low order 64 bits.");
+		rc = -1;
+		goto out;
+	}
+
+	memcpy(&newc->u.ibpkey.subnet_prefix[0], &subnet_prefix.s6_addr[0],
+	       sizeof(newc->u.ibpkey.subnet_prefix));
+
+	newc->u.ibpkey.low_pkey = low;
+	newc->u.ibpkey.high_pkey = high;
+
+	if (low > high) {
+		yyerror2("low pkey %d exceeds high pkey %d", low, high);
+		rc = -1;
+		goto out;
+	}
+
+	rc = parse_security_context(&newc->context[0]);
+	if (rc)
+		goto out;
+
+	/* Preserve the matching order specified in the configuration. */
+	head = policydbp->ocontexts[OCON_IBPKEY];
+	for (l = NULL, c = head; c; l = c, c = c->next) {
+		unsigned int low2, high2;
+
+		low2 = c->u.ibpkey.low_pkey;
+		high2 = c->u.ibpkey.high_pkey;
+
+		if (low == low2 && high == high2 &&
+		    !memcmp(&c->u.ibpkey.subnet_prefix[0],
+			    &newc->u.ibpkey.subnet_prefix[0],
+			    sizeof(c->u.ibpkey.subnet_prefix))) {
+			yyerror2("duplicate ibpkeycon entry for %d-%d ",
+				 low, high);
+			rc = -1;
+			goto out;
+		}
+		if (low2 <= low && high2 >= high &&
+		    !memcmp(&c->u.ibpkey.subnet_prefix[0],
+			    &newc->u.ibpkey.subnet_prefix[0],
+			    sizeof(c->u.ibpkey.subnet_prefix))) {
+			yyerror2("ibpkeycon entry for %d-%d hidden by earlier entry for %d-%d",
+				 low, high, low2, high2);
+			rc = -1;
+			goto out;
+		}
+	}
+
+	if (l)
+		l->next = newc;
+	else
+		policydbp->ocontexts[OCON_IBPKEY] = newc;
+
+	return 0;
+
+out:
+	free(newc);
+	return rc;
+}
+
 int define_netif_context(void)
 {
 	ocontext_t *newc, *c, *head;
checkpolicy/policy_define.h +1 -0
index 9f4b6d0..75e3683 100644
@@ -43,6 +43,7 @@ int define_level(void);
 int define_netif_context(void);
 int define_permissive(void);
 int define_polcap(void);
+int define_ibpkey_context(unsigned int low, unsigned int high);
 int define_port_context(unsigned int low, unsigned int high);
 int define_pirq_context(unsigned int pirq);
 int define_iomem_context(uint64_t low, uint64_t high);
checkpolicy/policy_parse.y +14 -1
index 1ac1c96..35b433b 100644
@@ -21,6 +21,7 @@
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2008 Tresys Technology, LLC
  * Copyright (C) 2007 Red Hat Inc.
+ * Copyright (C) 2017 Mellanox Technologies Inc.
  *	This program is free software; you can redistribute it and/or modify
  *  	it under the terms of the GNU General Public License as published by
  *	the Free Software Foundation, version 2.
@@ -135,6 +136,7 @@ typedef int (* require_func_t)(int pass);
 %token TARGET
 %token SAMEUSER
 %token FSCON PORTCON NETIFCON NODECON 
+%token IBPKEYCON
 %token PIRQCON IOMEMCON IOPORTCON PCIDEVICECON DEVICETREECON
 %token FSUSEXATTR FSUSETASK FSUSETRANS
 %token GENFSCON
@@ -170,7 +172,7 @@ base_policy             : { if (define_policy(pass, 0) == -1) return -1; }
 			  opt_default_rules opt_mls te_rbac users opt_constraints 
                          { if (pass == 1) { if (policydb_index_bools(policydbp)) return -1;}
 			   else if (pass == 2) { if (policydb_index_others(NULL, policydbp, 0)) return -1;}}
-			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts
+			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts opt_ibpkey_contexts
 			;
 classes			: class_def 
 			| classes class_def
@@ -713,6 +715,17 @@ port_context_def	: PORTCON identifier number security_context_def
 			| PORTCON identifier number '-' number security_context_def
 			{if (define_port_context($3,$5)) return -1;}
 			;
+opt_ibpkey_contexts     : ibpkey_contexts
+                        |
+                        ;
+ibpkey_contexts		: ibpkey_context_def
+			| ibpkey_contexts ibpkey_context_def
+			;
+ibpkey_context_def	: IBPKEYCON ipv6_addr number security_context_def
+			{if (define_ibpkey_context($3,$3)) return -1;}
+			| IBPKEYCON ipv6_addr number '-' number security_context_def
+			{if (define_ibpkey_context($3,$5)) return -1;}
+			;
 opt_netif_contexts      : netif_contexts 
                         |
                         ;
checkpolicy/policy_scan.l +3 -0
index 028bd25..f742939 100644
@@ -12,6 +12,7 @@
  *	Added support for binary policy modules
  *
  * Copyright (C) 2003-5 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
  *	This program is free software; you can redistribute it and/or modify
  *  	it under the terms of the GNU General Public License as published by
  *	the Free Software Foundation, version 2.
@@ -183,6 +184,8 @@ INCOMP |
 incomp				{ return(INCOMP);}
 fscon |
 FSCON                           { return(FSCON);}
+ibpkeycon |
+IBPKEYCON			{ return(IBPKEYCON);}
 portcon |
 PORTCON				{ return(PORTCON);}
 netifcon |                     
libsepol/include/sepol/policydb/policydb.h +20 -12
index 37e0c9e..844191c 100644
@@ -24,6 +24,7 @@
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2004 Tresys Technology, LLC
  * Copyright (C) 2003 - 2004 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Techonolgies Inc.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -358,6 +359,11 @@ typedef struct ocontext {
 			uint32_t low_ioport;
 			uint32_t high_ioport;
 		} ioport;
+		struct {
+			uint32_t subnet_prefix[4];
+			uint16_t low_pkey;
+			uint16_t high_pkey;
+		} ibpkey;
 	} u;
 	union {
 		uint32_t sclass;	/* security class for genfs */
@@ -386,14 +392,14 @@ typedef struct genfs {
 #define SYM_NUM     8
 
 /* object context array indices */
-#define OCON_ISID  0		/* initial SIDs */
-#define OCON_FS    1		/* unlabeled file systems */
-#define OCON_PORT  2		/* TCP and UDP port numbers */
-#define OCON_NETIF 3		/* network interfaces */
-#define OCON_NODE  4		/* nodes */
-#define OCON_FSUSE 5		/* fs_use */
-#define OCON_NODE6 6		/* IPv6 nodes */
-#define OCON_GENFS 7            /* needed for ocontext_supported */
+#define OCON_ISID  0	/* initial SIDs */
+#define OCON_FS    1	/* unlabeled file systems */
+#define OCON_PORT  2	/* TCP and UDP port numbers */
+#define OCON_NETIF 3	/* network interfaces */
+#define OCON_NODE  4	/* nodes */
+#define OCON_FSUSE 5	/* fs_use */
+#define OCON_NODE6 6	/* IPv6 nodes */
+#define OCON_IBPKEY 7	/* Infiniband PKEY */
 
 /* object context array indices for Xen */
 #define OCON_XEN_ISID  	    0    /* initial SIDs */
@@ -404,7 +410,7 @@ typedef struct genfs {
 #define OCON_XEN_DEVICETREE 5    /* device tree node */
 
 /* OCON_NUM needs to be the largest index in any platform's ocontext array */
-#define OCON_NUM   7
+#define OCON_NUM   8
 
 /* section: module information */
 
@@ -726,10 +732,11 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
 #define POLICYDB_VERSION_CONSTRAINT_NAMES	29
 #define POLICYDB_VERSION_XEN_DEVICETREE		30 /* Xen-specific */
 #define POLICYDB_VERSION_XPERMS_IOCTL	30 /* Linux-specific */
+#define POLICYDB_VERSION_INFINIBAND		31 /* Linux-specific */
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN	POLICYDB_VERSION_BASE
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_XPERMS_IOCTL
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_INFINIBAND
 
 /* Module versions and specific changes*/
 #define MOD_POLICYDB_VERSION_BASE		4
@@ -747,10 +754,11 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
 #define MOD_POLICYDB_VERSION_TUNABLE_SEP	14
 #define MOD_POLICYDB_VERSION_NEW_OBJECT_DEFAULTS	15
 #define MOD_POLICYDB_VERSION_DEFAULT_TYPE	16
-#define MOD_POLICYDB_VERSION_CONSTRAINT_NAMES  17
+#define MOD_POLICYDB_VERSION_CONSTRAINT_NAMES	17
+#define MOD_POLICYDB_VERSION_INFINIBAND		18
 
 #define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE
-#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_CONSTRAINT_NAMES
+#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_INFINIBAND
 
 #define POLICYDB_CONFIG_MLS    1
 
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v1 1/9] checkpolicy: Add support for ibpkeycon labels

Quoted 96 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add checkpolicy support for scanning and parsing ibpkeycon labels. Also
create a new ocontext for Infiniband Pkeys and define a new policydb version for infiniband support.

---
v1:
Stephen Smalley:
- Always use s6_addr instead of s6_addr32.
- Add comment about POLICYDB_VERSION_INFINIBAND being linux specific.

---
 checkpolicy/policy_define.c                | 105
+++++++++++++++++++++++++++++
 checkpolicy/policy_define.h                |   1 + checkpolicy/policy_parse.y                 |  15 ++++- checkpolicy/policy_scan.l                  |   3 + libsepol/include/sepol/policydb/policydb.h |  32 +++++----

 5 files changed, 143 insertions(+), 13 deletions(-)
checkpolicy/policy_define.c +1 -0
index 8fab214..ffdc5f8 100644
@@ -20,6 +20,7 @@
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003 - 2008 Tresys Technology, LLC
   * Copyright (C) 2007 Red Hat Inc.
+ * Copyright (C) 2017 Mellanox Techonologies Inc.
   *	This program is free software; you can redistribute it

and/or modify
  *   it under the terms of the GNU General Public License as
published by
  * the Free Software Foundation, version 2.

checkpolicy/policy_define.c +0 -0
@@ -5057,6 +5058,110 @@ int define_port_context(unsigned int low,
 unsigned int high)
  	return -1;
  }

checkpolicy/policy_define.c +44 -0
+int define_ibpkey_context(unsigned int low, unsigned int high)
+{
+	ocontext_t *newc, *c, *l, *head;
+	struct in6_addr subnet_prefix;
+	char *id;
+	int rc = 0;
+
+	if (policydbp->target_platform != SEPOL_TARGET_SELINUX) {
+		yyerror("ibpkeycon not supported for target");
+		return -1;
+	}
+
+	if (pass == 1) {
+		id = (char *)queue_remove(id_queue);
+		free(id);
+		parse_security_context(NULL);
+		return 0;
+	}
+
+	newc = malloc(sizeof(*newc));
+	if (!newc) {
+		yyerror("out of memory");
+		return -1;
+	}
+	memset(newc, 0, sizeof(*newc));
+
+	id = queue_remove(id_queue);
+	if (!id) {
+		yyerror("failed to read the subnet prefix");
+		rc = -1;
+		goto out;
+	}
+
+	rc = inet_pton(AF_INET6, id, &subnet_prefix);
+	free(id);
+	if (rc < 1) {
+		yyerror("failed to parse the subnet prefix");
+		if (rc == 0)
+			rc = -1;
+		goto out;
+	}
+
+	if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
+		yyerror("subnet prefix should be 0's in the low

order 64 bits.");

checkpolicy/policy_define.c +5 -0
+		rc = -1;
+		goto out;
+	}
+
+	memcpy(&newc->u.ibpkey.subnet_prefix[0],

&subnet_prefix.s6_addr[0],

checkpolicy/policy_define.c int define_port_context(unsigned int low, unsigned int high) · line 5113

Quoted 4 lines
checkpolicy/policy_define.c +4 -0
+	       sizeof(newc->u.ibpkey.subnet_prefix));
+
+	newc->u.ibpkey.low_pkey = low;
+	newc->u.ibpkey.high_pkey = high;

Kernel patch also rejects low or high > 0xffff, so we likely ought to do the same here?

Quoted 247 lines
checkpolicy/policy_define.c +3 -0
+
+	if (low > high) {
+		yyerror2("low pkey %d exceeds high pkey %d", low,

high);

checkpolicy/policy_define.c +9 -0
+		rc = -1;
+		goto out;
+	}
+
+	rc = parse_security_context(&newc->context[0]);
+	if (rc)
+		goto out;
+
+	/* Preserve the matching order specified in the

configuration. */

checkpolicy/policy_define.c +12 -0
+	head = policydbp->ocontexts[OCON_IBPKEY];
+	for (l = NULL, c = head; c; l = c, c = c->next) {
+		unsigned int low2, high2;
+
+		low2 = c->u.ibpkey.low_pkey;
+		high2 = c->u.ibpkey.high_pkey;
+
+		if (low == low2 && high == high2 &&
+		    !memcmp(&c->u.ibpkey.subnet_prefix[0],
+			    &newc->u.ibpkey.subnet_prefix[0],
+			    sizeof(c->u.ibpkey.subnet_prefix))) {
+			yyerror2("duplicate ibpkeycon entry for %d-

%d ",

checkpolicy/policy_define.c +9 -0
+				 low, high);
+			rc = -1;
+			goto out;
+		}
+		if (low2 <= low && high2 >= high &&
+		    !memcmp(&c->u.ibpkey.subnet_prefix[0],
+			    &newc->u.ibpkey.subnet_prefix[0],
+			    sizeof(c->u.ibpkey.subnet_prefix))) {
+			yyerror2("ibpkeycon entry for %d-%d hidden

by earlier entry for %d-%d",

checkpolicy/policy_define.c +18 -0
+				 low, high, low2, high2);
+			rc = -1;
+			goto out;
+		}
+	}
+
+	if (l)
+		l->next = newc;
+	else
+		policydbp->ocontexts[OCON_IBPKEY] = newc;
+
+	return 0;
+
+out:
+	free(newc);
+	return rc;
+}
+

 int define_netif_context(void)
 {
  ocontext_t *newc, *c, *head;

checkpolicy/policy_define.h +1 -0
index 9f4b6d0..75e3683 100644
@@ -43,6 +43,7 @@ int define_level(void);
  int define_netif_context(void);
  int define_permissive(void);
  int define_polcap(void);
+int define_ibpkey_context(unsigned int low, unsigned int high);
  int define_port_context(unsigned int low, unsigned int high);
  int define_pirq_context(unsigned int pirq);
  int define_iomem_context(uint64_t low, uint64_t high);
checkpolicy/policy_parse.y +1 -0
index 1ac1c96..35b433b 100644
@@ -21,6 +21,7 @@
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003 - 2008 Tresys Technology, LLC
   * Copyright (C) 2007 Red Hat Inc.
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *	This program is free software; you can redistribute it

and/or modify
  *   it under the terms of the GNU General Public License as
published by
  * the Free Software Foundation, version 2.

checkpolicy/policy_parse.y +0 -0
@@ -135,6 +136,7 @@ typedef int (* require_func_t)(int pass);

 %token TARGET
 %token SAMEUSER
 %token FSCON PORTCON NETIFCON NODECON
+%token IBPKEYCON
 %token PIRQCON IOMEMCON IOPORTCON PCIDEVICECON DEVICETREECON %token FSUSEXATTR FSUSETASK FSUSETRANS
 %token GENFSCON

checkpolicy/policy_parse.y +0 -0
@@ -170,7 +172,7 @@ base_policy             : { if
 (define_policy(pass, 0) == -1) return -1; }

    opt_default_rules opt_mls te_rbac users opt_constraints
                          { if (pass == 1) { if (policydb_index_bools(policydbp)) return -1;}
     else if (pass == 2) { if (policydb_index_others(NULL, policydbp, 0)) return -1;}}

checkpolicy/policy_parse.y +0 -1
-			  initial_sid_contexts opt_fs_contexts

opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts

checkpolicy/policy_parse.y +1 -0
+			  initial_sid_contexts opt_fs_contexts

opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts opt_ibpkey_contexts
  ;
 classes : class_def
  | classes class_def

checkpolicy/policy_parse.y +0 -0
@@ -713,6 +715,17 @@ port_context_def	: PORTCON identifier

number security_context_def
  | PORTCON identifier number '-' number security_context_def
  {if (define_port_context($3,$5)) return -1;} ;

checkpolicy/policy_parse.y +7 -0
+opt_ibpkey_contexts     : ibpkey_contexts
+                        |
+                        ;
+ibpkey_contexts		: ibpkey_context_def
+			| ibpkey_contexts ibpkey_context_def
+			;
+ibpkey_context_def	: IBPKEYCON ipv6_addr number

security_context_def

checkpolicy/policy_parse.y +2 -1
+			{if (define_ibpkey_context($3,$3)) return
-1;}
+			| IBPKEYCON ipv6_addr number '-' number

security_context_def

checkpolicy/policy_parse.y +2 -1
+			{if (define_ibpkey_context($3,$5)) return
-1;}
+			;

 opt_netif_contexts      : netif_contexts
                         |
                         ;

checkpolicy/policy_scan.l +1 -0
index 028bd25..f742939 100644
@@ -12,6 +12,7 @@
   *	Added support for binary policy modules
   *
   * Copyright (C) 2003-5 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *	This program is free software; you can redistribute it

and/or modify
  *   it under the terms of the GNU General Public License as
published by
  * the Free Software Foundation, version 2.

checkpolicy/policy_scan.l +0 -0
@@ -183,6 +184,8 @@ INCOMP |
  incomp				{ return(INCOMP);}

 fscon |
 FSCON                           { return(FSCON);}

checkpolicy/policy_scan.l +2 -0
+ibpkeycon |
+IBPKEYCON			{ return(IBPKEYCON);}

 portcon |
 PORTCON { return(PORTCON);}
 netifcon |

libsepol/include/sepol/policydb/policydb.h +6 -0
index 37e0c9e..844191c 100644
@@ -24,6 +24,7 @@
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003 - 2004 Tresys Technology, LLC
   * Copyright (C) 2003 - 2004 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Techonolgies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -358,6 +359,11 @@ typedef struct ocontext {
  			uint32_t low_ioport;
  			uint32_t high_ioport;
  		} ioport;
+		struct {
+			uint32_t subnet_prefix[4];
+			uint16_t low_pkey;
+			uint16_t high_pkey;
+		} ibpkey;
  	} u;
  	union {

  uint32_t sclass; /* security class for genfs
*/

libsepol/include/sepol/policydb/policydb.h +0 -0
@@ -386,14 +392,14 @@ typedef struct genfs {
  #define SYM_NUM     8


 /* object context array indices */

libsepol/include/sepol/policydb/policydb.h +8 -8
-#define OCON_ISID  0		/* initial SIDs */
-#define OCON_FS    1		/* unlabeled file systems */
-#define OCON_PORT  2		/* TCP and UDP port numbers */
-#define OCON_NETIF 3		/* network interfaces */
-#define OCON_NODE  4		/* nodes */
-#define OCON_FSUSE 5		/* fs_use */
-#define OCON_NODE6 6		/* IPv6 nodes */
-#define OCON_GENFS 7            /* needed for ocontext_supported */
+#define OCON_ISID  0	/* initial SIDs */
+#define OCON_FS    1	/* unlabeled file systems */
+#define OCON_PORT  2	/* TCP and UDP port numbers */
+#define OCON_NETIF 3	/* network interfaces */
+#define OCON_NODE  4	/* nodes */
+#define OCON_FSUSE 5	/* fs_use */
+#define OCON_NODE6 6	/* IPv6 nodes */
+#define OCON_IBPKEY 7	/* Infiniband PKEY */


 /* object context array indices for Xen */
 #define OCON_XEN_ISID       0    /* initial SIDs */

libsepol/include/sepol/policydb/policydb.h +0 -0
@@ -404,7 +410,7 @@ typedef struct genfs {
  #define OCON_XEN_DEVICETREE 5    /* device tree node */


 /* OCON_NUM needs to be the largest index in any platform's ocontext array */

libsepol/include/sepol/policydb/policydb.h +1 -1
-#define OCON_NUM   7
+#define OCON_NUM   8


 /* section: module information */

libsepol/include/sepol/policydb/policydb.h +0 -0
@@ -726,10 +732,11 @@ extern int
 policydb_set_target_platform(policydb_t *p, int platform);
  #define POLICYDB_VERSION_CONSTRAINT_NAMES	29
  #define POLICYDB_VERSION_XEN_DEVICETREE		30 /* Xen-

specific */
 #define POLICYDB_VERSION_XPERMS_IOCTL 30 /* Linux-specific */
+#define POLICYDB_VERSION_INFINIBAND 31 /* Linux-
specific */

 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE

libsepol/include/sepol/policydb/policydb.h +1 -1
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_XPERMS_IOCTL
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_INFINIBAND


 /* Module versions and specific changes*/
 #define MOD_POLICYDB_VERSION_BASE 4

libsepol/include/sepol/policydb/policydb.h +2 -1
@@ -747,10 +754,11 @@ extern int
 policydb_set_target_platform(policydb_t *p, int platform);
  #define MOD_POLICYDB_VERSION_TUNABLE_SEP	14
  #define MOD_POLICYDB_VERSION_NEW_OBJECT_DEFAULTS	15
  #define MOD_POLICYDB_VERSION_DEFAULT_TYPE	16
-#define MOD_POLICYDB_VERSION_CONSTRAINT_NAMES  17
+#define MOD_POLICYDB_VERSION_CONSTRAINT_NAMES	17
+#define MOD_POLICYDB_VERSION_INFINIBAND		18


 #define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE -#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_CONSTRAINT_NAMES
+#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_INFINIBAND
 #define POLICYDB_CONFIG_MLS    1

#3 lore raw

Re: [PATCH v1 1/9] checkpolicy: Add support for ibpkeycon labels

Quoted 18 lines · Stephen Smalley
Quoted 11 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

(quoted diff) +2 -0
+	if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
+		yyerror("subnet prefix should be 0's in the low

order 64 bits.");

checkpolicy/policy_define.c +5 -0
+		rc = -1;
+		goto out;
+	}
+
+	memcpy(&newc->u.ibpkey.subnet_prefix[0],

&subnet_prefix.s6_addr[0],

checkpolicy/policy_define.c int define_port_context(unsigned int low, unsigned int high) · line 5113

Quoted 4 lines
checkpolicy/policy_define.c +4 -0
+	       sizeof(newc->u.ibpkey.subnet_prefix));
+
+	newc->u.ibpkey.low_pkey = low;
+	newc->u.ibpkey.high_pkey = high;

Kernel patch also rejects low or high > 0xffff, so we likely ought to do the same here?

Done

#4 lore raw

PATCH 2/9 libsepol: Add ibpkey ocontext handling

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying Infinabinda Pkey ocontext data. Also add support for querying a Pkey sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed domain and type params from sepol_ibpkey_sid.
- Removed splen param from sepol_ibpkey_sid, it never varied.
- Removed extra XPERMS_IOCTL version from policydb_compat_info.
- Confirm that low order bytes of IPv6 addr for subnet prefix is 0's.

James Carter:
- Added ibpkey handling to kernel_to_cil.c and kernel_to_conf.c

---
 checkpolicy/checkpolicy.c                  | 25 +++++++++++++
 libsepol/include/sepol/policydb/services.h |  8 ++++
 libsepol/src/expand.c                      |  9 +++++
 libsepol/src/kernel_to_cil.c               | 58 +++++++++++++++++++++++++++++
 libsepol/src/kernel_to_conf.c              | 59 ++++++++++++++++++++++++++++++
 libsepol/src/libsepol.map.in               |  1 +
 libsepol/src/module_to_cil.c               | 38 +++++++++++++++++++
 libsepol/src/policydb.c                    | 37 +++++++++++++++++++
 libsepol/src/services.c                    | 51 ++++++++++++++++++++++++++
 libsepol/src/write.c                       | 16 ++++++++
 10 files changed, 302 insertions(+)
checkpolicy/checkpolicy.c +25 -0
index 534fc22..d0e46ba 100644
@@ -22,6 +22,7 @@
  *
  *	Policy Module support.
  *
+ * Copyright (C) 2017 Mellanox Technologies Inc.
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2005 Tresys Technology, LLC
  * Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]>
@@ -699,6 +700,7 @@ int main(int argc, char **argv)
 	printf("h)  change a boolean value\n");
 	printf("i)  display constraint expressions\n");
 	printf("j)  display validatetrans expressions\n");
+	printf("k)  Call ibpkey_sid\n");
 #ifdef EQUIVTYPES
 	printf("z)  Show equivalent types\n");
 #endif
@@ -1220,6 +1222,29 @@ int main(int argc, char **argv)
 				    "\nNo validatetrans expressions found.\n");
 			}
 			break;
+		case 'k':
+			{
+				char *p;
+				struct in6_addr addr6;
+				unsigned int pkey;
+
+				printf("subnet prefix?  ");
+				FGETS(ans, sizeof(ans), stdin);
+				ans[strlen(ans) - 1] = 0;
+				p = (char *)&addr6;
+
+				if (inet_pton(AF_INET6, ans, p) < 1) {
+					printf("error parsing subnet prefix\n");
+					break;
+				}
+
+				printf("pkey? ");
+				FGETS(ans, sizeof(ans), stdin);
+				pkey = atoi(ans);
+				sepol_ibpkey_sid(p, pkey, &ssid);
+				printf("sid %d\n", ssid);
+			}
+			break;
 #ifdef EQUIVTYPES
 		case 'z':
 			identify_equiv_types();
libsepol/include/sepol/policydb/services.h +8 -0
index 9162149..459254e 100644
@@ -188,6 +188,14 @@ extern int sepol_port_sid(uint16_t domain,
 			  uint16_t port, sepol_security_id_t * out_sid);
 
 /*
+ * Return the SID of the ibpkey specified by
+ * `subnet prefix', and `pkey'.
+ */
+extern int sepol_ibpkey_sid(void *subnet_prefix_p,
+			    uint16_t pkey,
+			    sepol_security_id_t *out_sid);
+
+/*
  * Return the SIDs to use for a network interface
  * with the name `name'.  The `if_sid' SID is returned for 
  * the interface and the `msg_sid' SID is returned as
libsepol/src/expand.c +9 -0
index 54bf781..c45ecbe 100644
@@ -4,6 +4,7 @@
  *
  * Copyright (C) 2004-2005 Tresys Technology, LLC
  * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies, Inc.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -2217,6 +2218,14 @@ static int ocontext_copy_selinux(expand_state_t *state)
 					return -1;
 				}
 				break;
+			case OCON_IBPKEY:
+				n->u.ibpkey.subnet_prefix[0] = c->u.ibpkey.subnet_prefix[0];
+				n->u.ibpkey.subnet_prefix[1] = c->u.ibpkey.subnet_prefix[1];
+				n->u.ibpkey.subnet_prefix[2] = c->u.ibpkey.subnet_prefix[2];
+				n->u.ibpkey.subnet_prefix[3] = c->u.ibpkey.subnet_prefix[3];
+				n->u.ibpkey.low_pkey = c->u.ibpkey.low_pkey;
+				n->u.ibpkey.high_pkey = c->u.ibpkey.high_pkey;
+			break;
 			case OCON_PORT:
 				n->u.port.protocol = c->u.port.protocol;
 				n->u.port.low_port = c->u.port.low_port;
libsepol/src/kernel_to_cil.c +58 -0

70 lines not on this page · raw message

libsepol/src/kernel_to_conf.c +59 -0

71 lines not on this page · raw message

libsepol/src/libsepol.map.in +1 -0
index 4042640..36225d1 100644
@@ -6,6 +6,7 @@ LIBSEPOL_1.0 {
 	sepol_context_*; sepol_mls_*; sepol_check_context;
 	sepol_iface_*; 
 	sepol_port_*;
+	sepol_ibpkey_*;
 	sepol_node_*;
 	sepol_user_*; sepol_genusers; sepol_set_delusers;
 	sepol_msg_*; sepol_debug;
libsepol/src/module_to_cil.c +38 -0
index 7d8eb20..c97f453 100644
@@ -3,6 +3,7 @@
  * Functions to convert policy module to CIL
  *
  * Copyright (C) 2015 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -2656,6 +2657,42 @@ exit:
 	return rc;
 }
 
+static int ocontext_selinux_ibpkey_to_cil(struct policydb *pdb,
+					struct ocontext *ibpkeycons)
+{
+	int rc = -1;
+	struct ocontext *ibpkeycon;
+	char subnet_prefix[INET6_ADDRSTRLEN];
+	uint16_t high;
+	uint16_t low;
+
+	for (ibpkeycon = ibpkeycons; ibpkeycon; ibpkeycon = ibpkeycon->next) {
+		low = ibpkeycon->u.ibpkey.low_pkey;
+		high = ibpkeycon->u.ibpkey.high_pkey;
+
+		if (inet_ntop(AF_INET6, &ibpkeycon->u.ibpkey.subnet_prefix,
+			      subnet_prefix, INET6_ADDRSTRLEN) == NULL) {
+			log_err("ibpkeycon subnet_prefix is invalid: %s",
+				strerror(errno));
+			rc = -1;
+			goto exit;
+		}
+
+		if (low == high)
+			cil_printf("(ibpkeycon %s %i ", subnet_prefix, low);
+		else
+			cil_printf("(ibpkeycon %s (%i %i) ", subnet_prefix, low,
+				   high);
+
+		context_to_cil(pdb, &ibpkeycon->context[0]);
+
+		cil_printf(")\n");
+	}
+	return 0;
+exit:
+	return rc;
+}
+
 static int ocontext_selinux_netif_to_cil(struct policydb *pdb, struct ocontext *netifs)
 {
 	struct ocontext *netif;
@@ -2889,6 +2926,7 @@ static int ocontexts_to_cil(struct policydb *pdb)
 		ocontext_selinux_node_to_cil,
 		ocontext_selinux_fsuse_to_cil,
 		ocontext_selinux_node6_to_cil,
+		ocontext_selinux_ibpkey_to_cil,
 	};
 	static int (*ocon_xen_funcs[OCON_NUM])(struct policydb *pdb, struct ocontext *ocon) = {
 		ocontext_xen_isid_to_cil,
libsepol/src/policydb.c +37 -0
index 7093b29..d6e8e6f 100644
@@ -18,6 +18,7 @@
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2005 Tresys Technology, LLC
  * Copyright (C) 2003 - 2007 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies Inc.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -186,6 +187,13 @@ static struct policydb_compat_info policydb_compat[] = {
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
 	{
+	 .type = POLICY_KERN,
+	 .version = POLICYDB_VERSION_INFINIBAND,
+	 .sym_num = SYM_NUM,
+	 .ocon_num = OCON_IBPKEY + 1,
+	 .target_platform = SEPOL_TARGET_SELINUX,
+	},
+	{
 	 .type = POLICY_BASE,
 	 .version = MOD_POLICYDB_VERSION_BASE,
 	 .sym_num = SYM_NUM,
@@ -284,6 +292,13 @@ static struct policydb_compat_info policydb_compat[] = {
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
 	{
+	 .type = POLICY_BASE,
+	 .version = MOD_POLICYDB_VERSION_INFINIBAND,
+	 .sym_num = SYM_NUM,
+	 .ocon_num = OCON_IBPKEY + 1,
+	 .target_platform = SEPOL_TARGET_SELINUX,
+	},
+	{
 	 .type = POLICY_MOD,
 	 .version = MOD_POLICYDB_VERSION_BASE,
 	 .sym_num = SYM_NUM,
@@ -381,6 +396,13 @@ static struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = 0,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
+	{
+	 .type = POLICY_MOD,
+	 .version = MOD_POLICYDB_VERSION_INFINIBAND,
+	 .sym_num = SYM_NUM,
+	 .ocon_num = 0,
+	 .target_platform = SEPOL_TARGET_SELINUX,
+	},
 };
 
 #if 0
@@ -2782,6 +2804,21 @@ static int ocontext_read_selinux(struct policydb_compat_info *info,
 				    (&c->context[1], p, fp))
 					return -1;
 				break;
+			case OCON_IBPKEY:
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 6);
+				if (rc < 0 || buf[2] || buf[3])
+					return -1;
+
+				c->u.ibpkey.subnet_prefix[0] = buf[0];
+				c->u.ibpkey.subnet_prefix[1] = buf[1];
+
+				c->u.ibpkey.low_pkey = le32_to_cpu(buf[4]);
+				c->u.ibpkey.high_pkey = le32_to_cpu(buf[5]);
+
+				if (context_read_and_validate
+				    (&c->context[0], p, fp))
+					return -1;
+				break;
 			case OCON_PORT:
 				rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
 				if (rc < 0)
libsepol/src/services.c +51 -0

63 lines not on this page · raw message

libsepol/src/write.c +16 -0
index e75b9ab..fa1b7d1 100644
@@ -16,6 +16,7 @@
  *
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003-2005 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -1410,6 +1411,21 @@ static int ocontext_write_selinux(struct policydb_compat_info *info,
 				if (context_write(p, &c->context[1], fp))
 					return POLICYDB_ERROR;
 				break;
+			case OCON_IBPKEY:
+				 /* The subnet prefix is in network order */
+				for (j = 0; j < 4; j++)
+					buf[j] = c->u.ibpkey.subnet_prefix[j];
+
+				buf[4] = cpu_to_le32(c->u.ibpkey.low_pkey);
+				buf[5] = cpu_to_le32(c->u.ibpkey.high_pkey);
+
+				items = put_entry(buf, sizeof(uint32_t), 6, fp);
+				if (items != 6)
+					return POLICYDB_ERROR;
+
+				if (context_write(p, &c->context[0], fp))
+					return POLICYDB_ERROR;
+				break;
 			case OCON_PORT:
 				buf[0] = c->u.port.protocol;
 				buf[1] = c->u.port.low_port;
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v1 2/9] libsepol: Add ibpkey ocontext handling

Quoted 3 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying Infinabinda Pkey

Infiniband

Quoted 40 lines

ocontext
data. Also add support for querying a Pkey sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed domain and type params from sepol_ibpkey_sid.
- Removed splen param from sepol_ibpkey_sid, it never varied.
- Removed extra XPERMS_IOCTL version from policydb_compat_info.
- Confirm that low order bytes of IPv6 addr for subnet prefix is 0's.

James Carter:
- Added ibpkey handling to kernel_to_cil.c and kernel_to_conf.c

---
 checkpolicy/checkpolicy.c                  | 25 +++++++++++++ libsepol/include/sepol/policydb/services.h |  8 ++++ libsepol/src/expand.c                      |  9 +++++ libsepol/src/kernel_to_cil.c               | 58
+++++++++++++++++++++++++++++
 libsepol/src/kernel_to_conf.c              | 59
++++++++++++++++++++++++++++++
 libsepol/src/libsepol.map.in               |  1 + libsepol/src/module_to_cil.c               | 38 +++++++++++++++++++ libsepol/src/policydb.c                    | 37 +++++++++++++++++++ libsepol/src/services.c                    | 51
++++++++++++++++++++++++++
 libsepol/src/write.c                       | 16 ++++++++

 10 files changed, 302 insertions(+)
libsepol/include/sepol/policydb/services.h +0 -0
index 9162149..459254e 100644
@@ -188,6 +188,14 @@ extern int sepol_port_sid(uint16_t domain,
Quoted 8 lines

    uint16_t port, sepol_security_id_t * out_sid);

 /*
+ * Return the SID of the ibpkey specified by
+ * subnet prefix', and pkey'.
+ */
+extern int sepol_ibpkey_sid(void *subnet_prefix_p,

Why void *? Can't this just be struct in6_addr *subnet_prefix or uint32_t subnet_prefix[]? The only reason we use void *addr in sepol_node_sid() is because that argument can actually vary depending on the domain. Likely can be const too.

Quoted 32 lines
libsepol/include/sepol/policydb/services.h +4 -0
+			    uint16_t pkey,
+			    sepol_security_id_t *out_sid);
+
+/*

  * Return the SIDs to use for a network interface
  * with the name name'.  The if_sid' SID is returned for
  * the interface and the `msg_sid' SID is returned as

libsepol/src/expand.c +5 -0
index 54bf781..c45ecbe 100644
@@ -4,6 +4,7 @@
   *
   * Copyright (C) 2004-2005 Tresys Technology, LLC
   * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies, Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -2217,6 +2218,14 @@ static int
 ocontext_copy_selinux(expand_state_t *state)
  					return -1;
  				}
  				break;
+			case OCON_IBPKEY:
+				n->u.ibpkey.subnet_prefix[0] = c-
 >u.ibpkey.subnet_prefix[0];
+				n->u.ibpkey.subnet_prefix[1] = c-
 >u.ibpkey.subnet_prefix[1];
+				n->u.ibpkey.subnet_prefix[2] = c-
Quoted 1 line

u.ibpkey.subnet_prefix[2];

libsepol/src/expand.c +1 -0
+				n->u.ibpkey.subnet_prefix[3] = c-
Quoted 1 line
Quoted 1 line

u.ibpkey.subnet_prefix[3];

[2] and [3] should always be zero.

Quoted 17 lines
libsepol/src/expand.c +1 -0
+				n->u.ibpkey.low_pkey = c-
Quoted 1 line

u.ibpkey.low_pkey;

libsepol/src/expand.c +1 -0
+				n->u.ibpkey.high_pkey = c-
Quoted 1 line

u.ibpkey.high_pkey;

libsepol/src/expand.c +1 -0
+			break;

  case OCON_PORT:
  n->u.port.protocol = c-

Quoted 1 line

u.port.protocol;

  n->u.port.low_port = c-

Quoted 1 line

u.port.low_port;

libsepol/src/policydb.c +0 -0
index 7093b29..d6e8e6f 100644

libsepol/src/policydb.c static int ocontext_read_selinux(struct · line 2812

Quoted 9 lines
libsepol/src/policydb.c +4 -0
@@ -2782,6 +2804,21 @@ static int ocontext_read_selinux(struct
 policydb_compat_info *info,
  				    (&c->context[1], p, fp))
  					return -1;
  				break;
+			case OCON_IBPKEY:
+				rc = next_entry(buf, fp,
 sizeof(uint32_t) * 6);
+				if (rc < 0 || buf[2] || buf[3])
+					return -1;

Kernel code also rejects buf[4] or buf[5] > 0xffff.

Quoted 43 lines
libsepol/src/policydb.c +3 -0
+
+				c->u.ibpkey.subnet_prefix[0] =
 buf[0];
+				c->u.ibpkey.subnet_prefix[1] =

buf[1];

libsepol/src/policydb.c +2 -0
+
+				c->u.ibpkey.low_pkey =

le32_to_cpu(buf[4]);

libsepol/src/policydb.c +1 -0
+				c->u.ibpkey.high_pkey =

le32_to_cpu(buf[5]);

libsepol/src/policydb.c +5 -0
+
+				if (context_read_and_validate
+				    (&c->context[0], p, fp))
+					return -1;
+				break;

  case OCON_PORT:
  rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
  if (rc < 0)

libsepol/src/write.c +3 -0
index e75b9ab..fa1b7d1 100644
@@ -16,6 +16,7 @@
   *
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003-2005 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -1410,6 +1411,21 @@ static int ocontext_write_selinux(struct
 policydb_compat_info *info,
  				if (context_write(p, &c->context[1], 
 fp))
  					return POLICYDB_ERROR;
  				break;
+			case OCON_IBPKEY:
+				 /* The subnet prefix is in network

order */

libsepol/src/write.c +2 -0
+				for (j = 0; j < 4; j++)
+					buf[j] = c-
Quoted 1 line
Quoted 1 line

u.ibpkey.subnet_prefix[j];

Kernel write code always writes [2] and [3] as 0.

Quoted 18 lines
libsepol/src/write.c +2 -0
+
+				buf[4] = cpu_to_le32(c-
Quoted 1 line

u.ibpkey.low_pkey);

libsepol/src/write.c +1 -0
+				buf[5] = cpu_to_le32(c-
Quoted 1 line

u.ibpkey.high_pkey);

libsepol/src/write.c +2 -0
+
+				items = put_entry(buf,

sizeof(uint32_t), 6, fp);

libsepol/src/write.c +4 -0
+				if (items != 6)
+					return POLICYDB_ERROR;
+
+				if (context_write(p, &c->context[0], 

fp))

libsepol/src/write.c +2 -0
+					return POLICYDB_ERROR;
+				break;

  case OCON_PORT:
  buf[0] = c->u.port.protocol; buf[1] = c->u.port.low_port;

#6 lore raw

Re: [PATCH v1 2/9] libsepol: Add ibpkey ocontext handling

Quoted 177 lines · Stephen Smalley
Quoted 3 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying Infinabinda Pkey

Infiniband

Quoted 42 lines

ocontext
data. Also add support for querying a Pkey sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed domain and type params from sepol_ibpkey_sid.
- Removed splen param from sepol_ibpkey_sid, it never varied.
- Removed extra XPERMS_IOCTL version from policydb_compat_info.
- Confirm that low order bytes of IPv6 addr for subnet prefix is 0's.

James Carter:
- Added ibpkey handling to kernel_to_cil.c and kernel_to_conf.c

---
 checkpolicy/checkpolicy.c                  | 25 +++++++++++++ libsepol/include/sepol/policydb/services.h |  8 ++++ libsepol/src/expand.c                      |  9 +++++ libsepol/src/kernel_to_cil.c               | 58
+++++++++++++++++++++++++++++
 libsepol/src/kernel_to_conf.c              | 59
++++++++++++++++++++++++++++++
 libsepol/src/libsepol.map.in               |  1 + libsepol/src/module_to_cil.c               | 38
+++++++++++++++++++
 libsepol/src/policydb.c                    | 37
+++++++++++++++++++
 libsepol/src/services.c                    | 51
++++++++++++++++++++++++++
 libsepol/src/write.c                       | 16 ++++++++

 10 files changed, 302 insertions(+)
libsepol/include/sepol/policydb/services.h +0 -0
index 9162149..459254e 100644
@@ -188,6 +188,14 @@ extern int sepol_port_sid(uint16_t domain,
Quoted 8 lines

    uint16_t port, sepol_security_id_t * out_sid);

 /*
+ * Return the SID of the ibpkey specified by
+ * subnet prefix', and pkey'.
+ */
+extern int sepol_ibpkey_sid(void *subnet_prefix_p,

Why void *?  Can't this just be struct in6_addr *subnet_prefix or uint32_t subnet_prefix[]?  The only reason we use void *addr in sepol_node_sid() is because that argument can actually vary depending on the domain.  Likely can be const too.

Quoted 35 lines
libsepol/include/sepol/policydb/services.h +4 -0
+			    uint16_t pkey,
+			    sepol_security_id_t *out_sid);
+
+/*

  * Return the SIDs to use for a network interface
  * with the name name'.  The if_sid' SID is returned for
  * the interface and the `msg_sid' SID is returned as

libsepol/src/expand.c +4 -0
index 54bf781..c45ecbe 100644
@@ -4,6 +4,7 @@
   *
   * Copyright (C) 2004-2005 Tresys Technology, LLC
   * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies, Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -2217,6 +2218,14 @@ static int
 ocontext_copy_selinux(expand_state_t *state)
  					return -1;
  				}
  				break;
+			case OCON_IBPKEY:
+				n->u.ibpkey.subnet_prefix[0] = c-
 > u.ibpkey.subnet_prefix[0];
 
+				n->u.ibpkey.subnet_prefix[1] = c-
Quoted 1 line

u.ibpkey.subnet_prefix[1];

libsepol/src/expand.c +1 -0
+				n->u.ibpkey.subnet_prefix[2] = c-
Quoted 1 line

u.ibpkey.subnet_prefix[2];

libsepol/src/expand.c +1 -0
+				n->u.ibpkey.subnet_prefix[3] = c-
Quoted 1 line
Quoted 1 line

u.ibpkey.subnet_prefix[3];

[2] and [3] should always be zero.

Quoted 19 lines
libsepol/src/expand.c +1 -0
+				n->u.ibpkey.low_pkey = c-
Quoted 1 line

u.ibpkey.low_pkey;

libsepol/src/expand.c +1 -0
+				n->u.ibpkey.high_pkey = c-
Quoted 1 line

u.ibpkey.high_pkey;

libsepol/src/expand.c +1 -0
+			break;

  case OCON_PORT:
  n->u.port.protocol = c-

Quoted 1 line

u.port.protocol;

  n->u.port.low_port = c-

Quoted 1 line

u.port.low_port;

libsepol/src/policydb.c +0 -0
index 7093b29..d6e8e6f 100644

libsepol/src/policydb.c static int ocontext_read_selinux(struct · line 2812

Quoted 9 lines
libsepol/src/policydb.c +4 -0
@@ -2782,6 +2804,21 @@ static int ocontext_read_selinux(struct
 policydb_compat_info *info,
  				    (&c->context[1], p, fp))
  					return -1;
  				break;
+			case OCON_IBPKEY:
+				rc = next_entry(buf, fp,
 sizeof(uint32_t) * 6);
+				if (rc < 0 || buf[2] || buf[3])
+					return -1;

Kernel code also rejects buf[4] or buf[5] > 0xffff.

Quoted 44 lines
libsepol/src/policydb.c +3 -0
+
+				c->u.ibpkey.subnet_prefix[0] =
 buf[0];
+				c->u.ibpkey.subnet_prefix[1] =

buf[1];

libsepol/src/policydb.c +2 -0
+
+				c->u.ibpkey.low_pkey =

le32_to_cpu(buf[4]);

libsepol/src/policydb.c +1 -0
+				c->u.ibpkey.high_pkey =

le32_to_cpu(buf[5]);

libsepol/src/policydb.c +5 -0
+
+				if (context_read_and_validate
+				    (&c->context[0], p, fp))
+					return -1;
+				break;

  case OCON_PORT:
  rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
  if (rc < 0)

libsepol/src/write.c +1 -0
index e75b9ab..fa1b7d1 100644
@@ -16,6 +16,7 @@
   *
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003-2005 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -1410,6 +1411,21 @@ static int ocontext_write_selinux(struct
 policydb_compat_info *info,

  if (context_write(p, &c-

Quoted 1 line

context[1],

fp))
  return POLICYDB_ERROR; break;

libsepol/src/write.c +2 -0
+			case OCON_IBPKEY:
+				 /* The subnet prefix is in

network
order */

libsepol/src/write.c +2 -0
+				for (j = 0; j < 4; j++)
+					buf[j] = c-
Quoted 3 lines
Quoted 1 line
Quoted 1 line

u.ibpkey.subnet_prefix[j];

Kernel write code always writes [2] and [3] as 0.

This btw again raises the question of whether it worth storing them in the binary policy at all.

Quoted 22 lines
Quoted 22 lines
libsepol/src/write.c +2 -0
+
+				buf[4] = cpu_to_le32(c-
Quoted 1 line

u.ibpkey.low_pkey);

libsepol/src/write.c +1 -0
+				buf[5] = cpu_to_le32(c-
Quoted 1 line

u.ibpkey.high_pkey);

libsepol/src/write.c +2 -0
+
+				items = put_entry(buf,

sizeof(uint32_t), 6, fp);

libsepol/src/write.c +4 -0
+				if (items != 6)
+					return POLICYDB_ERROR;
+
+				if (context_write(p, &c-
Quoted 1 line

context[0],

fp))

libsepol/src/write.c +2 -0
+					return POLICYDB_ERROR;
+				break;

  case OCON_PORT:
  buf[0] = c->u.port.protocol; buf[1] = c->u.port.low_port;

#7 lore raw

Re: [PATCH v1 2/9] libsepol: Add ibpkey ocontext handling

Quoted 11 lines · Stephen Smalley
Quoted 10 lines · Stephen Smalley
Quoted 9 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

(quoted diff) +2 -0
+			case OCON_IBPKEY:
+				 /* The subnet prefix is in

network
order */

(quoted diff) +2 -0
+				for (j = 0; j < 4; j++)
+					buf[j] = c-
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

u.ibpkey.subnet_prefix[j];

Kernel write code always writes [2] and [3] as 0.

This btw again raises the question of whether it worth storing them in the binary policy at all.

Done, just store the upper 8 bytes in the policy now.

#8 lore raw

Re: [PATCH v1 2/9] libsepol: Add ibpkey ocontext handling

In reply to Stephen Smalley
Quoted 48 lines · Stephen Smalley
Quoted 3 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying Infinabinda Pkey

Infiniband

Quoted 42 lines

ocontext
data. Also add support for querying a Pkey sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed domain and type params from sepol_ibpkey_sid.
- Removed splen param from sepol_ibpkey_sid, it never varied.
- Removed extra XPERMS_IOCTL version from policydb_compat_info.
- Confirm that low order bytes of IPv6 addr for subnet prefix is 0's.

James Carter:
- Added ibpkey handling to kernel_to_cil.c and kernel_to_conf.c

---
 checkpolicy/checkpolicy.c                  | 25 +++++++++++++
 libsepol/include/sepol/policydb/services.h |  8 ++++
 libsepol/src/expand.c                      |  9 +++++
 libsepol/src/kernel_to_cil.c               | 58
+++++++++++++++++++++++++++++
 libsepol/src/kernel_to_conf.c              | 59
++++++++++++++++++++++++++++++
 libsepol/src/libsepol.map.in               |  1 +
 libsepol/src/module_to_cil.c               | 38 +++++++++++++++++++
 libsepol/src/policydb.c                    | 37 +++++++++++++++++++
 libsepol/src/services.c                    | 51
++++++++++++++++++++++++++
 libsepol/src/write.c                       | 16 ++++++++
 10 files changed, 302 insertions(+)
libsepol/include/sepol/policydb/services.h +0 -0
index 9162149..459254e 100644
@@ -188,6 +188,14 @@ extern int sepol_port_sid(uint16_t domain,
 			  uint16_t port, sepol_security_id_t *
 out_sid);
 
Quoted 9 lines

libsepol/include/sepol/policydb/services.h extern int sepol_port_sid(uint16_t domain, · line 194

Quoted 5 lines
libsepol/include/sepol/policydb/services.h +4 -0
 /*
+ * Return the SID of the ibpkey specified by
+ * `subnet prefix', and `pkey'.
+ */
+extern int sepol_ibpkey_sid(void *subnet_prefix_p,

Why void *? Can't this just be struct in6_addr *subnet_prefix or uint32_t subnet_prefix[]? The only reason we use void *addr in sepol_node_sid() is because that argument can actually vary depending on the domain. Likely can be const too.

Changed to uint32_t *, since that's what the type is in the ocontext structure. Added const.

Quoted 5 lines

libsepol/include/sepol/policydb/services.h extern int sepol_port_sid(uint16_t domain, · line 199

Quoted 4 lines
libsepol/include/sepol/policydb/services.h +2 -0
+				n->u.ibpkey.subnet_prefix[2] = c-
 > u.ibpkey.subnet_prefix[2];
+				n->u.ibpkey.subnet_prefix[3] = c-
 > u.ibpkey.subnet_prefix[3];

[2] and [3] should always be zero.

Done

Quoted 16 lines
Quoted 16 lines
libsepol/include/sepol/policydb/services.h +1 -0
+				n->u.ibpkey.low_pkey = c-
Quoted 1 line

u.ibpkey.low_pkey;

libsepol/include/sepol/policydb/services.h +1 -0
+				n->u.ibpkey.high_pkey = c-
Quoted 1 line

u.ibpkey.high_pkey;

libsepol/include/sepol/policydb/services.h +1 -0
+			break;
 			case OCON_PORT:
 				n->u.port.protocol = c-
Quoted 1 line

u.port.protocol;

n->u.port.low_port = c-

Quoted 1 line

u.port.low_port;

libsepol/src/policydb.c +0 -0
index 7093b29..d6e8e6f 100644
Quoted 11 lines

libsepol/src/policydb.c static int ocontext_read_selinux(struct · line 2812

Quoted 10 lines
libsepol/src/policydb.c +4 -0
@@ -2782,6 +2804,21 @@ static int ocontext_read_selinux(struct
 policydb_compat_info *info,
 				    (&c->context[1], p, fp))
 					return -1;
 				break;
+			case OCON_IBPKEY:
+				rc = next_entry(buf, fp,
 sizeof(uint32_t) * 6);
+				if (rc < 0 || buf[2] || buf[3])
+					return -1;

Kernel code also rejects buf[4] or buf[5] > 0xffff.

Done

Quoted 11 lines
Quoted 11 lines
libsepol/src/policydb.c +2 -0
@@ -1410,6 +1411,21 @@ static int ocontext_write_selinux(struct
 policydb_compat_info *info,
 				if (context_write(p, &c->context[1], 
 fp))
 					return POLICYDB_ERROR;
 				break;
+			case OCON_IBPKEY:
+				 /* The subnet prefix is in network

order */

libsepol/src/policydb.c +2 -0
+				for (j = 0; j < 4; j++)
+					buf[j] = c-
Quoted 2 lines
Quoted 1 line
Quoted 1 line

u.ibpkey.subnet_prefix[j];

Kernel write code always writes [2] and [3] as 0.

Done

#9 lore raw

Re: [PATCH v1 2/9] libsepol: Add ibpkey ocontext handling

In reply to Dan Jurgens
Quoted 256 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying Infinabinda Pkey ocontext data. Also add support for querying a Pkey sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed domain and type params from sepol_ibpkey_sid.
- Removed splen param from sepol_ibpkey_sid, it never varied.
- Removed extra XPERMS_IOCTL version from policydb_compat_info.
- Confirm that low order bytes of IPv6 addr for subnet prefix is 0's.

James Carter:
- Added ibpkey handling to kernel_to_cil.c and kernel_to_conf.c

---
  checkpolicy/checkpolicy.c                  | 25 +++++++++++++
  libsepol/include/sepol/policydb/services.h |  8 ++++
  libsepol/src/expand.c                      |  9 +++++
  libsepol/src/kernel_to_cil.c               | 58 +++++++++++++++++++++++++++++
  libsepol/src/kernel_to_conf.c              | 59 ++++++++++++++++++++++++++++++
  libsepol/src/libsepol.map.in               |  1 +
  libsepol/src/module_to_cil.c               | 38 +++++++++++++++++++
  libsepol/src/policydb.c                    | 37 +++++++++++++++++++
  libsepol/src/services.c                    | 51 ++++++++++++++++++++++++++
  libsepol/src/write.c                       | 16 ++++++++
  10 files changed, 302 insertions(+)
checkpolicy/checkpolicy.c +25 -0
index 534fc22..d0e46ba 100644
@@ -22,6 +22,7 @@
   *
   *	Policy Module support.
   *
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003 - 2005 Tresys Technology, LLC
   * Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]>
@@ -699,6 +700,7 @@ int main(int argc, char **argv)
  	printf("h)  change a boolean value\n");
  	printf("i)  display constraint expressions\n");
  	printf("j)  display validatetrans expressions\n");
+	printf("k)  Call ibpkey_sid\n");
  #ifdef EQUIVTYPES
  	printf("z)  Show equivalent types\n");
  #endif
@@ -1220,6 +1222,29 @@ int main(int argc, char **argv)
  				    "\nNo validatetrans expressions found.\n");
  			}
  			break;
+		case 'k':
+			{
+				char *p;
+				struct in6_addr addr6;
+				unsigned int pkey;
+
+				printf("subnet prefix?  ");
+				FGETS(ans, sizeof(ans), stdin);
+				ans[strlen(ans) - 1] = 0;
+				p = (char *)&addr6;
+
+				if (inet_pton(AF_INET6, ans, p) < 1) {
+					printf("error parsing subnet prefix\n");
+					break;
+				}
+
+				printf("pkey? ");
+				FGETS(ans, sizeof(ans), stdin);
+				pkey = atoi(ans);
+				sepol_ibpkey_sid(p, pkey, &ssid);
+				printf("sid %d\n", ssid);
+			}
+			break;
  #ifdef EQUIVTYPES
  		case 'z':
  			identify_equiv_types();
libsepol/include/sepol/policydb/services.h +8 -0
index 9162149..459254e 100644
@@ -188,6 +188,14 @@ extern int sepol_port_sid(uint16_t domain,
  			  uint16_t port, sepol_security_id_t * out_sid);
 
  /*
+ * Return the SID of the ibpkey specified by
+ * `subnet prefix', and `pkey'.
+ */
+extern int sepol_ibpkey_sid(void *subnet_prefix_p,
+			    uint16_t pkey,
+			    sepol_security_id_t *out_sid);
+
+/*
   * Return the SIDs to use for a network interface
   * with the name `name'.  The `if_sid' SID is returned for
   * the interface and the `msg_sid' SID is returned as
libsepol/src/expand.c +9 -0
index 54bf781..c45ecbe 100644
@@ -4,6 +4,7 @@
   *
   * Copyright (C) 2004-2005 Tresys Technology, LLC
   * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies, Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -2217,6 +2218,14 @@ static int ocontext_copy_selinux(expand_state_t *state)
  					return -1;
  				}
  				break;
+			case OCON_IBPKEY:
+				n->u.ibpkey.subnet_prefix[0] = c->u.ibpkey.subnet_prefix[0];
+				n->u.ibpkey.subnet_prefix[1] = c->u.ibpkey.subnet_prefix[1];
+				n->u.ibpkey.subnet_prefix[2] = c->u.ibpkey.subnet_prefix[2];
+				n->u.ibpkey.subnet_prefix[3] = c->u.ibpkey.subnet_prefix[3];
+				n->u.ibpkey.low_pkey = c->u.ibpkey.low_pkey;
+				n->u.ibpkey.high_pkey = c->u.ibpkey.high_pkey;
+			break;
  			case OCON_PORT:
  				n->u.port.protocol = c->u.port.protocol;
  				n->u.port.low_port = c->u.port.low_port;
libsepol/src/kernel_to_cil.c +58 -0
index 3a1c0be..fcfd0e0 100644
@@ -2784,6 +2784,59 @@ exit:
  	return rc;
  }
 
+static int write_selinux_ibpkey_rules_to_cil(FILE *out, struct policydb *pdb)
+{
+	struct ocontext *ibpkeycon;
+	char subnet_prefix[INET6_ADDRSTRLEN];
+	uint16_t low;
+	uint16_t high;
+	char low_high_str[44]; /* 2^64 <= 20 digits so "(low high)" <= 44 chars */
+	char *ctx;
+	int rc = 0;
+
+	for (ibpkeycon = pdb->ocontexts[OCON_IBPKEY]; ibpkeycon != NULL;
+	     ibpkeycon = ibpkeycon->next) {
+		if (inet_ntop(AF_INET6, &ibpkeycon->u.ibpkey.subnet_prefix,
+			      subnet_prefix, INET6_ADDRSTRLEN) == NULL) {
+			sepol_log_err("ibpkeycon subnet_prefix is invalid: %s",
+				      strerror(errno));
+			rc = -1;
+			goto exit;
+		}
+
+		low = ibpkeycon->u.ibpkey.low_pkey;
+		high = ibpkeycon->u.ibpkey.high_pkey;
+		if (low == high) {
+			rc = snprintf(low_high_str, 44, "%u", low);
+		} else {
+			rc = snprintf(low_high_str, 44, "(%u %u)", low, high);
+		}
+		if (rc < 0 || rc >= 44) {
+			rc = -1;
+			goto exit;
+		}
+
+		ctx = context_to_str(pdb, &ibpkeycon->context[0]);
+		if (!ctx) {
+			rc = -1;
+			goto exit;
+		}
+
+		sepol_printf(out, "(ibpkeycon %s %s %s)\n", subnet_prefix, low_high_str, ctx);
+
+		free(ctx);
+	}
+
+	rc = 0;
+
+exit:
+	if (rc != 0) {
+		sepol_log_err("Error writing ibpkeycon rules to CIL\n");
+	}
+
+	return rc;
+}
+
  static int write_xen_isid_rules_to_cil(FILE *out, struct policydb *pdb)
  {
  	return write_sid_context_rules_to_cil(out, pdb, xen_sid_to_str);
@@ -3180,6 +3233,11 @@ int sepol_kernel_policydb_to_cil(FILE *out, struct policydb *pdb)
  		if (rc != 0) {
  			goto exit;
  		}
+
+		rc = write_selinux_ibpkey_rules_to_cil(out, pdb);
+		if (rc != 0) {
+			goto exit;
+		}
  	} else if (pdb->target_platform == SEPOL_TARGET_XEN) {
  		rc = write_xen_isid_rules_to_cil(out, pdb);
  		if (rc != 0) {
libsepol/src/kernel_to_conf.c +44 -0
index 22a0909..795cf56 100644
@@ -2645,6 +2645,60 @@ exit:
  	return rc;
  }
 
+static int write_selinux_ibpkey_rules_to_conf(FILE *out, struct policydb *pdb)
+{
+	struct ocontext *ibpkeycon;
+	char subnet_prefix[INET6_ADDRSTRLEN];
+	uint16_t low;
+	uint16_t high;
+	char low_high_str[44]; /* 2^64 <= 20 digits so "low-high" <= 44 chars */
+	char *ctx;
+	int rc = 0;
+
+	for (ibpkeycon = pdb->ocontexts[OCON_IBPKEY]; ibpkeycon != NULL;
+	     ibpkeycon = ibpkeycon->next) {
+		if (inet_ntop(AF_INET6, &ibpkeycon->u.ibpkey.subnet_prefix,
+			      subnet_prefix, INET6_ADDRSTRLEN) == NULL) {
+			sepol_log_err("ibpkeycon address is invalid: %s",
+				      strerror(errno));
+			rc = -1;
+			goto exit;
+		}
+
+		low = ibpkeycon->u.ibpkey.low_pkey;
+		high = ibpkeycon->u.ibpkey.high_pkey;
+		if (low == high) {
+			rc = snprintf(low_high_str, 44, "%u", low);
+		} else {
+			rc = snprintf(low_high_str, 44, "%u-%u", low, high);
+		}
+		if (rc < 0 || rc >= 44) {
+			rc = -1;
+			goto exit;
+		}
+
+		ctx = context_to_str(pdb, &ibpkeycon->context[0]);
+		if (!ctx) {
+			rc = -1;
+			goto exit;
+		}
+
+		sepol_printf(out, "ibpkeycon %s %s %s\n", subnet_prefix,
+			     low_high_str, ctx);
+
+		free(ctx);
+	}
+

libsepol/src/kernel_to_conf.c exit: · line 2701

Quoted 10 lines
libsepol/src/kernel_to_conf.c +10 -0
+	rc = 0;
+
+exit:
+	if (rc != 0) {
+		sepol_log_err("Error writing ibpkeycon rules to policy.conf\n");
+	}
+
+	return rc;
+}
+

I forgot to mention that you also need to add a compare function (should be similar to the one you made for cil_post.c) and modify sort_ocontexts() in kernel_to_common.c so that the ibpkey rules get sorted.

Quoted 270 lines
libsepol/src/kernel_to_conf.c +5 -0
  static int write_xen_isid_rules_to_conf(FILE *out, struct policydb *pdb)
  {
  	return write_sid_context_rules_to_conf(out, pdb, xen_sid_to_str);
@@ -3045,6 +3099,11 @@ int sepol_kernel_policydb_to_conf(FILE *out, struct policydb *pdb)
  		if (rc != 0) {
  			goto exit;
  		}
+
+		rc = write_selinux_ibpkey_rules_to_conf(out, pdb);
+		if (rc != 0) {
+			goto exit;
+		}
  	} else if (pdb->target_platform == SEPOL_TARGET_XEN) {
  		rc = write_xen_isid_rules_to_conf(out, pdb);
  		if (rc != 0) {
libsepol/src/libsepol.map.in +1 -0
index 4042640..36225d1 100644
@@ -6,6 +6,7 @@ LIBSEPOL_1.0 {
  	sepol_context_*; sepol_mls_*; sepol_check_context;
  	sepol_iface_*;
  	sepol_port_*;
+	sepol_ibpkey_*;
  	sepol_node_*;
  	sepol_user_*; sepol_genusers; sepol_set_delusers;
  	sepol_msg_*; sepol_debug;
libsepol/src/module_to_cil.c +38 -0
index 7d8eb20..c97f453 100644
@@ -3,6 +3,7 @@
   * Functions to convert policy module to CIL
   *
   * Copyright (C) 2015 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -2656,6 +2657,42 @@ exit:
  	return rc;
  }
 
+static int ocontext_selinux_ibpkey_to_cil(struct policydb *pdb,
+					struct ocontext *ibpkeycons)
+{
+	int rc = -1;
+	struct ocontext *ibpkeycon;
+	char subnet_prefix[INET6_ADDRSTRLEN];
+	uint16_t high;
+	uint16_t low;
+
+	for (ibpkeycon = ibpkeycons; ibpkeycon; ibpkeycon = ibpkeycon->next) {
+		low = ibpkeycon->u.ibpkey.low_pkey;
+		high = ibpkeycon->u.ibpkey.high_pkey;
+
+		if (inet_ntop(AF_INET6, &ibpkeycon->u.ibpkey.subnet_prefix,
+			      subnet_prefix, INET6_ADDRSTRLEN) == NULL) {
+			log_err("ibpkeycon subnet_prefix is invalid: %s",
+				strerror(errno));
+			rc = -1;
+			goto exit;
+		}
+
+		if (low == high)
+			cil_printf("(ibpkeycon %s %i ", subnet_prefix, low);
+		else
+			cil_printf("(ibpkeycon %s (%i %i) ", subnet_prefix, low,
+				   high);
+
+		context_to_cil(pdb, &ibpkeycon->context[0]);
+
+		cil_printf(")\n");
+	}
+	return 0;
+exit:
+	return rc;
+}
+
  static int ocontext_selinux_netif_to_cil(struct policydb *pdb, struct ocontext *netifs)
  {
  	struct ocontext *netif;
@@ -2889,6 +2926,7 @@ static int ocontexts_to_cil(struct policydb *pdb)
  		ocontext_selinux_node_to_cil,
  		ocontext_selinux_fsuse_to_cil,
  		ocontext_selinux_node6_to_cil,
+		ocontext_selinux_ibpkey_to_cil,
  	};
  	static int (*ocon_xen_funcs[OCON_NUM])(struct policydb *pdb, struct ocontext *ocon) = {
  		ocontext_xen_isid_to_cil,
libsepol/src/policydb.c +37 -0
index 7093b29..d6e8e6f 100644
@@ -18,6 +18,7 @@
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003 - 2005 Tresys Technology, LLC
   * Copyright (C) 2003 - 2007 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -186,6 +187,13 @@ static struct policydb_compat_info policydb_compat[] = {
  	 .target_platform = SEPOL_TARGET_SELINUX,
  	},
  	{
+	 .type = POLICY_KERN,
+	 .version = POLICYDB_VERSION_INFINIBAND,
+	 .sym_num = SYM_NUM,
+	 .ocon_num = OCON_IBPKEY + 1,
+	 .target_platform = SEPOL_TARGET_SELINUX,
+	},
+	{
  	 .type = POLICY_BASE,
  	 .version = MOD_POLICYDB_VERSION_BASE,
  	 .sym_num = SYM_NUM,
@@ -284,6 +292,13 @@ static struct policydb_compat_info policydb_compat[] = {
  	 .target_platform = SEPOL_TARGET_SELINUX,
  	},
  	{
+	 .type = POLICY_BASE,
+	 .version = MOD_POLICYDB_VERSION_INFINIBAND,
+	 .sym_num = SYM_NUM,
+	 .ocon_num = OCON_IBPKEY + 1,
+	 .target_platform = SEPOL_TARGET_SELINUX,
+	},
+	{
  	 .type = POLICY_MOD,
  	 .version = MOD_POLICYDB_VERSION_BASE,
  	 .sym_num = SYM_NUM,
@@ -381,6 +396,13 @@ static struct policydb_compat_info policydb_compat[] = {
  	 .ocon_num = 0,
  	 .target_platform = SEPOL_TARGET_SELINUX,
  	},
+	{
+	 .type = POLICY_MOD,
+	 .version = MOD_POLICYDB_VERSION_INFINIBAND,
+	 .sym_num = SYM_NUM,
+	 .ocon_num = 0,
+	 .target_platform = SEPOL_TARGET_SELINUX,
+	},
  };
 
  #if 0
@@ -2782,6 +2804,21 @@ static int ocontext_read_selinux(struct policydb_compat_info *info,
  				    (&c->context[1], p, fp))
  					return -1;
  				break;
+			case OCON_IBPKEY:
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 6);
+				if (rc < 0 || buf[2] || buf[3])
+					return -1;
+
+				c->u.ibpkey.subnet_prefix[0] = buf[0];
+				c->u.ibpkey.subnet_prefix[1] = buf[1];
+
+				c->u.ibpkey.low_pkey = le32_to_cpu(buf[4]);
+				c->u.ibpkey.high_pkey = le32_to_cpu(buf[5]);
+
+				if (context_read_and_validate
+				    (&c->context[0], p, fp))
+					return -1;
+				break;
  			case OCON_PORT:
  				rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
  				if (rc < 0)
libsepol/src/services.c +51 -0
index 03fb120..4236aac 100644
@@ -21,6 +21,7 @@
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003 - 2004 Tresys Technology, LLC
   * Copyright (C) 2003 - 2004 Red Hat, Inc.
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -1910,6 +1911,56 @@ int hidden sepol_fs_sid(char *name,
  	return rc;
  }
 
+static int match_subnet_prefix(uint32_t *input, uint32_t *subnet_prefix)
+{
+	int i, fail = 0;
+
+	for (i = 0; i < 4; i++)
+		if (subnet_prefix[i] != input[i]) {
+			fail = 1;
+			break;
+		}
+
+	return !fail;
+}
+
+/*
+ * Return the SID of the ibpkey specified by
+ * `subnet prefix', and `pkey number'.
+ */
+int hidden sepol_ibpkey_sid(void *subnet_prefix_p,
+			    uint16_t pkey, sepol_security_id_t *out_sid)
+{
+	ocontext_t *c;
+	int rc = 0;
+
+	c = policydb->ocontexts[OCON_IBPKEY];
+	while (c) {
+		if (c->u.ibpkey.low_pkey <= pkey &&
+		    c->u.ibpkey.high_pkey >= pkey &&
+		    match_subnet_prefix(subnet_prefix_p,
+					c->u.ibpkey.subnet_prefix))
+			break;
+		c = c->next;
+	}
+
+	if (c) {
+		if (!c->sid[0]) {
+			rc = sepol_sidtab_context_to_sid(sidtab,
+							 &c->context[0],
+							 &c->sid[0]);
+			if (rc)
+				goto out;
+		}
+		*out_sid = c->sid[0];
+	} else {
+		*out_sid = SECINITSID_UNLABELED;
+	}
+
+out:
+	return rc;
+}
+
  /*
   * Return the SID of the port specified by
   * `domain', `type', `protocol', and `port'.
libsepol/src/write.c +16 -0
index e75b9ab..fa1b7d1 100644
@@ -16,6 +16,7 @@
   *
   * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
   * Copyright (C) 2003-2005 Tresys Technology, LLC
+ * Copyright (C) 2017 Mellanox Technologies Inc.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
@@ -1410,6 +1411,21 @@ static int ocontext_write_selinux(struct policydb_compat_info *info,
  				if (context_write(p, &c->context[1], fp))
  					return POLICYDB_ERROR;
  				break;
+			case OCON_IBPKEY:
+				 /* The subnet prefix is in network order */
+				for (j = 0; j < 4; j++)
+					buf[j] = c->u.ibpkey.subnet_prefix[j];
+
+				buf[4] = cpu_to_le32(c->u.ibpkey.low_pkey);
+				buf[5] = cpu_to_le32(c->u.ibpkey.high_pkey);
+
+				items = put_entry(buf, sizeof(uint32_t), 6, fp);
+				if (items != 6)
+					return POLICYDB_ERROR;
+
+				if (context_write(p, &c->context[0], fp))
+					return POLICYDB_ERROR;
+				break;
  			case OCON_PORT:
  				buf[0] = c->u.port.protocol;
  				buf[1] = c->u.port.low_port;
Signature · 2 lines
James Carter <[email protected]>
National Security Agency
#10 lore raw

PATCH 3/9 libsepol: Add Infiniband Pkey handling to CIL

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add Infiniband pkey parsing, symbol table management, and policy generation to CIL.

---
 libsepol/cil/src/cil.c             | 19 +++++++++
 libsepol/cil/src/cil_binary.c      | 39 +++++++++++++++++
 libsepol/cil/src/cil_binary.h      | 12 ++++++
 libsepol/cil/src/cil_build_ast.c   | 86 ++++++++++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_build_ast.h   |  2 +
 libsepol/cil/src/cil_copy_ast.c    | 26 ++++++++++++
 libsepol/cil/src/cil_copy_ast.h    |  1 +
 libsepol/cil/src/cil_flavor.h      |  1 +
 libsepol/cil/src/cil_internal.h    | 11 +++++
 libsepol/cil/src/cil_policy.c      | 16 +++++++
 libsepol/cil/src/cil_post.c        | 45 ++++++++++++++++++++
 libsepol/cil/src/cil_post.h        |  1 +
 libsepol/cil/src/cil_reset_ast.c   |  9 ++++
 libsepol/cil/src/cil_resolve_ast.c | 27 ++++++++++++
 libsepol/cil/src/cil_resolve_ast.h |  1 +
 libsepol/cil/src/cil_tree.c        | 16 ++++++-
 libsepol/cil/src/cil_verify.c      | 23 ++++++++++
 17 files changed, 334 insertions(+), 1 deletion(-)
libsepol/cil/src/cil.c +19 -0
index 9b9ccc3..3df670a 100644
@@ -188,6 +188,7 @@ static void cil_init_keys(void)
 	CIL_KEY_MLSVALIDATETRANS = cil_strpool_add("mlsvalidatetrans");
 	CIL_KEY_CONTEXT = cil_strpool_add("context");
 	CIL_KEY_FILECON = cil_strpool_add("filecon");
+	CIL_KEY_IBPKEYCON = cil_strpool_add("ibpkeycon");
 	CIL_KEY_PORTCON = cil_strpool_add("portcon");
 	CIL_KEY_NODECON = cil_strpool_add("nodecon");
 	CIL_KEY_GENFSCON = cil_strpool_add("genfscon");
@@ -257,6 +258,7 @@ void cil_db_init(struct cil_db **db)
 	cil_sort_init(&(*db)->genfscon);
 	cil_sort_init(&(*db)->filecon);
 	cil_sort_init(&(*db)->nodecon);
+	cil_sort_init(&(*db)->ibpkeycon);
 	cil_sort_init(&(*db)->portcon);
 	cil_sort_init(&(*db)->pirqcon);
 	cil_sort_init(&(*db)->iomemcon);
@@ -308,6 +310,7 @@ void cil_db_destroy(struct cil_db **db)
 	cil_sort_destroy(&(*db)->genfscon);
 	cil_sort_destroy(&(*db)->filecon);
 	cil_sort_destroy(&(*db)->nodecon);
+	cil_sort_destroy(&(*db)->ibpkeycon);
 	cil_sort_destroy(&(*db)->portcon);
 	cil_sort_destroy(&(*db)->pirqcon);
 	cil_sort_destroy(&(*db)->iomemcon);
@@ -728,6 +731,9 @@ void cil_destroy_data(void **data, enum cil_flavor flavor)
 	case CIL_FILECON:
 		cil_destroy_filecon(*data);
 		break;
+	case CIL_IBPKEYCON:
+		cil_destroy_ibpkeycon(*data);
+		break;
 	case CIL_PORTCON:
 		cil_destroy_portcon(*data);
 		break;
@@ -1097,6 +1103,8 @@ const char * cil_node_to_string(struct cil_tree_node *node)
 		return CIL_KEY_FSUSE;
 	case CIL_FILECON:
 		return CIL_KEY_FILECON;
+	case CIL_IBPKEYCON:
+		return CIL_KEY_IBPKEYCON;
 	case CIL_PORTCON:
 		return CIL_KEY_PORTCON;
 	case CIL_NODECON:
@@ -2255,6 +2263,17 @@ void cil_filecon_init(struct cil_filecon **filecon)
 	(*filecon)->context = NULL;
 }
 
+void cil_ibpkeycon_init(struct cil_ibpkeycon **ibpkeycon)
+{
+	*ibpkeycon = cil_malloc(sizeof(**ibpkeycon));
+
+	(*ibpkeycon)->subnet_prefix_str = NULL;
+	(*ibpkeycon)->pkey_low = 0;
+	(*ibpkeycon)->pkey_high = 0;
+	(*ibpkeycon)->context_str = NULL;
+	(*ibpkeycon)->context = NULL;
+}
+
 void cil_portcon_init(struct cil_portcon **portcon)
 {
 	*portcon = cil_malloc(sizeof(**portcon));
libsepol/cil/src/cil_binary.c +39 -0
index e1481a4..75398ff 100644
@@ -3218,6 +3218,40 @@ exit:
 	return rc;
 }
 
+int cil_ibpkeycon_to_policydb(policydb_t *pdb, struct cil_sort *ibpkeycons)
+{
+	int rc = SEPOL_ERR;
+	uint32_t i = 0;
+	ocontext_t *tail = NULL;
+	struct in6_addr subnet_prefix;
+
+	for (i = 0; i < ibpkeycons->count; i++) {
+		struct cil_ibpkeycon *cil_ibpkeycon = ibpkeycons->array[i];
+		ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_IBPKEY], &tail);
+
+		rc = inet_pton(AF_INET6, cil_ibpkeycon->subnet_prefix_str, &subnet_prefix);
+		if (rc != 1) {
+			cil_log(CIL_ERR, "ibpkeycon subnet prefix not in valid IPV6 format\n");
+			rc = SEPOL_ERR;
+			goto exit;
+		}
+
+		memcpy(new_ocon->u.ibpkey.subnet_prefix, &subnet_prefix.s6_addr[0],
+		       sizeof(*new_ocon->u.ibpkey.subnet_prefix));
+		new_ocon->u.ibpkey.low_pkey = cil_ibpkeycon->pkey_low;
+		new_ocon->u.ibpkey.high_pkey = cil_ibpkeycon->pkey_high;
+
+		rc = __cil_context_to_sepol_context(pdb, cil_ibpkeycon->context, &new_ocon->context[0]);
+		if (rc != SEPOL_OK)
+			goto exit;
+	}
+
+	return SEPOL_OK;
+
+exit:
+	return rc;
+}
+
 int cil_portcon_to_policydb(policydb_t *pdb, struct cil_sort *portcons)
 {
 	int rc = SEPOL_ERR;
@@ -3848,6 +3882,11 @@ int __cil_contexts_to_policydb(policydb_t *pdb, const struct cil_db *db)
 		goto exit;
 	}
 
+	rc = cil_ibpkeycon_to_policydb(pdb, db->ibpkeycon);
+	if (rc != SEPOL_OK) {
+		goto exit;
+	}
+
 	if (db->target_platform == SEPOL_TARGET_XEN) {
 		rc = cil_pirqcon_to_policydb(pdb, db->pirqcon);
 		if (rc != SEPOL_OK) {
libsepol/cil/src/cil_binary.h +12 -0
index c59b1e3..a03d250 100644
@@ -330,6 +330,18 @@ int cil_sepol_level_define(policydb_t *pdb, struct cil_sens *cil_sens);
 int cil_rangetransition_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_rangetransition *rangetrans, hashtab_t range_trans_table);
 
 /**
+ * Insert cil ibpkeycon structure into sepol policydb.
+ * The function is given a structure containing the sorted ibpkeycons and
+ * loops over this structure inserting them into the policy database.
+ *
+ * @param[in] pdb The policy database to insert the ibpkeycon into.
+ * @param[in] node The cil_sort structure that contains the sorted ibpkeycons.
+ *
+ * @return SEPOL_OK upon success or an error otherwise.
+ */
+int cil_ibpkeycon_to_policydb(policydb_t *pdb, struct cil_sort *ibpkeycons);
+
+/**
  * Insert cil portcon structure into sepol policydb.
  * The function is given a structure containing the sorted portcons and
  * loops over this structure inserting them into the policy database.
libsepol/cil/src/cil_build_ast.c +86 -0

98 lines not on this page · raw message

libsepol/cil/src/cil_build_ast.h +2 -0
index 33bae99..c2d7b31 100644
@@ -175,6 +175,8 @@ int cil_gen_context(struct cil_db *db, struct cil_tree_node *parse_current, stru
 void cil_destroy_context(struct cil_context *context);
 int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
 void cil_destroy_filecon(struct cil_filecon *filecon);
+int cil_gen_ibpkeycon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
+void cil_destroy_ibpkeycon(struct cil_ibpkeycon *ibpkeycon);
 int cil_gen_portcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
 void cil_destroy_portcon(struct cil_portcon *portcon);
 int cil_gen_nodecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
libsepol/cil/src/cil_copy_ast.c +26 -0
index d668505..7307b08 100644
@@ -1204,6 +1204,29 @@ int cil_copy_nodecon(struct cil_db *db, void *data, void **copy, __attribute__((
 	return SEPOL_OK;
 }
 
+int cil_copy_ibpkeycon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
+{
+	struct cil_ibpkeycon *orig = data;
+	struct cil_ibpkeycon *new = NULL;
+
+	cil_ibpkeycon_init(&new);
+
+	new->subnet_prefix_str = orig->subnet_prefix_str;
+	new->pkey_low = orig->pkey_low;
+	new->pkey_high = orig->pkey_high;
+
+	if (orig->context_str) {
+		new->context_str = orig->context_str;
+	} else {
+		cil_context_init(&new->context);
+		cil_copy_fill_context(db, orig->context, new->context);
+	}
+
+	*copy = new;
+
+	return SEPOL_OK;
+}
+
 int cil_copy_portcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
 {
 	struct cil_portcon *orig = data;
@@ -1916,6 +1939,9 @@ int __cil_copy_node_helper(struct cil_tree_node *orig, __attribute__((unused)) u
 	case CIL_NODECON:
 		copy_func = &cil_copy_nodecon;
 		break;
+	case CIL_IBPKEYCON:
+		copy_func = &cil_copy_ibpkeycon;
+		break;
 	case CIL_PORTCON:
 		copy_func = &cil_copy_portcon;
 		break;
libsepol/cil/src/cil_copy_ast.h +1 -0
index 78c34b8..a50c370 100644
@@ -99,6 +99,7 @@ int cil_copy_netifcon(struct cil_db *db, void *data, void **copy, symtab_t *symt
 int cil_copy_genfscon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
 int cil_copy_filecon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
 int cil_copy_nodecon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
+int cil_copy_ibpkeycon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
 int cil_copy_portcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
 int cil_copy_pirqcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
 int cil_copy_iomemcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
libsepol/cil/src/cil_flavor.h +1 -0
index c01f967..4505b8b 100644
@@ -113,6 +113,7 @@ enum cil_flavor {
 	CIL_HANDLEUNKNOWN,
 	CIL_MLS,
 	CIL_SRC_INFO,
+	CIL_IBPKEYCON,
 
 /*
  *          boolean  constraint  set  catset
libsepol/cil/src/cil_internal.h +11 -0
index aee3f00..2add97b 100644
@@ -203,6 +203,7 @@ char *CIL_KEY_VALIDATETRANS;
 char *CIL_KEY_MLSVALIDATETRANS;
 char *CIL_KEY_CONTEXT;
 char *CIL_KEY_FILECON;
+char *CIL_KEY_IBPKEYCON;
 char *CIL_KEY_PORTCON;
 char *CIL_KEY_NODECON;
 char *CIL_KEY_GENFSCON;
@@ -286,6 +287,7 @@ struct cil_db {
 	struct cil_sort *genfscon;
 	struct cil_sort *filecon;
 	struct cil_sort *nodecon;
+	struct cil_sort *ibpkeycon;
 	struct cil_sort *portcon;
 	struct cil_sort *pirqcon;
 	struct cil_sort *iomemcon;
@@ -737,6 +739,14 @@ enum cil_protocol {
 	CIL_PROTOCOL_DCCP
 };
 
+struct cil_ibpkeycon {
+	char *subnet_prefix_str;
+	uint32_t pkey_low;
+	uint32_t pkey_high;
+	char *context_str;
+	struct cil_context *context;
+};
+
 struct cil_portcon {
 	enum cil_protocol proto;
 	uint32_t port_low;
@@ -1007,6 +1017,7 @@ void cil_catset_init(struct cil_catset **catset);
 void cil_cats_init(struct cil_cats **cats);
 void cil_senscat_init(struct cil_senscat **senscat);
 void cil_filecon_init(struct cil_filecon **filecon);
+void cil_ibpkeycon_init(struct cil_ibpkeycon **ibpkeycon);
 void cil_portcon_init(struct cil_portcon **portcon);
 void cil_nodecon_init(struct cil_nodecon **nodecon);
 void cil_genfscon_init(struct cil_genfscon **genfscon);
libsepol/cil/src/cil_policy.c +16 -0
index 77179e6..35a0a29 100644
@@ -1714,6 +1714,21 @@ static void cil_genfscons_to_policy(FILE *out, struct cil_sort *genfscons, int m
 	}
 }
 
+static void cil_ibpkeycons_to_policy(FILE *out, struct cil_sort *ibpkeycons, int mls)
+{
+	uint32_t i = 0;
+
+	for (i = 0; i < ibpkeycons->count; i++) {
+		struct cil_ibpkeycon *ibpkeycon = (struct cil_ibpkeycon *)ibpkeycons->array[i];
+
+		fprintf(out, "ibpkeycon %s ", ibpkeycon->subnet_prefix_str);
+		fprintf(out, "%d ", ibpkeycon->pkey_low);
+		fprintf(out, "%d ", ibpkeycon->pkey_high);
+		cil_context_to_policy(out, ibpkeycon->context, mls);
+		fprintf(out, "\n");
+	}
+}
+
 static void cil_portcons_to_policy(FILE *out, struct cil_sort *portcons, int mls)
 {
 	unsigned i;
@@ -1942,6 +1957,7 @@ void cil_gen_policy(FILE *out, struct cil_db *db)
 	cil_genfscons_to_policy(out, db->genfscon, db->mls);
 	cil_portcons_to_policy(out, db->portcon, db->mls);
 	cil_netifcons_to_policy(out, db->netifcon, db->mls);
+	cil_ibpkeycons_to_policy(out, db->ibpkeycon, db->mls);
 	cil_nodecons_to_policy(out, db->nodecon, db->mls);
 	cil_pirqcons_to_policy(out, db->pirqcon, db->mls);
 	cil_iomemcons_to_policy(out, db->iomemcon, db->mls);
libsepol/cil/src/cil_post.c +45 -0

75 lines not on this page · raw message

libsepol/cil/src/cil_post.h +1 -0
index 74393cc..fe7f3a5 100644
@@ -38,6 +38,7 @@ struct fc_data {
 
 void cil_post_fc_fill_data(struct fc_data *fc, char *path);
 int cil_post_filecon_compare(const void *a, const void *b);
+int cil_post_ibpkeycon_compare(const void *a, const void *b);
 int cil_post_portcon_compare(const void *a, const void *b);
 int cil_post_genfscon_compare(const void *a, const void *b);
 int cil_post_netifcon_compare(const void *a, const void *b);
libsepol/cil/src/cil_reset_ast.c +9 -0
index 676e156..fc23a2c 100644
@@ -288,6 +288,12 @@ static void cil_reset_filecon(struct cil_filecon *filecon)
 	}
 }
 
+static void cil_reset_ibpkeycon(struct cil_ibpkeycon *ibpkeycon)
+{
+	if (!ibpkeycon->context)
+		cil_reset_context(ibpkeycon->context);
+}
+
 static void cil_reset_portcon(struct cil_portcon *portcon)
 {
 	if (portcon->context_str == NULL) {
@@ -489,6 +495,9 @@ int __cil_reset_node(struct cil_tree_node *node,  __attribute__((unused)) uint32
 	case CIL_FILECON:
 		cil_reset_filecon(node->data);
 		break;
+	case CIL_IBPKEYCON:
+		cil_reset_ibpkeycon(node->data);
+		break;
 	case CIL_PORTCON:
 		cil_reset_portcon(node->data);
 		break;
libsepol/cil/src/cil_resolve_ast.c +27 -0
index 8925b27..9e3cb2b 100644
@@ -1923,6 +1923,30 @@ int cil_resolve_filecon(struct cil_tree_node *current, void *extra_args)
 	return SEPOL_OK;
 }
 
+int cil_resolve_ibpkeycon(struct cil_tree_node *current, void *extra_args)
+{
+	struct cil_ibpkeycon *ibpkeycon = current->data;
+	struct cil_symtab_datum *context_datum = NULL;
+	int rc = SEPOL_ERR;
+
+	if (ibpkeycon->context_str) {
+		rc = cil_resolve_name(current, ibpkeycon->context_str, CIL_SYM_CONTEXTS, extra_args, &context_datum);
+		if (rc != SEPOL_OK)
+			goto exit;
+
+		ibpkeycon->context = (struct cil_context *)context_datum;
+	} else {
+		rc = cil_resolve_context(current, ibpkeycon->context, extra_args);
+		if (rc != SEPOL_OK)
+			goto exit;
+	}
+
+	return SEPOL_OK;
+
+exit:
+	return rc;
+}
+
 int cil_resolve_portcon(struct cil_tree_node *current, void *extra_args)
 {
 	struct cil_portcon *portcon = current->data;
@@ -3567,6 +3591,9 @@ int __cil_resolve_ast_node(struct cil_tree_node *node, void *extra_args)
 		case CIL_FILECON:
 			rc = cil_resolve_filecon(node, args);
 			break;
+		case CIL_IBPKEYCON:
+			rc = cil_resolve_ibpkeycon(node, args);
+			break;
 		case CIL_PORTCON:
 			rc = cil_resolve_portcon(node, args);
 			break;
libsepol/cil/src/cil_resolve_ast.h +1 -0
index 1175f97..0506a3d 100644
@@ -74,6 +74,7 @@ int cil_resolve_constrain(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_validatetrans(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_context(struct cil_tree_node *current, struct cil_context *context, void *extra_args);
 int cil_resolve_filecon(struct cil_tree_node *current, void *extra_args);
+int cil_resolve_ibpkeycon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_portcon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_genfscon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_nodecon(struct cil_tree_node *current, void *extra_args);
libsepol/cil/src/cil_tree.c +15 -1
index 2cc2744..89706d0 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright 2011 Tresys Technology, LLC. All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  * 
@@ -1409,6 +1409,20 @@ void cil_tree_print_node(struct cil_tree_node *node)
 			return;
 
 		}
+		case CIL_IBPKEYCON: {
+			struct cil_ibpkeycon *ibpkeycon = node->data;
+
+			cil_log(CIL_INFO, "IBPKEYCON: %s", ibpkeycon->subnet_prefix_str);
+			cil_log(CIL_INFO, " (%d %d) ", ibpkeycon->pkey_low, ibpkeycon->pkey_high);
+
+			if (ibpkeycon->context)
+				cil_tree_print_context(ibpkeycon->context);
+			else if (ibpkeycon->context_str)
+				cil_log(CIL_INFO, " %s", ibpkeycon->context_str);
+
+			cil_log(CIL_INFO, "\n");
+			return;
+		}
 		case CIL_PORTCON: {
 			struct cil_portcon *portcon = node->data;
 			cil_log(CIL_INFO, "PORTCON:");
libsepol/cil/src/cil_verify.c +23 -0
index 47dcfaa..108da33 100644
@@ -1080,6 +1080,26 @@ exit:
 	return rc;
 }
 
+int __cil_verify_ibpkeycon(struct cil_db *db, struct cil_tree_node *node)
+{
+	int rc = SEPOL_ERR;
+	struct cil_ibpkeycon *pkey = node->data;
+	struct cil_context *ctx = pkey->context;
+
+	/* Verify only when anonymous */
+	if (!ctx->datum.name) {
+		rc = __cil_verify_context(db, ctx);
+		if (rc != SEPOL_OK)
+			goto exit;
+	}
+
+	return SEPOL_OK;
+
+exit:
+	cil_tree_log(node, CIL_ERR, "Invalid ibpkeycon");
+	return rc;
+}
+
 int __cil_verify_portcon(struct cil_db *db, struct cil_tree_node *node)
 {
 	int rc = SEPOL_ERR;
@@ -1452,6 +1472,9 @@ int __cil_verify_helper(struct cil_tree_node *node, uint32_t *finished, void *ex
 		case CIL_NODECON:
 			rc = __cil_verify_nodecon(db, node);
 			break;
+		case CIL_IBPKEYCON:
+			rc = __cil_verify_ibpkeycon(db, node);
+			break;
 		case CIL_PORTCON:
 			rc = __cil_verify_portcon(db, node);
 			break;
Signature · 1 line
2.7.4
#11 lore raw

PATCH 4/9 checkpolicy: Add support for ibendportcon labels

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add checkpolicy support for scanning and parsing ibendportcon labels. Also create a new ocontext for IB end ports.

---
v1:
Stephen Smalley:
- Check IB device name length when parsing policy.
- Use strcmp vs strncmp to compare device names.

---
 checkpolicy/policy_define.c                | 75 ++++++++++++++++++++++++++++++
 checkpolicy/policy_define.h                |  1 +
 checkpolicy/policy_parse.y                 | 14 +++++-
 checkpolicy/policy_scan.l                  |  2 +
 libsepol/include/sepol/policydb/policydb.h |  9 +++-
 5 files changed, 98 insertions(+), 3 deletions(-)
checkpolicy/policy_define.c +75 -0
index ffdc5f8..239ca37 100644
@@ -5162,6 +5162,81 @@ out:
 	return rc;
 }
 
+int define_ibendport_context(unsigned int port)
+{
+	ocontext_t *newc, *c, *l, *head;
+	char *id;
+	int rc = 0;
+
+	if (policydbp->target_platform != SEPOL_TARGET_SELINUX) {
+		yyerror("ibendportcon not supported for target");
+		return -1;
+	}
+
+	if (pass == 1) {
+		id = (char *)queue_remove(id_queue);
+		free(id);
+		parse_security_context(NULL);
+		return 0;
+	}
+
+	newc = malloc(sizeof(*newc));
+	if (!newc) {
+		yyerror("out of memory");
+		return -1;
+	}
+	memset(newc, 0, sizeof(*newc));
+
+	newc->u.ibendport.dev_name = queue_remove(id_queue);
+	if (!newc->u.ibendport.dev_name) {
+		yyerror("failed to read infiniband device name.");
+		rc = -1;
+		goto out;
+	}
+
+	if (strlen(newc->u.ibendport.dev_name) > IB_DEVICE_NAME_MAX - 1) {
+		yyerror("infiniband device name exceeds max length of 63.");
+		rc = -1;
+		goto out;
+	}
+
+	newc->u.ibendport.port = port;
+
+	if (parse_security_context(&newc->context[0])) {
+		free(newc);
+		return -1;
+	}
+
+	/* Preserve the matching order specified in the configuration. */
+	head = policydbp->ocontexts[OCON_IBENDPORT];
+	for (l = NULL, c = head; c; l = c, c = c->next) {
+		unsigned int port2;
+
+		port2 = c->u.ibendport.port;
+
+		if (port == port2 &&
+		    !strcmp(c->u.ibendport.dev_name,
+			     newc->u.ibendport.dev_name)) {
+			yyerror2("duplicate ibendportcon entry for %s port %u",
+				 newc->u.ibendport.dev_name, port);
+			rc = -1;
+			goto out;
+		}
+	}
+
+	if (l)
+		l->next = newc;
+	else
+		policydbp->ocontexts[OCON_IBENDPORT] = newc;
+
+	return 0;
+
+out:
+	free(newc->u.ibendport.dev_name);
+	free(newc);
+	return rc;
+}
+
 int define_netif_context(void)
 {
 	ocontext_t *newc, *c, *head;
checkpolicy/policy_define.h +1 -0
index 75e3683..50a7ba7 100644
@@ -44,6 +44,7 @@ int define_netif_context(void);
 int define_permissive(void);
 int define_polcap(void);
 int define_ibpkey_context(unsigned int low, unsigned int high);
+int define_ibendport_context(unsigned int port);
 int define_port_context(unsigned int low, unsigned int high);
 int define_pirq_context(unsigned int pirq);
 int define_iomem_context(uint64_t low, uint64_t high);
checkpolicy/policy_parse.y +12 -2
index 35b433b..6b406c8 100644
@@ -137,6 +137,7 @@ typedef int (* require_func_t)(int pass);
 %token SAMEUSER
 %token FSCON PORTCON NETIFCON NODECON 
 %token IBPKEYCON
+%token IBENDPORTCON
 %token PIRQCON IOMEMCON IOPORTCON PCIDEVICECON DEVICETREECON
 %token FSUSEXATTR FSUSETASK FSUSETRANS
 %token GENFSCON
@@ -172,7 +173,7 @@ base_policy             : { if (define_policy(pass, 0) == -1) return -1; }
 			  opt_default_rules opt_mls te_rbac users opt_constraints 
                          { if (pass == 1) { if (policydb_index_bools(policydbp)) return -1;}
 			   else if (pass == 2) { if (policydb_index_others(NULL, policydbp, 0)) return -1;}}
-			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts opt_ibpkey_contexts
+			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts opt_ibpkey_contexts opt_ibendport_contexts
 			;
 classes			: class_def 
 			| classes class_def
@@ -702,7 +703,7 @@ fs_contexts		: fs_context_def
 fs_context_def		: FSCON number number security_context_def security_context_def
 			{if (define_fs_context($2,$3)) return -1;}
 			;
-net_contexts		: opt_port_contexts opt_netif_contexts opt_node_contexts 
+net_contexts		: opt_port_contexts opt_netif_contexts opt_node_contexts
 			;
 opt_port_contexts       : port_contexts
                         |
@@ -726,6 +727,15 @@ ibpkey_context_def	: IBPKEYCON ipv6_addr number security_context_def
 			| IBPKEYCON ipv6_addr number '-' number security_context_def
 			{if (define_ibpkey_context($3,$5)) return -1;}
 			;
+opt_ibendport_contexts	: ibendport_contexts
+			|
+			;
+ibendport_contexts	: ibendport_context_def
+                        | ibendport_contexts ibendport_context_def
+                        ;
+ibendport_context_def	: IBENDPORTCON identifier number security_context_def
+                        {if (define_ibendport_context($3)) return -1;}
+                        ;
 opt_netif_contexts      : netif_contexts 
                         |
                         ;
checkpolicy/policy_scan.l +2 -0
index f742939..e6c4898 100644
@@ -186,6 +186,8 @@ fscon |
 FSCON                           { return(FSCON);}
 ibpkeycon |
 IBPKEYCON			{ return(IBPKEYCON);}
+ibendportcon |
+IBENDPORTCON			{ return(IBENDPORTCON);}
 portcon |
 PORTCON				{ return(PORTCON);}
 netifcon |                     
libsepol/include/sepol/policydb/policydb.h +8 -1
index 844191c..ed5730b 100644
@@ -73,6 +73,8 @@
 extern "C" {
 #endif
 
+#define IB_DEVICE_NAME_MAX 64
+
 /*
  * A datum type is defined for each kind of symbol 
  * in the configuration data:  individual permissions, 
@@ -364,6 +366,10 @@ typedef struct ocontext {
 			uint16_t low_pkey;
 			uint16_t high_pkey;
 		} ibpkey;
+		struct {
+			char *dev_name;
+			uint8_t port;
+		} ibendport;
 	} u;
 	union {
 		uint32_t sclass;	/* security class for genfs */
@@ -400,6 +406,7 @@ typedef struct genfs {
 #define OCON_FSUSE 5	/* fs_use */
 #define OCON_NODE6 6	/* IPv6 nodes */
 #define OCON_IBPKEY 7	/* Infiniband PKEY */
+#define OCON_IBENDPORT 8	/* Infiniband End Port */
 
 /* object context array indices for Xen */
 #define OCON_XEN_ISID  	    0    /* initial SIDs */
@@ -410,7 +417,7 @@ typedef struct genfs {
 #define OCON_XEN_DEVICETREE 5    /* device tree node */
 
 /* OCON_NUM needs to be the largest index in any platform's ocontext array */
-#define OCON_NUM   8
+#define OCON_NUM   9
 
 /* section: module information */
 
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v1 4/9] checkpolicy: Add support for ibendportcon labels

Quoted 68 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add checkpolicy support for scanning and parsing ibendportcon labels. Also create a new ocontext for IB end ports.

---
v1:
Stephen Smalley:
- Check IB device name length when parsing policy.
- Use strcmp vs strncmp to compare device names.

---
 checkpolicy/policy_define.c                | 75
++++++++++++++++++++++++++++++
 checkpolicy/policy_define.h                |  1 + checkpolicy/policy_parse.y                 | 14 +++++- checkpolicy/policy_scan.l                  |  2 + libsepol/include/sepol/policydb/policydb.h |  9 +++-

 5 files changed, 98 insertions(+), 3 deletions(-)
checkpolicy/policy_define.c +0 -0
index ffdc5f8..239ca37 100644
@@ -5162,6 +5162,81 @@ out:
  	return rc;
  }

checkpolicy/policy_define.c +34 -1
+int define_ibendport_context(unsigned int port)
+{
+	ocontext_t *newc, *c, *l, *head;
+	char *id;
+	int rc = 0;
+
+	if (policydbp->target_platform != SEPOL_TARGET_SELINUX) {
+		yyerror("ibendportcon not supported for target");
+		return -1;
+	}
+
+	if (pass == 1) {
+		id = (char *)queue_remove(id_queue);
+		free(id);
+		parse_security_context(NULL);
+		return 0;
+	}
+
+	newc = malloc(sizeof(*newc));
+	if (!newc) {
+		yyerror("out of memory");
+		return -1;
+	}
+	memset(newc, 0, sizeof(*newc));
+
+	newc->u.ibendport.dev_name = queue_remove(id_queue);
+	if (!newc->u.ibendport.dev_name) {
+		yyerror("failed to read infiniband device name.");
+		rc = -1;
+		goto out;
+	}
+
+	if (strlen(newc->u.ibendport.dev_name) > IB_DEVICE_NAME_MAX
- 1) {
+		yyerror("infiniband device name exceeds max length

of 63.");

checkpolicy/policy_define.c out: · line 5203

Quoted 5 lines
checkpolicy/policy_define.c +5 -0
+		rc = -1;
+		goto out;
+	}
+
+	newc->u.ibendport.port = port;

Kernel also treats it as an error if port > 0xff || port == 0.

#13 lore raw

PATCH 5/9 libsepol: Add ibendport ocontext handling

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying IB end port ocontext data. Also add support for querying a IB end port sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed unused domain and type params from sepol_ibendport_sid.
- Remove ibendport initial sid from ocontext_selinux_isid_to_cil
- Check the length provide for the device name in ocontext_read_selinux
- Used strcmp for dev_name comparison.

James Carter:
- Added ibendport handling to kernel_to_cil.c and kernel_to_conf.c

---
 checkpolicy/checkpolicy.c                  | 20 ++++++++++++++
 libsepol/include/sepol/policydb/services.h |  8 ++++++
 libsepol/src/expand.c                      |  8 ++++++
 libsepol/src/kernel_to_cil.c               | 42 ++++++++++++++++++++++++++++++
 libsepol/src/kernel_to_conf.c              | 41 +++++++++++++++++++++++++++++
 libsepol/src/libsepol.map.in               |  1 +
 libsepol/src/module_to_cil.c               | 14 ++++++++++
 libsepol/src/policydb.c                    | 26 +++++++++++++++---
 libsepol/src/services.c                    | 37 ++++++++++++++++++++++++++
 libsepol/src/write.c                       | 14 ++++++++++
 10 files changed, 208 insertions(+), 3 deletions(-)
checkpolicy/checkpolicy.c +20 -0
index d0e46ba..94bf083 100644
@@ -701,6 +701,7 @@ int main(int argc, char **argv)
 	printf("i)  display constraint expressions\n");
 	printf("j)  display validatetrans expressions\n");
 	printf("k)  Call ibpkey_sid\n");
+	printf("l)  Call ibendport_sid\n");
 #ifdef EQUIVTYPES
 	printf("z)  Show equivalent types\n");
 #endif
@@ -1245,6 +1246,25 @@ int main(int argc, char **argv)
 				printf("sid %d\n", ssid);
 			}
 			break;
+		case 'l':
+			printf("device name (eg. mlx4_0)?  ");
+			FGETS(ans, sizeof(ans), stdin);
+			ans[strlen(ans) - 1] = 0;
+
+			name = malloc((strlen(ans) + 1) * sizeof(char));
+			if (!name) {
+				fprintf(stderr, "couldn't malloc string.\n");
+				break;
+			}
+			strcpy(name, ans);
+
+			printf("port? ");
+			FGETS(ans, sizeof(ans), stdin);
+			port = atoi(ans);
+			sepol_ibendport_sid(name, port, &ssid);
+			printf("sid %d\n", ssid);
+			free(name);
+			break;
 #ifdef EQUIVTYPES
 		case 'z':
 			identify_equiv_types();
libsepol/include/sepol/policydb/services.h +8 -0
index 459254e..e4f2f11 100644
@@ -196,6 +196,14 @@ extern int sepol_ibpkey_sid(void *subnet_prefix_p,
 			    sepol_security_id_t *out_sid);
 
 /*
+ * Return the SID of the ibendport specified by
+ * `dev_name', and `port'.
+ */
+extern int sepol_ibendport_sid(char *dev_name,
+			       uint8_t port,
+			       sepol_security_id_t *out_sid);
+
+/*
  * Return the SIDs to use for a network interface
  * with the name `name'.  The `if_sid' SID is returned for 
  * the interface and the `msg_sid' SID is returned as
libsepol/src/expand.c +8 -0
index c45ecbe..061945e 100644
@@ -2226,6 +2226,14 @@ static int ocontext_copy_selinux(expand_state_t *state)
 				n->u.ibpkey.low_pkey = c->u.ibpkey.low_pkey;
 				n->u.ibpkey.high_pkey = c->u.ibpkey.high_pkey;
 			break;
+			case OCON_IBENDPORT:
+				n->u.ibendport.dev_name = strdup(c->u.ibendport.dev_name);
+				if (!n->u.ibendport.dev_name) {
+					ERR(state->handle, "Out of memory!");
+					return -1;
+				}
+				n->u.ibendport.port = c->u.ibendport.port;
+				break;
 			case OCON_PORT:
 				n->u.port.protocol = c->u.port.protocol;
 				n->u.port.low_port = c->u.port.low_port;
libsepol/src/kernel_to_cil.c +42 -0

54 lines not on this page · raw message

libsepol/src/kernel_to_conf.c +41 -0

53 lines not on this page · raw message

libsepol/src/libsepol.map.in +1 -0
index 36225d1..dd1fec2 100644
@@ -7,6 +7,7 @@ LIBSEPOL_1.0 {
 	sepol_iface_*; 
 	sepol_port_*;
 	sepol_ibpkey_*;
+	sepol_ibendport_*;
 	sepol_node_*;
 	sepol_user_*; sepol_genusers; sepol_set_delusers;
 	sepol_msg_*; sepol_debug;
libsepol/src/module_to_cil.c +14 -0
index c97f453..04394f0 100644
@@ -2773,6 +2773,19 @@ exit:
 	return rc;
 }
 
+static int ocontext_selinux_ibendport_to_cil(struct policydb *pdb, struct ocontext *ibendports)
+{
+	struct ocontext *ibendport;
+
+	for (ibendport = ibendports; ibendport; ibendport = ibendport->next) {
+		cil_printf("(ibendportcon %s %u ", ibendport->u.ibendport.dev_name, ibendport->u.ibendport.port);
+		context_to_cil(pdb, &ibendport->context[0]);
+
+		cil_printf(")\n");
+	}
+
+	return 0;
+}
 
 static int ocontext_selinux_fsuse_to_cil(struct policydb *pdb, struct ocontext *fsuses)
 {
@@ -2927,6 +2940,7 @@ static int ocontexts_to_cil(struct policydb *pdb)
 		ocontext_selinux_fsuse_to_cil,
 		ocontext_selinux_node6_to_cil,
 		ocontext_selinux_ibpkey_to_cil,
+		ocontext_selinux_ibendport_to_cil,
 	};
 	static int (*ocon_xen_funcs[OCON_NUM])(struct policydb *pdb, struct ocontext *ocon) = {
 		ocontext_xen_isid_to_cil,
libsepol/src/policydb.c +23 -3
index d6e8e6f..9a11d45 100644
@@ -190,7 +190,7 @@ static struct policydb_compat_info policydb_compat[] = {
 	 .type = POLICY_KERN,
 	 .version = POLICYDB_VERSION_INFINIBAND,
 	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBPKEY + 1,
+	 .ocon_num = OCON_IBENDPORT + 1,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
 	{
@@ -295,7 +295,7 @@ static struct policydb_compat_info policydb_compat[] = {
 	 .type = POLICY_BASE,
 	 .version = MOD_POLICYDB_VERSION_INFINIBAND,
 	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBPKEY + 1,
+	 .ocon_num = OCON_IBENDPORT + 1,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
 	{
@@ -2788,7 +2788,7 @@ static int ocontext_read_selinux(struct policydb_compat_info *info,
 				if (rc < 0)
 					return -1;
 				len = le32_to_cpu(buf[0]);
-				if (zero_or_saturated(len))
+				if (zero_or_saturated(len) || len > 63)
 					return -1;
 				c->u.name = malloc(len + 1);
 				if (!c->u.name)
@@ -2819,6 +2819,26 @@ static int ocontext_read_selinux(struct policydb_compat_info *info,
 				    (&c->context[0], p, fp))
 					return -1;
 				break;
+			case OCON_IBENDPORT:
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+				if (rc < 0)
+					return -1;
+				len = le32_to_cpu(buf[0]);
+				if (len == 0 || len > IB_DEVICE_NAME_MAX - 1)
+					return -1;
+
+				c->u.ibendport.dev_name = malloc(len + 1);
+				if (!c->u.ibendport.dev_name)
+					return -1;
+				rc = next_entry(c->u.ibendport.dev_name, fp, len);
+				if (rc < 0)
+					return -1;
+				c->u.ibendport.dev_name[len] = 0;
+				c->u.ibendport.port = le32_to_cpu(buf[1]);
+				if (context_read_and_validate
+				    (&c->context[0], p, fp))
+					return -1;
+				break;
 			case OCON_PORT:
 				rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
 				if (rc < 0)
libsepol/src/services.c +37 -0
index 4236aac..f444f10 100644
@@ -1962,6 +1962,43 @@ out:
 }
 
 /*
+ * Return the SID of the subnet management interface specified by
+ * `device name', and `port'.
+ */
+int hidden sepol_ibendport_sid(char *dev_name,
+			       uint8_t port,
+			       sepol_security_id_t *out_sid)
+{
+	ocontext_t *c;
+	int rc = 0;
+
+	c = policydb->ocontexts[OCON_IBENDPORT];
+	while (c) {
+		if (c->u.ibendport.port == port &&
+		    !strcmp(dev_name, c->u.ibendport.dev_name))
+			break;
+		c = c->next;
+	}
+
+	if (c) {
+		if (!c->sid[0]) {
+			rc = sepol_sidtab_context_to_sid(sidtab,
+							 &c->context[0],
+							 &c->sid[0]);
+			if (rc)
+				goto out;
+		}
+		*out_sid = c->sid[0];
+	} else {
+		*out_sid = SECINITSID_UNLABELED;
+	}
+
+out:
+	return rc;
+}
+
+
+/*
  * Return the SID of the port specified by
  * `domain', `type', `protocol', and `port'.
  */
libsepol/src/write.c +14 -0
index fa1b7d1..e3ff389 100644
@@ -1426,6 +1426,20 @@ static int ocontext_write_selinux(struct policydb_compat_info *info,
 				if (context_write(p, &c->context[0], fp))
 					return POLICYDB_ERROR;
 				break;
+			case OCON_IBENDPORT:
+				len = strlen(c->u.ibendport.dev_name);
+				buf[0] = cpu_to_le32(len);
+				buf[1] = cpu_to_le32(c->u.ibendport.port);
+				items = put_entry(buf, sizeof(uint32_t), 2, fp);
+				if (items != 2)
+					return POLICYDB_ERROR;
+				items = put_entry(c->u.ibendport.dev_name, 1, len, fp);
+				if (items != len)
+					return POLICYDB_ERROR;
+
+				if (context_write(p, &c->context[0], fp))
+					return POLICYDB_ERROR;
+				break;
 			case OCON_PORT:
 				buf[0] = c->u.port.protocol;
 				buf[1] = c->u.port.low_port;
Signature · 1 line
2.7.4
#14 lore raw

Re: [PATCH v1 5/9] libsepol: Add ibendport ocontext handling

Quoted 143 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add support for reading, writing, and copying IB end port ocontext data. Also add support for querying a IB end port sid to checkpolicy.

---
v1:
Stephen Smalley:
- Removed unused domain and type params from sepol_ibendport_sid.
- Remove ibendport initial sid from ocontext_selinux_isid_to_cil
- Check the length provide for the device name in ocontext_read_selinux
- Used strcmp for dev_name comparison.

James Carter:
- Added ibendport handling to kernel_to_cil.c and kernel_to_conf.c

---
  checkpolicy/checkpolicy.c                  | 20 ++++++++++++++
  libsepol/include/sepol/policydb/services.h |  8 ++++++
  libsepol/src/expand.c                      |  8 ++++++
  libsepol/src/kernel_to_cil.c               | 42 ++++++++++++++++++++++++++++++
  libsepol/src/kernel_to_conf.c              | 41 +++++++++++++++++++++++++++++
  libsepol/src/libsepol.map.in               |  1 +
  libsepol/src/module_to_cil.c               | 14 ++++++++++
  libsepol/src/policydb.c                    | 26 +++++++++++++++---
  libsepol/src/services.c                    | 37 ++++++++++++++++++++++++++
  libsepol/src/write.c                       | 14 ++++++++++
  10 files changed, 208 insertions(+), 3 deletions(-)
checkpolicy/checkpolicy.c +20 -0
index d0e46ba..94bf083 100644
@@ -701,6 +701,7 @@ int main(int argc, char **argv)
  	printf("i)  display constraint expressions\n");
  	printf("j)  display validatetrans expressions\n");
  	printf("k)  Call ibpkey_sid\n");
+	printf("l)  Call ibendport_sid\n");
  #ifdef EQUIVTYPES
  	printf("z)  Show equivalent types\n");
  #endif
@@ -1245,6 +1246,25 @@ int main(int argc, char **argv)
  				printf("sid %d\n", ssid);
  			}
  			break;
+		case 'l':
+			printf("device name (eg. mlx4_0)?  ");
+			FGETS(ans, sizeof(ans), stdin);
+			ans[strlen(ans) - 1] = 0;
+
+			name = malloc((strlen(ans) + 1) * sizeof(char));
+			if (!name) {
+				fprintf(stderr, "couldn't malloc string.\n");
+				break;
+			}
+			strcpy(name, ans);
+
+			printf("port? ");
+			FGETS(ans, sizeof(ans), stdin);
+			port = atoi(ans);
+			sepol_ibendport_sid(name, port, &ssid);
+			printf("sid %d\n", ssid);
+			free(name);
+			break;
  #ifdef EQUIVTYPES
  		case 'z':
  			identify_equiv_types();
libsepol/include/sepol/policydb/services.h +8 -0
index 459254e..e4f2f11 100644
@@ -196,6 +196,14 @@ extern int sepol_ibpkey_sid(void *subnet_prefix_p,
  			    sepol_security_id_t *out_sid);
 
  /*
+ * Return the SID of the ibendport specified by
+ * `dev_name', and `port'.
+ */
+extern int sepol_ibendport_sid(char *dev_name,
+			       uint8_t port,
+			       sepol_security_id_t *out_sid);
+
+/*
   * Return the SIDs to use for a network interface
   * with the name `name'.  The `if_sid' SID is returned for
   * the interface and the `msg_sid' SID is returned as
libsepol/src/expand.c +8 -0
index c45ecbe..061945e 100644
@@ -2226,6 +2226,14 @@ static int ocontext_copy_selinux(expand_state_t *state)
  				n->u.ibpkey.low_pkey = c->u.ibpkey.low_pkey;
  				n->u.ibpkey.high_pkey = c->u.ibpkey.high_pkey;
  			break;
+			case OCON_IBENDPORT:
+				n->u.ibendport.dev_name = strdup(c->u.ibendport.dev_name);
+				if (!n->u.ibendport.dev_name) {
+					ERR(state->handle, "Out of memory!");
+					return -1;
+				}
+				n->u.ibendport.port = c->u.ibendport.port;
+				break;
  			case OCON_PORT:
  				n->u.port.protocol = c->u.port.protocol;
  				n->u.port.low_port = c->u.port.low_port;
libsepol/src/kernel_to_cil.c +27 -0
index fcfd0e0..6587ff4 100644
@@ -2837,6 +2837,43 @@ exit:
  	return rc;
  }
 
+static int write_selinux_ibendport_rules_to_cil(FILE *out, struct policydb *pdb)
+{
+	struct ocontext *ibendportcon;
+	char port_str[4];
+	char *ctx;
+	int rc = 0;
+
+	for (ibendportcon = pdb->ocontexts[OCON_IBENDPORT];
+	     ibendportcon != NULL; ibendportcon = ibendportcon->next) {
+		rc = snprintf(port_str, 4, "%u", ibendportcon->u.ibendport.port);
+		if (rc < 0 || rc >= 4) {
+			rc = -1;
+			goto exit;
+		}
+
+		ctx = context_to_str(pdb, &ibendportcon->context[0]);
+		if (!ctx) {
+			rc = -1;
+			goto exit;
+		}
+
+		sepol_printf(out, "(ibendportcon %s %s %s)\n",
+			     ibendportcon->u.ibendport.dev_name, port_str, ctx);
+
+		free(ctx);
+	}
+

libsepol/src/kernel_to_cil.c exit: · line 2876

Quoted 10 lines
libsepol/src/kernel_to_cil.c +10 -0
+	rc = 0;
+
+exit:
+	if (rc != 0) {
+		sepol_log_err("Error writing ibendportcon rules to CIL\n");
+	}
+
+	return rc;
+}
+

You need to have the ibendport rules sorted like I mentioned for ibpkey in patch 2.

Jim

Quoted 250 lines
libsepol/src/kernel_to_cil.c +5 -0
  static int write_xen_isid_rules_to_cil(FILE *out, struct policydb *pdb)
  {
  	return write_sid_context_rules_to_cil(out, pdb, xen_sid_to_str);
@@ -3238,6 +3275,11 @@ int sepol_kernel_policydb_to_cil(FILE *out, struct policydb *pdb)
  		if (rc != 0) {
  			goto exit;
  		}
+
+		rc = write_selinux_ibendport_rules_to_cil(out, pdb);
+		if (rc != 0) {
+			goto exit;
+		}
  	} else if (pdb->target_platform == SEPOL_TARGET_XEN) {
  		rc = write_xen_isid_rules_to_cil(out, pdb);
  		if (rc != 0) {
libsepol/src/kernel_to_conf.c +41 -0
index 795cf56..ba261cf 100644
@@ -2699,6 +2699,42 @@ exit:
  	return rc;
  }
 
+static int write_selinux_ibendport_rules_to_conf(FILE *out, struct policydb *pdb)
+{
+	struct ocontext *ibendportcon;
+	char port_str[4];
+	char *ctx;
+	int rc = 0;
+
+	for (ibendportcon = pdb->ocontexts[OCON_IBENDPORT];
+	     ibendportcon != NULL; ibendportcon = ibendportcon->next) {
+		rc = snprintf(port_str, 4, "%u", ibendportcon->u.ibendport.port);
+		if (rc < 0 || rc >= 4) {
+			rc = -1;
+			goto exit;
+		}
+
+		ctx = context_to_str(pdb, &ibendportcon->context[0]);
+		if (!ctx) {
+			rc = -1;
+			goto exit;
+		}
+
+		sepol_printf(out, "ibendportcon %s %s %s\n", ibendportcon->u.ibendport.dev_name, port_str, ctx);
+
+		free(ctx);
+	}
+
+	rc = 0;
+
+exit:
+	if (rc != 0) {
+		sepol_log_err("Error writing ibendportcon rules to policy.conf\n");
+	}
+
+	return rc;
+}
+
  static int write_xen_isid_rules_to_conf(FILE *out, struct policydb *pdb)
  {
  	return write_sid_context_rules_to_conf(out, pdb, xen_sid_to_str);
@@ -3104,6 +3140,11 @@ int sepol_kernel_policydb_to_conf(FILE *out, struct policydb *pdb)
  		if (rc != 0) {
  			goto exit;
  		}
+
+		rc = write_selinux_ibendport_rules_to_conf(out, pdb);
+		if (rc != 0) {
+			goto exit;
+		}
  	} else if (pdb->target_platform == SEPOL_TARGET_XEN) {
  		rc = write_xen_isid_rules_to_conf(out, pdb);
  		if (rc != 0) {
libsepol/src/libsepol.map.in +1 -0
index 36225d1..dd1fec2 100644
@@ -7,6 +7,7 @@ LIBSEPOL_1.0 {
  	sepol_iface_*;
  	sepol_port_*;
  	sepol_ibpkey_*;
+	sepol_ibendport_*;
  	sepol_node_*;
  	sepol_user_*; sepol_genusers; sepol_set_delusers;
  	sepol_msg_*; sepol_debug;
libsepol/src/module_to_cil.c +14 -0
index c97f453..04394f0 100644
@@ -2773,6 +2773,19 @@ exit:
  	return rc;
  }
 
+static int ocontext_selinux_ibendport_to_cil(struct policydb *pdb, struct ocontext *ibendports)
+{
+	struct ocontext *ibendport;
+
+	for (ibendport = ibendports; ibendport; ibendport = ibendport->next) {
+		cil_printf("(ibendportcon %s %u ", ibendport->u.ibendport.dev_name, ibendport->u.ibendport.port);
+		context_to_cil(pdb, &ibendport->context[0]);
+
+		cil_printf(")\n");
+	}
+
+	return 0;
+}
 
  static int ocontext_selinux_fsuse_to_cil(struct policydb *pdb, struct ocontext *fsuses)
  {
@@ -2927,6 +2940,7 @@ static int ocontexts_to_cil(struct policydb *pdb)
  		ocontext_selinux_fsuse_to_cil,
  		ocontext_selinux_node6_to_cil,
  		ocontext_selinux_ibpkey_to_cil,
+		ocontext_selinux_ibendport_to_cil,
  	};
  	static int (*ocon_xen_funcs[OCON_NUM])(struct policydb *pdb, struct ocontext *ocon) = {
  		ocontext_xen_isid_to_cil,
libsepol/src/policydb.c +23 -3
index d6e8e6f..9a11d45 100644
@@ -190,7 +190,7 @@ static struct policydb_compat_info policydb_compat[] = {
  	 .type = POLICY_KERN,
  	 .version = POLICYDB_VERSION_INFINIBAND,
  	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBPKEY + 1,
+	 .ocon_num = OCON_IBENDPORT + 1,
  	 .target_platform = SEPOL_TARGET_SELINUX,
  	},
  	{
@@ -295,7 +295,7 @@ static struct policydb_compat_info policydb_compat[] = {
  	 .type = POLICY_BASE,
  	 .version = MOD_POLICYDB_VERSION_INFINIBAND,
  	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBPKEY + 1,
+	 .ocon_num = OCON_IBENDPORT + 1,
  	 .target_platform = SEPOL_TARGET_SELINUX,
  	},
  	{
@@ -2788,7 +2788,7 @@ static int ocontext_read_selinux(struct policydb_compat_info *info,
  				if (rc < 0)
  					return -1;
  				len = le32_to_cpu(buf[0]);
-				if (zero_or_saturated(len))
+				if (zero_or_saturated(len) || len > 63)
  					return -1;
  				c->u.name = malloc(len + 1);
  				if (!c->u.name)
@@ -2819,6 +2819,26 @@ static int ocontext_read_selinux(struct policydb_compat_info *info,
  				    (&c->context[0], p, fp))
  					return -1;
  				break;
+			case OCON_IBENDPORT:
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+				if (rc < 0)
+					return -1;
+				len = le32_to_cpu(buf[0]);
+				if (len == 0 || len > IB_DEVICE_NAME_MAX - 1)
+					return -1;
+
+				c->u.ibendport.dev_name = malloc(len + 1);
+				if (!c->u.ibendport.dev_name)
+					return -1;
+				rc = next_entry(c->u.ibendport.dev_name, fp, len);
+				if (rc < 0)
+					return -1;
+				c->u.ibendport.dev_name[len] = 0;
+				c->u.ibendport.port = le32_to_cpu(buf[1]);
+				if (context_read_and_validate
+				    (&c->context[0], p, fp))
+					return -1;
+				break;
  			case OCON_PORT:
  				rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
  				if (rc < 0)
libsepol/src/services.c +37 -0
index 4236aac..f444f10 100644
@@ -1962,6 +1962,43 @@ out:
  }
 
  /*
+ * Return the SID of the subnet management interface specified by
+ * `device name', and `port'.
+ */
+int hidden sepol_ibendport_sid(char *dev_name,
+			       uint8_t port,
+			       sepol_security_id_t *out_sid)
+{
+	ocontext_t *c;
+	int rc = 0;
+
+	c = policydb->ocontexts[OCON_IBENDPORT];
+	while (c) {
+		if (c->u.ibendport.port == port &&
+		    !strcmp(dev_name, c->u.ibendport.dev_name))
+			break;
+		c = c->next;
+	}
+
+	if (c) {
+		if (!c->sid[0]) {
+			rc = sepol_sidtab_context_to_sid(sidtab,
+							 &c->context[0],
+							 &c->sid[0]);
+			if (rc)
+				goto out;
+		}
+		*out_sid = c->sid[0];
+	} else {
+		*out_sid = SECINITSID_UNLABELED;
+	}
+
+out:
+	return rc;
+}
+
+
+/*
   * Return the SID of the port specified by
   * `domain', `type', `protocol', and `port'.
   */
libsepol/src/write.c +14 -0
index fa1b7d1..e3ff389 100644
@@ -1426,6 +1426,20 @@ static int ocontext_write_selinux(struct policydb_compat_info *info,
  				if (context_write(p, &c->context[0], fp))
  					return POLICYDB_ERROR;
  				break;
+			case OCON_IBENDPORT:
+				len = strlen(c->u.ibendport.dev_name);
+				buf[0] = cpu_to_le32(len);
+				buf[1] = cpu_to_le32(c->u.ibendport.port);
+				items = put_entry(buf, sizeof(uint32_t), 2, fp);
+				if (items != 2)
+					return POLICYDB_ERROR;
+				items = put_entry(c->u.ibendport.dev_name, 1, len, fp);
+				if (items != len)
+					return POLICYDB_ERROR;
+
+				if (context_write(p, &c->context[0], fp))
+					return POLICYDB_ERROR;
+				break;
  			case OCON_PORT:
  				buf[0] = c->u.port.protocol;
  				buf[1] = c->u.port.low_port;
Signature · 2 lines
James Carter <[email protected]>
National Security Agency
#15 lore raw

Re: [PATCH v1 5/9] libsepol: Add ibendport ocontext handling

Quoted 14 lines · James Carter

libsepol/src/kernel_to_cil.c exit: · line 2876

Quoted 11 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

libsepol/src/kernel_to_cil.c +8 -0
+exit:
+	if (rc != 0) {
+		sepol_log_err("Error writing ibendportcon rules to CIL\n");
+	}
+
+	return rc;
+}
+

You need to have the ibendport rules sorted like I mentioned for ibpkey in patch 2.

Quoted 1 line

Jim

Done for both patches.

#16 lore raw

PATCH 6/9 libsepol: Add IB end port handling to CIL

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Add IB end port parsing, symbol table management, and policy generation to CIL.

---
v1:
James Carter:
- Add cil_resolve_ibendportcon prototype in cil_resolve_ast.h

---
 libsepol/cil/src/cil.c             | 18 +++++++++++
 libsepol/cil/src/cil_binary.c      | 29 +++++++++++++++++
 libsepol/cil/src/cil_binary.h      | 12 +++++++
 libsepol/cil/src/cil_build_ast.c   | 65 ++++++++++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_build_ast.h   |  2 ++
 libsepol/cil/src/cil_copy_ast.c    | 25 +++++++++++++++
 libsepol/cil/src/cil_flavor.h      |  1 +
 libsepol/cil/src/cil_internal.h    |  9 ++++++
 libsepol/cil/src/cil_policy.c      | 15 +++++++++
 libsepol/cil/src/cil_post.c        | 42 ++++++++++++++++++++++++
 libsepol/cil/src/cil_post.h        |  1 +
 libsepol/cil/src/cil_reset_ast.c   | 10 ++++++
 libsepol/cil/src/cil_resolve_ast.c | 28 ++++++++++++++++
 libsepol/cil/src/cil_resolve_ast.h |  1 +
 libsepol/cil/src/cil_tree.c        | 13 ++++++++
 libsepol/cil/src/cil_verify.c      | 23 ++++++++++++++
 16 files changed, 294 insertions(+)
libsepol/cil/src/cil.c +18 -0
index 3df670a..c02a41a 100644
@@ -189,6 +189,7 @@ static void cil_init_keys(void)
 	CIL_KEY_CONTEXT = cil_strpool_add("context");
 	CIL_KEY_FILECON = cil_strpool_add("filecon");
 	CIL_KEY_IBPKEYCON = cil_strpool_add("ibpkeycon");
+	CIL_KEY_IBENDPORTCON = cil_strpool_add("ibendportcon");
 	CIL_KEY_PORTCON = cil_strpool_add("portcon");
 	CIL_KEY_NODECON = cil_strpool_add("nodecon");
 	CIL_KEY_GENFSCON = cil_strpool_add("genfscon");
@@ -259,6 +260,7 @@ void cil_db_init(struct cil_db **db)
 	cil_sort_init(&(*db)->filecon);
 	cil_sort_init(&(*db)->nodecon);
 	cil_sort_init(&(*db)->ibpkeycon);
+	cil_sort_init(&(*db)->ibendportcon);
 	cil_sort_init(&(*db)->portcon);
 	cil_sort_init(&(*db)->pirqcon);
 	cil_sort_init(&(*db)->iomemcon);
@@ -311,6 +313,7 @@ void cil_db_destroy(struct cil_db **db)
 	cil_sort_destroy(&(*db)->filecon);
 	cil_sort_destroy(&(*db)->nodecon);
 	cil_sort_destroy(&(*db)->ibpkeycon);
+	cil_sort_destroy(&(*db)->ibendportcon);
 	cil_sort_destroy(&(*db)->portcon);
 	cil_sort_destroy(&(*db)->pirqcon);
 	cil_sort_destroy(&(*db)->iomemcon);
@@ -737,6 +740,9 @@ void cil_destroy_data(void **data, enum cil_flavor flavor)
 	case CIL_PORTCON:
 		cil_destroy_portcon(*data);
 		break;
+	case CIL_IBENDPORTCON:
+		cil_destroy_ibendportcon(*data);
+		break;
 	case CIL_NODECON:
 		cil_destroy_nodecon(*data);
 		break;
@@ -1105,6 +1111,8 @@ const char * cil_node_to_string(struct cil_tree_node *node)
 		return CIL_KEY_FILECON;
 	case CIL_IBPKEYCON:
 		return CIL_KEY_IBPKEYCON;
+	case CIL_IBENDPORTCON:
+		return CIL_KEY_IBENDPORTCON;
 	case CIL_PORTCON:
 		return CIL_KEY_PORTCON;
 	case CIL_NODECON:
@@ -1838,6 +1846,16 @@ void cil_netifcon_init(struct cil_netifcon **netifcon)
 	(*netifcon)->context_str = NULL;
 }
 
+void cil_ibendportcon_init(struct cil_ibendportcon **ibendportcon)
+{
+	*ibendportcon = cil_malloc(sizeof(**ibendportcon));
+
+	(*ibendportcon)->dev_name_str = NULL;
+	(*ibendportcon)->port = 0;
+	(*ibendportcon)->context_str = NULL;
+	(*ibendportcon)->context = NULL;
+}
+
 void cil_context_init(struct cil_context **context)
 {
 	*context = cil_malloc(sizeof(**context));
libsepol/cil/src/cil_binary.c +29 -0
index 75398ff..fb65698 100644
@@ -3323,6 +3323,30 @@ exit:
 	return rc;
 }
 
+int cil_ibendportcon_to_policydb(policydb_t *pdb, struct cil_sort *ibendportcons)
+{
+	int rc = SEPOL_ERR;
+	uint32_t i;
+	ocontext_t *tail = NULL;
+
+	for (i = 0; i < ibendportcons->count; i++) {
+		ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_IBENDPORT], &tail);
+		struct cil_ibendportcon *cil_ibendportcon = ibendportcons->array[i];
+
+		new_ocon->u.ibendport.dev_name = cil_strdup(cil_ibendportcon->dev_name_str);
+		new_ocon->u.ibendport.port = cil_ibendportcon->port;
+
+		rc = __cil_context_to_sepol_context(pdb, cil_ibendportcon->context, &new_ocon->context[0]);
+		if (rc != SEPOL_OK)
+			goto exit;
+	}
+
+	return SEPOL_OK;
+
+exit:
+	return rc;
+}
+
 int cil_nodecon_to_policydb(policydb_t *pdb, struct cil_sort *nodecons)
 {
 	int rc = SEPOL_ERR;
@@ -3887,6 +3911,11 @@ int __cil_contexts_to_policydb(policydb_t *pdb, const struct cil_db *db)
 		goto exit;
 	}
 
+	rc = cil_ibendportcon_to_policydb(pdb, db->ibendportcon);
+	if (rc != SEPOL_OK) {
+		goto exit;
+	}
+
 	if (db->target_platform == SEPOL_TARGET_XEN) {
 		rc = cil_pirqcon_to_policydb(pdb, db->pirqcon);
 		if (rc != SEPOL_OK) {
libsepol/cil/src/cil_binary.h +12 -0
index a03d250..5367feb 100644
@@ -342,6 +342,18 @@ int cil_rangetransition_to_policydb(policydb_t *pdb, const struct cil_db *db, st
 int cil_ibpkeycon_to_policydb(policydb_t *pdb, struct cil_sort *ibpkeycons);
 
 /**
+ * Insert cil idbev structure into sepol policydb.
+ * The function is given a structure containing the sorted ibendportcons and
+ * loops over this structure inserting them into the policy database.
+ *
+ * @param[in] pdb The policy database to insert the pkeycon into.
+ * @param[in] node The cil_sort structure that contains the sorted ibendportcons.
+ *
+ * @return SEPOL_OK upon success or an error otherwise.
+ */
+int cil_ibendportcon_to_policydb(policydb_t *pdb, struct cil_sort *pkeycons);
+
+/**
  * Insert cil portcon structure into sepol policydb.
  * The function is given a structure containing the sorted portcons and
  * loops over this structure inserting them into the policy database.
libsepol/cil/src/cil_build_ast.c +65 -0

77 lines not on this page · raw message

libsepol/cil/src/cil_build_ast.h +2 -0
index c2d7b31..8153e51 100644
@@ -177,6 +177,8 @@ int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, stru
 void cil_destroy_filecon(struct cil_filecon *filecon);
 int cil_gen_ibpkeycon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
 void cil_destroy_ibpkeycon(struct cil_ibpkeycon *ibpkeycon);
+int cil_gen_ibendportcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
+void cil_destroy_ibendportcon(struct cil_ibendportcon *ibendportcon);
 int cil_gen_portcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
 void cil_destroy_portcon(struct cil_portcon *portcon);
 int cil_gen_nodecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
libsepol/cil/src/cil_copy_ast.c +25 -0
index 7307b08..7af00aa 100644
@@ -1227,6 +1227,28 @@ int cil_copy_ibpkeycon(struct cil_db *db, void *data, void **copy, __attribute__
 	return SEPOL_OK;
 }
 
+int cil_copy_ibendportcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
+{
+	struct cil_ibendportcon *orig = data;
+	struct cil_ibendportcon *new = NULL;
+
+	cil_ibendportcon_init(&new);
+
+	new->dev_name_str = orig->dev_name_str;
+	new->port = orig->port;
+
+	if (orig->context_str) {
+		new->context_str = orig->context_str;
+	} else {
+		cil_context_init(&new->context);
+		cil_copy_fill_context(db, orig->context, new->context);
+	}
+
+	*copy = new;
+
+	return SEPOL_OK;
+}
+
 int cil_copy_portcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
 {
 	struct cil_portcon *orig = data;
@@ -1942,6 +1964,9 @@ int __cil_copy_node_helper(struct cil_tree_node *orig, __attribute__((unused)) u
 	case CIL_IBPKEYCON:
 		copy_func = &cil_copy_ibpkeycon;
 		break;
+	case CIL_IBENDPORTCON:
+		copy_func = &cil_copy_ibendportcon;
+		break;
 	case CIL_PORTCON:
 		copy_func = &cil_copy_portcon;
 		break;
libsepol/cil/src/cil_flavor.h +1 -0
index 4505b8b..c2f0cee 100644
@@ -114,6 +114,7 @@ enum cil_flavor {
 	CIL_MLS,
 	CIL_SRC_INFO,
 	CIL_IBPKEYCON,
+	CIL_IBENDPORTCON,
 
 /*
  *          boolean  constraint  set  catset
libsepol/cil/src/cil_internal.h +9 -0
index 2add97b..6d6a7d9 100644
@@ -204,6 +204,7 @@ char *CIL_KEY_MLSVALIDATETRANS;
 char *CIL_KEY_CONTEXT;
 char *CIL_KEY_FILECON;
 char *CIL_KEY_IBPKEYCON;
+char *CIL_KEY_IBENDPORTCON;
 char *CIL_KEY_PORTCON;
 char *CIL_KEY_NODECON;
 char *CIL_KEY_GENFSCON;
@@ -288,6 +289,7 @@ struct cil_db {
 	struct cil_sort *filecon;
 	struct cil_sort *nodecon;
 	struct cil_sort *ibpkeycon;
+	struct cil_sort *ibendportcon;
 	struct cil_sort *portcon;
 	struct cil_sort *pirqcon;
 	struct cil_sort *iomemcon;
@@ -789,6 +791,12 @@ struct cil_netifcon {
 	char *context_str;
 };
 
+struct cil_ibendportcon {
+	char *dev_name_str;
+	uint32_t port;
+	char *context_str;
+	struct cil_context *context;
+};
 struct cil_pirqcon {
 	uint32_t pirq;
 	char *context_str;
@@ -974,6 +982,7 @@ int cil_get_symtab(struct cil_tree_node *ast_node, symtab_t **symtab, enum cil_s
 void cil_sort_init(struct cil_sort **sort);
 void cil_sort_destroy(struct cil_sort **sort);
 void cil_netifcon_init(struct cil_netifcon **netifcon);
+void cil_ibendportcon_init(struct cil_ibendportcon **ibendportcon);
 void cil_context_init(struct cil_context **context);
 void cil_level_init(struct cil_level **level);
 void cil_levelrange_init(struct cil_levelrange **lvlrange);
libsepol/cil/src/cil_policy.c +15 -0
index 35a0a29..2196ae8 100644
@@ -1729,6 +1729,20 @@ static void cil_ibpkeycons_to_policy(FILE *out, struct cil_sort *ibpkeycons, int
 	}
 }
 
+static void cil_ibendportcons_to_policy(FILE *out, struct cil_sort *ibendportcons, int mls)
+{
+	uint32_t i;
+
+	for (i = 0; i < ibendportcons->count; i++) {
+		struct cil_ibendportcon *ibendportcon = (struct cil_ibendportcon *)ibendportcons->array[i];
+
+		fprintf(out, "ibendportcon %s ", ibendportcon->dev_name_str);
+		fprintf(out, "%u ", ibendportcon->port);
+		cil_context_to_policy(out, ibendportcon->context, mls);
+		fprintf(out, "\n");
+	}
+}
+
 static void cil_portcons_to_policy(FILE *out, struct cil_sort *portcons, int mls)
 {
 	unsigned i;
@@ -1958,6 +1972,7 @@ void cil_gen_policy(FILE *out, struct cil_db *db)
 	cil_portcons_to_policy(out, db->portcon, db->mls);
 	cil_netifcons_to_policy(out, db->netifcon, db->mls);
 	cil_ibpkeycons_to_policy(out, db->ibpkeycon, db->mls);
+	cil_ibendportcons_to_policy(out, db->ibendportcon, db->mls);
 	cil_nodecons_to_policy(out, db->nodecon, db->mls);
 	cil_pirqcons_to_policy(out, db->pirqcon, db->mls);
 	cil_iomemcons_to_policy(out, db->iomemcon, db->mls);
libsepol/cil/src/cil_post.c +42 -0

72 lines not on this page · raw message

libsepol/cil/src/cil_post.h +1 -0
index fe7f3a5..3d54154 100644
@@ -40,6 +40,7 @@ void cil_post_fc_fill_data(struct fc_data *fc, char *path);
 int cil_post_filecon_compare(const void *a, const void *b);
 int cil_post_ibpkeycon_compare(const void *a, const void *b);
 int cil_post_portcon_compare(const void *a, const void *b);
+int cil_post_ibendportcon_compare(const void *a, const void *b);
 int cil_post_genfscon_compare(const void *a, const void *b);
 int cil_post_netifcon_compare(const void *a, const void *b);
 int cil_post_nodecon_compare(const void *a, const void *b);
libsepol/cil/src/cil_reset_ast.c +10 -0
index fc23a2c..73034a9 100644
@@ -326,6 +326,13 @@ static void cil_reset_netifcon(struct cil_netifcon *netifcon)
 	}
 }
 
+static void cil_reset_ibendportcon(struct cil_ibendportcon *ibendportcon)
+{
+	if (!ibendportcon->context_str) {
+		cil_reset_context(ibendportcon->context);
+	}
+}
+
 static void cil_reset_pirqcon(struct cil_pirqcon *pirqcon)
 {
 	if (pirqcon->context_str == NULL) {
@@ -498,6 +505,9 @@ int __cil_reset_node(struct cil_tree_node *node,  __attribute__((unused)) uint32
 	case CIL_IBPKEYCON:
 		cil_reset_ibpkeycon(node->data);
 		break;
+	case CIL_IBENDPORTCON:
+		cil_reset_ibendportcon(node->data);
+		break;
 	case CIL_PORTCON:
 		cil_reset_portcon(node->data);
 		break;
libsepol/cil/src/cil_resolve_ast.c +28 -0
index 9e3cb2b..a671068 100644
@@ -2086,6 +2086,31 @@ exit:
 	return rc;
 }
 
+int cil_resolve_ibendportcon(struct cil_tree_node *current, void *extra_args)
+{
+	struct cil_ibendportcon *ibendportcon = current->data;
+	struct cil_symtab_datum *con_datum = NULL;
+
+	int rc = SEPOL_ERR;
+
+	if (ibendportcon->context_str) {
+		rc = cil_resolve_name(current, ibendportcon->context_str, CIL_SYM_CONTEXTS, extra_args, &con_datum);
+		if (rc != SEPOL_OK)
+			goto exit;
+
+		ibendportcon->context = (struct cil_context *)con_datum;
+	} else {
+		rc = cil_resolve_context(current, ibendportcon->context, extra_args);
+		if (rc != SEPOL_OK)
+			goto exit;
+	}
+
+	return SEPOL_OK;
+
+exit:
+	return rc;
+}
+
 int cil_resolve_pirqcon(struct cil_tree_node *current, void *extra_args)
 {
 	struct cil_pirqcon *pirqcon = current->data;
@@ -3606,6 +3631,9 @@ int __cil_resolve_ast_node(struct cil_tree_node *node, void *extra_args)
 		case CIL_NETIFCON:
 			rc = cil_resolve_netifcon(node, args);
 			break;
+		case CIL_IBENDPORTCON:
+			rc = cil_resolve_ibendportcon(node, args);
+			break;
 		case CIL_PIRQCON:
 			rc = cil_resolve_pirqcon(node, args);
 			break;
libsepol/cil/src/cil_resolve_ast.h +1 -0
index 0506a3d..82c8ea3 100644
@@ -75,6 +75,7 @@ int cil_resolve_validatetrans(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_context(struct cil_tree_node *current, struct cil_context *context, void *extra_args);
 int cil_resolve_filecon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_ibpkeycon(struct cil_tree_node *current, void *extra_args);
+int cil_resolve_ibendportcon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_portcon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_genfscon(struct cil_tree_node *current, void *extra_args);
 int cil_resolve_nodecon(struct cil_tree_node *current, void *extra_args);
libsepol/cil/src/cil_tree.c +13 -0
index 89706d0..d36401b 100644
@@ -1506,6 +1506,19 @@ void cil_tree_print_node(struct cil_tree_node *node)
 			cil_log(CIL_INFO, "\n");
 			return;
 		}
+		case CIL_IBENDPORTCON: {
+			struct cil_ibendportcon *ibendportcon = node->data;
+
+			cil_log(CIL_INFO, "IBENDPORTCON: %s %u ", ibendportcon->dev_name_str, ibendportcon->port);
+
+			if (ibendportcon->context)
+				cil_tree_print_context(ibendportcon->context);
+			else if (ibendportcon->context_str)
+				cil_log(CIL_INFO, " %s", ibendportcon->context_str);
+
+			cil_log(CIL_INFO, "\n");
+			return;
+		}
 		case CIL_PIRQCON: {
 			struct cil_pirqcon *pirqcon = node->data;
 
libsepol/cil/src/cil_verify.c +23 -0
index 108da33..1036d73 100644
@@ -1012,6 +1012,26 @@ exit:
 	return rc;
 }
 
+int __cil_verify_ibendportcon(struct cil_db *db, struct cil_tree_node *node)
+{
+	int rc = SEPOL_ERR;
+	struct cil_ibendportcon *ib_end_port = node->data;
+	struct cil_context *ctx = ib_end_port->context;
+
+	/* Verify only when anonymous */
+	if (!ctx->datum.name) {
+		rc = __cil_verify_context(db, ctx);
+		if (rc != SEPOL_OK)
+			goto exit;
+	}
+
+	return SEPOL_OK;
+
+exit:
+	cil_tree_log(node, CIL_ERR, "Invalid ibendportcon");
+	return rc;
+}
+
 int __cil_verify_genfscon(struct cil_db *db, struct cil_tree_node *node)
 {
 	int rc = SEPOL_ERR;
@@ -1475,6 +1495,9 @@ int __cil_verify_helper(struct cil_tree_node *node, uint32_t *finished, void *ex
 		case CIL_IBPKEYCON:
 			rc = __cil_verify_ibpkeycon(db, node);
 			break;
+		case CIL_IBENDPORTCON:
+			rc = __cil_verify_ibendportcon(db, node);
+			break;
 		case CIL_PORTCON:
 			rc = __cil_verify_portcon(db, node);
 			break;
Signature · 1 line
2.7.4
#17 lore raw

PATCH 7/9 semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local storage for new and modified pkey records in pkeys.local. Update semanage to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow in seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++
 libsemanage/include/semanage/ibpkeys_local.h  |  36 +++
 libsemanage/include/semanage/ibpkeys_policy.h |  28 ++
 libsemanage/include/semanage/semanage.h       |   3 +
 libsemanage/src/direct_api.c                  |  29 +-
 libsemanage/src/handle.h                      |  36 ++-
 libsemanage/src/ibpkey_internal.h             |  52 +++
 libsemanage/src/ibpkey_record.c               | 185 +++++++++++
 libsemanage/src/ibpkeys_file.c                | 181 +++++++++++
 libsemanage/src/ibpkeys_local.c               | 178 ++++++++++
 libsemanage/src/ibpkeys_policy.c              |  52 +++
 libsemanage/src/ibpkeys_policydb.c            |  62 ++++
 libsemanage/src/libsemanage.map               |   1 +
 libsemanage/src/policy_components.c           |   5 +-
 libsemanage/src/semanage_store.c              |   1 +
 libsemanage/src/semanage_store.h              |   1 +
 libsemanage/src/semanageswig.i                |   3 +
 libsemanage/src/semanageswig_python.i         |  43 +++
 libsemanage/utils/semanage_migrate_store      |   3 +-
 libsepol/include/sepol/ibpkey_record.h        |  77 +++++
 libsepol/include/sepol/ibpkeys.h              |  44 +++
 libsepol/include/sepol/sepol.h                |   2 +
 libsepol/src/ibpkey_internal.h                |  21 ++
 libsepol/src/ibpkey_record.c                  | 448 ++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263 +++++++++++++++
 python/semanage/semanage                      |  60 +++-
 python/semanage/seobject.py                   | 255 +++++++++++++++
 27 files changed, 2129 insertions(+), 16 deletions(-)
 create mode 100644 libsemanage/include/semanage/ibpkey_record.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_local.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h
 create mode 100644 libsemanage/src/ibpkey_internal.h
 create mode 100644 libsemanage/src/ibpkey_record.c
 create mode 100644 libsemanage/src/ibpkeys_file.c
 create mode 100644 libsemanage/src/ibpkeys_local.c
 create mode 100644 libsemanage/src/ibpkeys_policy.c
 create mode 100644 libsemanage/src/ibpkeys_policydb.c
 create mode 100644 libsepol/include/sepol/ibpkey_record.h
 create mode 100644 libsepol/include/sepol/ibpkeys.h
 create mode 100644 libsepol/src/ibpkey_internal.h
 create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c
libsemanage/include/semanage/ibpkey_record.h new file +76 -0
new file mode 100644
index 0000000..d76aaae
@@ -0,0 +1,76 @@
+/* Copyright (C) 2017 Mellanox Technologies Inc */
+
+#ifndef _SEMANAGE_IBPKEY_RECORD_H_
+#define _SEMANAGE_IBPKEY_RECORD_H_
+
+#include <semanage/context_record.h>
+#include <semanage/handle.h>
+#include <stddef.h>
+
+#ifndef _SEMANAGE_IBPKEY_DEFINED_
+struct semanage_ibpkey;
+struct semanage_ibpkey_key;
+typedef struct semanage_ibpkey semanage_ibpkey_t;
+typedef struct semanage_ibpkey_key semanage_ibpkey_key_t;
+#define _SEMANAGE_IBPKEY_DEFINED_
+#endif
+
+#define INET6_ADDRLEN 16
+
+extern int semanage_ibpkey_compare(const semanage_ibpkey_t *ibpkey,
+				   const semanage_ibpkey_key_t *key);
+
+extern int semanage_ibpkey_compare2(const semanage_ibpkey_t *ibpkey,
+				    const semanage_ibpkey_t *ibpkey2);
+
+extern int semanage_ibpkey_key_create(semanage_handle_t *handle,
+				      const char *subnet_prefix,
+				      int low, int high,
+				      semanage_ibpkey_key_t **key_ptr);
+
+extern int semanage_ibpkey_key_extract(semanage_handle_t *handle,
+				       const semanage_ibpkey_t *ibpkey,
+				       semanage_ibpkey_key_t **key_ptr);
+
+extern void semanage_ibpkey_key_free(semanage_ibpkey_key_t *key);
+
+extern int semanage_ibpkey_get_subnet_prefix(semanage_handle_t *handle,
+					     const semanage_ibpkey_t *ibpkey,
+					     char **subnet_prefix_ptr);
+
+extern int semanage_ibpkey_get_subnet_prefix_bytes(semanage_handle_t *handle,
+						   const semanage_ibpkey_t *ibpkey,
+						   char **subnet_prefix);
+
+extern int semanage_ibpkey_set_subnet_prefix(semanage_handle_t *handle,
+					     semanage_ibpkey_t *ibpkey,
+					     const char *subnet_prefix);
+
+extern int semanage_ibpkey_set_subnet_prefix_bytes(semanage_handle_t *handle,
+						   semanage_ibpkey_t *ibpkey,
+						   const char *subnet_prefix);
+
+extern int semanage_ibpkey_get_low(const semanage_ibpkey_t *ibpkey);
+
+extern int semanage_ibpkey_get_high(const semanage_ibpkey_t *ibpkey);
+
+extern void semanage_ibpkey_set_pkey(semanage_ibpkey_t *ibpkey, int pkey_num);
+
+extern void semanage_ibpkey_set_range(semanage_ibpkey_t *ibpkey, int low, int high);
+
+extern semanage_context_t *semanage_ibpkey_get_con(const semanage_ibpkey_t *ibpkey);
+
+extern int semanage_ibpkey_set_con(semanage_handle_t *handle,
+				   semanage_ibpkey_t *ibpkey,
+				   semanage_context_t *con);
+
+extern int semanage_ibpkey_create(semanage_handle_t *handle,
+				  semanage_ibpkey_t **ibpkey_ptr);
+
+extern int semanage_ibpkey_clone(semanage_handle_t *handle,
+				 const semanage_ibpkey_t *ibpkey,
+				 semanage_ibpkey_t **ibpkey_ptr);
+
+extern void semanage_ibpkey_free(semanage_ibpkey_t *ibpkey);
+
+#endif
libsemanage/include/semanage/ibpkeys_local.h new file +36 -0
new file mode 100644
index 0000000..079a642
@@ -0,0 +1,36 @@
+/* Copyright (C) 2017 Mellanox Technologies Inc */
+
+#ifndef _SEMANAGE_IBPKEYS_LOCAL_H_
+#define _SEMANAGE_IBPKEYS_LOCAL_H_
+
+#include <semanage/ibpkey_record.h>
+#include <semanage/handle.h>
+
+extern int semanage_ibpkey_modify_local(semanage_handle_t *handle,
+					const semanage_ibpkey_key_t *key,
+					const semanage_ibpkey_t *data);
+
+extern int semanage_ibpkey_del_local(semanage_handle_t *handle,
+				     const semanage_ibpkey_key_t *key);
+
+extern int semanage_ibpkey_query_local(semanage_handle_t *handle,
+				       const semanage_ibpkey_key_t *key,
+				       semanage_ibpkey_t **response);
+
+extern int semanage_ibpkey_exists_local(semanage_handle_t *handle,
+					const semanage_ibpkey_key_t *key,
+					int *response);
+
+extern int semanage_ibpkey_count_local(semanage_handle_t *handle,
+				       unsigned int *response);
+
+extern int semanage_ibpkey_iterate_local(semanage_handle_t *handle,
+					 int (*handler)(const semanage_ibpkey_t *
+							record, void *varg),
+					 void *handler_arg);
+
+extern int semanage_ibpkey_list_local(semanage_handle_t *handle,
+				      semanage_ibpkey_t ***records,
+				      unsigned int *count);
+
+#endif
libsemanage/include/semanage/ibpkeys_policy.h new file +28 -0
new file mode 100644
index 0000000..c287ac0
@@ -0,0 +1,28 @@
+/* Copyright (C) 2017 Mellanox Technolgies Inc. */
+
+#ifndef _SEMANAGE_IBPKEYS_POLICY_H_
+#define _SEMANAGE_IBPKEYS_POLICY_H_
+
+#include <semanage/handle.h>
+#include <semanage/ibpkey_record.h>
+
+extern int semanage_ibpkey_query(semanage_handle_t *handle,
+				 const semanage_ibpkey_key_t *key,
+				 semanage_ibpkey_t **response);
+
+extern int semanage_ibpkey_exists(semanage_handle_t *handle,
+				  const semanage_ibpkey_key_t *key, int *response);
+
+extern int semanage_ibpkey_count(semanage_handle_t *handle,
+				 unsigned int *response);
+
+extern int semanage_ibpkey_iterate(semanage_handle_t *handle,
+				   int (*handler)(const semanage_ibpkey_t *record,
+						  void *varg),
+				   void *handler_arg);
+
+extern int semanage_ibpkey_list(semanage_handle_t *handle,
+				semanage_ibpkey_t ***records,
+				unsigned int *count);
+
+#endif
libsemanage/include/semanage/semanage.h +3 -0
index f417ce4..cebf3f4 100644
@@ -33,6 +33,7 @@
 #include <semanage/context_record.h>
 #include <semanage/iface_record.h>
 #include <semanage/port_record.h>
+#include <semanage/ibpkey_record.h>
 #include <semanage/node_record.h>
 
 /* Dbase */
@@ -47,6 +48,8 @@
 #include <semanage/seusers_policy.h>
 #include <semanage/ports_local.h>
 #include <semanage/ports_policy.h>
+#include <semanage/ibpkeys_local.h>
+#include <semanage/ibpkeys_policy.h>
 #include <semanage/interfaces_local.h>
 #include <semanage/interfaces_policy.h>
 #include <semanage/nodes_local.h>
libsemanage/src/direct_api.c +27 -2
index f4b0416..436e334 100644
@@ -40,6 +40,7 @@
 #include "user_internal.h"
 #include "seuser_internal.h"
 #include "port_internal.h"
+#include "ibpkey_internal.h"
 #include "iface_internal.h"
 #include "boolean_internal.h"
 #include "fcontext_internal.h"
@@ -224,6 +225,14 @@ int semanage_direct_connect(semanage_handle_t * sh)
 				 semanage_node_dbase_local(sh)) < 0)
 		goto err;
 
+	if (ibpkey_file_dbase_init(sh,
+				 semanage_path(SEMANAGE_ACTIVE,
+					       SEMANAGE_IBPKEYS_LOCAL),
+				 semanage_path(SEMANAGE_TMP,
+					       SEMANAGE_IBPKEYS_LOCAL),
+				 semanage_ibpkey_dbase_local(sh)) < 0)
+		goto err;
+
 	/* Object databases: local modifications + policy */
 	if (user_base_policydb_dbase_init(sh,
 					  semanage_user_base_dbase_policy(sh)) <
@@ -248,6 +257,9 @@ int semanage_direct_connect(semanage_handle_t * sh)
 	if (port_policydb_dbase_init(sh, semanage_port_dbase_policy(sh)) < 0)
 		goto err;
 
+	if (ibpkey_policydb_dbase_init(sh, semanage_ibpkey_dbase_policy(sh)) < 0)
+		goto err;
+
 	if (iface_policydb_dbase_init(sh, semanage_iface_dbase_policy(sh)) < 0)
 		goto err;
 
@@ -320,6 +332,7 @@ static int semanage_direct_disconnect(semanage_handle_t * sh)
 	user_extra_file_dbase_release(semanage_user_extra_dbase_local(sh));
 	user_join_dbase_release(semanage_user_dbase_local(sh));
 	port_file_dbase_release(semanage_port_dbase_local(sh));
+	ibpkey_file_dbase_release(semanage_ibpkey_dbase_local(sh));
 	iface_file_dbase_release(semanage_iface_dbase_local(sh));
 	bool_file_dbase_release(semanage_bool_dbase_local(sh));
 	fcontext_file_dbase_release(semanage_fcontext_dbase_local(sh));
@@ -331,6 +344,7 @@ static int semanage_direct_disconnect(semanage_handle_t * sh)
 	user_extra_file_dbase_release(semanage_user_extra_dbase_policy(sh));
 	user_join_dbase_release(semanage_user_dbase_policy(sh));
 	port_policydb_dbase_release(semanage_port_dbase_policy(sh));
+	ibpkey_policydb_dbase_release(semanage_ibpkey_dbase_policy(sh));
 	iface_policydb_dbase_release(semanage_iface_dbase_policy(sh));
 	bool_policydb_dbase_release(semanage_bool_dbase_policy(sh));
 	fcontext_file_dbase_release(semanage_fcontext_dbase_policy(sh));
@@ -1144,13 +1158,15 @@ static int semanage_direct_commit(semanage_handle_t * sh)
 
 	int do_rebuild, do_write_kernel, do_install;
 	int fcontexts_modified, ports_modified, seusers_modified,
-		disable_dontaudit, preserve_tunables;
+		disable_dontaudit, preserve_tunables, ibpkeys_modified;
 	dbase_config_t *users = semanage_user_dbase_local(sh);
 	dbase_config_t *users_base = semanage_user_base_dbase_local(sh);
 	dbase_config_t *pusers_base = semanage_user_base_dbase_policy(sh);
 	dbase_config_t *pusers_extra = semanage_user_extra_dbase_policy(sh);
 	dbase_config_t *ports = semanage_port_dbase_local(sh);
 	dbase_config_t *pports = semanage_port_dbase_policy(sh);
+	dbase_config_t *ibpkeys = semanage_ibpkey_dbase_local(sh);
+	dbase_config_t *pibpkeys = semanage_ibpkey_dbase_policy(sh);
 	dbase_config_t *bools = semanage_bool_dbase_local(sh);
 	dbase_config_t *pbools = semanage_bool_dbase_policy(sh);
 	dbase_config_t *ifaces = semanage_iface_dbase_local(sh);
@@ -1164,6 +1180,7 @@ static int semanage_direct_commit(semanage_handle_t * sh)
 
 	/* Modified flags that we need to use more than once. */
 	ports_modified = ports->dtable->is_modified(ports->dbase);
+	ibpkeys_modified = ibpkeys->dtable->is_modified(ibpkeys->dbase);
 	seusers_modified = seusers->dtable->is_modified(seusers->dbase);
 	fcontexts_modified = fcontexts->dtable->is_modified(fcontexts->dbase);
 
@@ -1285,7 +1302,7 @@ rebuild:
 	 * that live under /etc/selinux (kernel policy, seusers, file contexts)
 	 * will be modified.
 	 */
-	do_write_kernel = do_rebuild | ports_modified |
+	do_write_kernel = do_rebuild | ports_modified | ibpkeys_modified |
 		bools->dtable->is_modified(bools->dbase) |
 		ifaces->dtable->is_modified(ifaces->dbase) |
 		nodes->dtable->is_modified(nodes->dbase) |
@@ -1431,6 +1448,7 @@ rebuild:
 	/* Attach our databases to the policydb we just created or loaded. */
 	dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pports->dbase, out);
+	dbase_policydb_attach((dbase_policydb_t *) pibpkeys->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pifaces->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pbools->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pnodes->dbase, out);
@@ -1479,6 +1497,12 @@ rebuild:
 			goto cleanup;
 	}
 
+	/* Validate local ibpkeys for overlap */
+	if (do_rebuild || ibpkeys_modified) {
+		retval = semanage_ibpkey_validate_local(sh);
+		if (retval < 0)
+			goto cleanup;
+	}
 	/* ================== Write non-policydb components ========= */
 
 	/* Commit changes to components */
@@ -1558,6 +1582,7 @@ cleanup:
 	/* Detach from policydb, so it can be freed */
 	dbase_policydb_detach((dbase_policydb_t *) pusers_base->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pports->dbase);
+	dbase_policydb_detach((dbase_policydb_t *) pibpkeys->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pifaces->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pnodes->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pbools->dbase);
libsemanage/src/handle.h +25 -11
index 64175c4..306727a 100644
@@ -79,7 +79,7 @@ struct semanage_handle {
 	struct semanage_policy_table *funcs;
 
 	/* Object databases */
-#define DBASE_COUNT      19
+#define DBASE_COUNT      21
 
 /* Local modifications */
 #define DBASE_LOCAL_USERS_BASE  0
@@ -91,20 +91,22 @@ struct semanage_handle {
 #define DBASE_LOCAL_FCONTEXTS	6
 #define DBASE_LOCAL_SEUSERS     7
 #define DBASE_LOCAL_NODES       8
+#define DBASE_LOCAL_IBPKEYS     9
 
 /* Policy + Local modifications */
-#define DBASE_POLICY_USERS_BASE  9
-#define DBASE_POLICY_USERS_EXTRA 10
-#define DBASE_POLICY_USERS       11
-#define DBASE_POLICY_PORTS       12
-#define DBASE_POLICY_INTERFACES  13
-#define DBASE_POLICY_BOOLEANS    14
-#define DBASE_POLICY_FCONTEXTS   15
-#define DBASE_POLICY_SEUSERS     16
-#define DBASE_POLICY_NODES       17
+#define DBASE_POLICY_USERS_BASE  10
+#define DBASE_POLICY_USERS_EXTRA 11
+#define DBASE_POLICY_USERS       12
+#define DBASE_POLICY_PORTS       13
+#define DBASE_POLICY_INTERFACES  14
+#define DBASE_POLICY_BOOLEANS    15
+#define DBASE_POLICY_FCONTEXTS   16
+#define DBASE_POLICY_SEUSERS     17
+#define DBASE_POLICY_NODES       18
+#define DBASE_POLICY_IBPKEYS     19
 
 /* Active kernel policy */
-#define DBASE_ACTIVE_BOOLEANS    18
+#define DBASE_ACTIVE_BOOLEANS    20
 	dbase_config_t dbase[DBASE_COUNT];
 };
 
@@ -134,6 +136,12 @@ static inline
 }
 
 static inline
+    dbase_config_t * semanage_ibpkey_dbase_local(semanage_handle_t * handle)
+{
+	return &handle->dbase[DBASE_LOCAL_IBPKEYS];
+}
+
+static inline
     dbase_config_t * semanage_iface_dbase_local(semanage_handle_t * handle)
 {
 	return &handle->dbase[DBASE_LOCAL_INTERFACES];
@@ -190,6 +198,12 @@ static inline
 }
 
 static inline
+    dbase_config_t * semanage_ibpkey_dbase_policy(semanage_handle_t * handle)
+{
+	return &handle->dbase[DBASE_POLICY_IBPKEYS];
+}
+
+static inline
     dbase_config_t * semanage_iface_dbase_policy(semanage_handle_t * handle)
 {
 	return &handle->dbase[DBASE_POLICY_INTERFACES];
libsemanage/src/ibpkey_internal.h new file +52 -0

52 lines not on this page · raw message

libsemanage/src/ibpkey_record.c new file +185 -0

185 lines not on this page · raw message

libsemanage/src/ibpkeys_file.c new file +181 -0

181 lines not on this page · raw message

libsemanage/src/ibpkeys_local.c new file +178 -0

178 lines not on this page · raw message

libsemanage/src/ibpkeys_policy.c new file +52 -0

52 lines not on this page · raw message

libsemanage/src/ibpkeys_policydb.c new file +62 -0

62 lines not on this page · raw message

libsemanage/src/libsemanage.map +1 -0
index 9f8a754..041b1ce 100644
@@ -18,6 +18,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_root;
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
 	  semanage_iface_*; semanage_port_*; semanage_context_*;
+	  semanage_ibpkey_*;
 	  semanage_node_*;
 	  semanage_fcontext_*; semanage_access_check; semanage_set_create_store;
 	  semanage_is_connected; semanage_get_disable_dontaudit; semanage_set_disable_dontaudit;
libsemanage/src/policy_components.c +4 -1
index d31bd48..136c5a7 100644
@@ -137,12 +137,14 @@ int semanage_base_merge_components(semanage_handle_t * handle)
 
 		{semanage_node_dbase_local(handle),
 		 semanage_node_dbase_policy(handle), MODE_MODIFY | MODE_SORT},
+
+		{semanage_ibpkey_dbase_local(handle),
+		 semanage_ibpkey_dbase_policy(handle), MODE_MODIFY},
 	};
 	const unsigned int CCOUNT = sizeof(components) / sizeof(components[0]);
 
 	/* Merge components into policy (and validate) */
 	for (i = 0; i < CCOUNT; i++) {
-
 		record_t **records = NULL;
 		unsigned int nrecords = 0;
 
@@ -218,6 +220,7 @@ int semanage_commit_components(semanage_handle_t * handle)
 		semanage_seuser_dbase_policy(handle),
 		semanage_bool_dbase_active(handle),
 		semanage_node_dbase_local(handle),
+		semanage_ibpkey_dbase_local(handle),
 	};
 	const int CCOUNT = sizeof(components) / sizeof(components[0]);
 
libsemanage/src/semanage_store.c +1 -0
index 6b75002..f61f3b2 100644
@@ -99,6 +99,7 @@ static const char *semanage_sandbox_paths[SEMANAGE_STORE_NUM_PATHS] = {
 	"/homedir_template",
 	"/file_contexts.template",
 	"/commit_num",
+	"/pkeys.local",
 	"/ports.local",
 	"/interfaces.local",
 	"/nodes.local",
libsemanage/src/semanage_store.h +1 -0
index 0b96fbe..c7bcf44 100644
@@ -44,6 +44,7 @@ enum semanage_sandbox_defs {
 	SEMANAGE_HOMEDIR_TMPL,
 	SEMANAGE_FC_TMPL,
 	SEMANAGE_COMMIT_NUM_FILE,
+	SEMANAGE_IBPKEYS_LOCAL,
 	SEMANAGE_PORTS_LOCAL,
 	SEMANAGE_INTERFACES_LOCAL,
 	SEMANAGE_NODES_LOCAL,
libsemanage/src/semanageswig.i +3 -0
index 583b7d8..d3ca795 100644
@@ -39,6 +39,9 @@
 %include "../include/semanage/port_record.h"
 %include "../include/semanage/ports_local.h"
 %include "../include/semanage/ports_policy.h"
+%include "../include/semanage/ibpkey_record.h"
+%include "../include/semanage/ibpkeys_local.h"
+%include "../include/semanage/ibpkeys_policy.h"
 %include "../include/semanage/fcontext_record.h"
 %include "../include/semanage/fcontexts_local.h"
 %include "../include/semanage/fcontexts_policy.h"
libsemanage/src/semanageswig_python.i +43 -0

49 lines not on this page · raw message

libsemanage/utils/semanage_migrate_store +2 -1
index 0ebd285..325de47 100755
@@ -253,7 +253,8 @@ if __name__ == "__main__":
 		"preserve_tunables",
 		"policy.kern",
 		"file_contexts",
-		"homedir_template"]
+		"homedir_template",
+                "pkeys.local"]
 
 
 	create_dir(newroot_path(), 0o755)
libsepol/include/sepol/ibpkey_record.h new file +77 -0

77 lines not on this page · raw message

libsepol/include/sepol/ibpkeys.h new file +44 -0

44 lines not on this page · raw message

libsepol/include/sepol/sepol.h +2 -0
index 513f77d..540f01d 100644
@@ -11,12 +11,14 @@ extern "C" {
 #include <sepol/user_record.h>
 #include <sepol/context_record.h>
 #include <sepol/iface_record.h>
+#include <sepol/ibpkey_record.h>
 #include <sepol/port_record.h>
 #include <sepol/boolean_record.h>
 #include <sepol/node_record.h>
 
 #include <sepol/booleans.h>
 #include <sepol/interfaces.h>
+#include <sepol/ibpkeys.h>
 #include <sepol/ports.h>
 #include <sepol/nodes.h>
 #include <sepol/users.h>
libsepol/src/ibpkey_internal.h new file +21 -0
new file mode 100644
index 0000000..addf80a
@@ -0,0 +1,21 @@
+#ifndef _SEPOL_IBPKEY_INTERNAL_H_
+#define _SEPOL_IBPKEY_INTERNAL_H_
+
+#include <sepol/ibpkey_record.h>
+#include <sepol/ibpkeys.h>
+#include "dso.h"
+
+hidden_proto(sepol_ibpkey_create)
+hidden_proto(sepol_ibpkey_free)
+hidden_proto(sepol_ibpkey_get_con)
+hidden_proto(sepol_ibpkey_get_high)
+hidden_proto(sepol_ibpkey_get_low)
+hidden_proto(sepol_ibpkey_key_create)
+hidden_proto(sepol_ibpkey_key_unpack)
+hidden_proto(sepol_ibpkey_set_con)
+hidden_proto(sepol_ibpkey_set_range)
+hidden_proto(sepol_ibpkey_get_subnet_prefix)
+hidden_proto(sepol_ibpkey_get_subnet_prefix_bytes)
+hidden_proto(sepol_ibpkey_set_subnet_prefix)
+hidden_proto(sepol_ibpkey_set_subnet_prefix_bytes)
+#endif
libsepol/src/ibpkey_record.c new file +448 -0

448 lines not on this page · raw message

libsepol/src/ibpkeys.c new file +263 -0

263 lines not on this page · raw message

python/semanage/semanage +59 -1

96 lines not on this page · raw message

python/semanage/seobject.py +255 -0

267 lines not on this page · raw message

Signature · 1 line
2.7.4
#18 lore raw

Re: [PATCH v1 7/9] semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

Quoted 86 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow in
seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++ libsemanage/include/semanage/ibpkeys_local.h  |  36 +++ libsemanage/include/semanage/ibpkeys_policy.h |  28 ++ libsemanage/include/semanage/semanage.h       |   3 + libsemanage/src/direct_api.c                  |  29 +- libsemanage/src/handle.h                      |  36 ++- libsemanage/src/ibpkey_internal.h             |  52 +++ libsemanage/src/ibpkey_record.c               | 185 +++++++++++ libsemanage/src/ibpkeys_file.c                | 181 +++++++++++ libsemanage/src/ibpkeys_local.c               | 178 ++++++++++ libsemanage/src/ibpkeys_policy.c              |  52 +++ libsemanage/src/ibpkeys_policydb.c            |  62 ++++ libsemanage/src/libsemanage.map               |   1 + libsemanage/src/policy_components.c           |   5 +- libsemanage/src/semanage_store.c              |   1 + libsemanage/src/semanage_store.h              |   1 + libsemanage/src/semanageswig.i                |   3 + libsemanage/src/semanageswig_python.i         |  43 +++ libsemanage/utils/semanage_migrate_store      |   3 +- libsepol/include/sepol/ibpkey_record.h        |  77 +++++ libsepol/include/sepol/ibpkeys.h              |  44 +++ libsepol/include/sepol/sepol.h                |   2 + libsepol/src/ibpkey_internal.h                |  21 ++ libsepol/src/ibpkey_record.c                  | 448
++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263 +++++++++++++++ python/semanage/semanage                      |  60 +++- python/semanage/seobject.py                   | 255 +++++++++++++++

 27 files changed, 2129 insertions(+), 16 deletions(-)

 create mode 100644 libsemanage/include/semanage/ibpkey_record.h create mode 100644 libsemanage/include/semanage/ibpkeys_local.h create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h create mode 100644 libsemanage/src/ibpkey_internal.h create mode 100644 libsemanage/src/ibpkey_record.c create mode 100644 libsemanage/src/ibpkeys_file.c create mode 100644 libsemanage/src/ibpkeys_local.c create mode 100644 libsemanage/src/ibpkeys_policy.c create mode 100644 libsemanage/src/ibpkeys_policydb.c create mode 100644 libsepol/include/sepol/ibpkey_record.h create mode 100644 libsepol/include/sepol/ibpkeys.h create mode 100644 libsepol/src/ibpkey_internal.h create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c

libsemanage/include/semanage/ibpkey_record.h new file +8 -0
new file mode 100644
index 0000000..d76aaae
@@ -0,0 +1,76 @@
+/* Copyright (C) 2017 Mellanox Technologies Inc */
+
+#ifndef _SEMANAGE_IBPKEY_RECORD_H_
+#define _SEMANAGE_IBPKEY_RECORD_H_
+
+#include <semanage/context_record.h>
+#include <semanage/handle.h>
+#include <stddef.h>

libsemanage/include/semanage/ibpkey_record.h line 18

Quoted 10 lines
libsemanage/include/semanage/ibpkey_record.h new file +10 -0
+
+#ifndef _SEMANAGE_IBPKEY_DEFINED_
+struct semanage_ibpkey;
+struct semanage_ibpkey_key;
+typedef struct semanage_ibpkey semanage_ibpkey_t;
+typedef struct semanage_ibpkey_key semanage_ibpkey_key_t;
+#define _SEMANAGE_IBPKEY_DEFINED_
+#endif
+
+#define INET6_ADDRLEN 16

We shouldn't expose this in a public header; it's an implementation detail. Likely could/should define it as sizeof(struct in6_addr) to ensure consistency?

Quoted 7 lines
libsepol/include/sepol/ibpkey_record.h new file +0 -0
new file mode 100644
index 0000000..fff4591

libsepol/include/sepol/ibpkey_record.h line 9

Quoted 9 lines
libsepol/include/sepol/ibpkey_record.h new file +9 -0
@@ -0,0 +1,77 @@
+#ifndef _SEPOL_IBPKEY_RECORD_H_
+#define _SEPOL_IBPKEY_RECORD_H_
+
+#include <stddef.h>
+#include <sepol/context_record.h>
+#include <sepol/handle.h>
+#include <sys/cdefs.h>
+
+#define INET6_ADDRLEN 16

Ditto

Quoted 80 lines
libsepol/src/ibpkey_record.c new file +41 -0
new file mode 100644
index 0000000..4eed083
@@ -0,0 +1,448 @@
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <sepol/ibpkey_record.h>
+
+#include "ibpkey_internal.h"
+#include "context_internal.h"
+#include "debug.h"
+
+struct sepol_ibpkey {
+	/* Subnet prefix */
+	char *subnet_prefix;
+
+	/* Low - High range. Same for single ibpkeys. */
+	int low, high;
+
+	/* Context */
+	sepol_context_t *con;
+};
+
+struct sepol_ibpkey_key {
+	/* Subnet prefix */
+	char *subnet_prefix;
+
+	/* Low - High range. Same for single ibpkeys. */
+	int low, high;
+};
+
+/* Converts a string represtation (subnet_prefix_str)
+ * to a numeric representation (subnet_prefix_bytes)
+ */
+static int ibpkey_parse_subnet_prefix(sepol_handle_t *handle,
+				      const char *subnet_prefix_str,
+				      char *subnet_prefix_bytes)
+{
+	struct in6_addr in_addr;
+
+	if (inet_pton(AF_INET6, subnet_prefix_str, &in_addr) <= 0) {
+		ERR(handle, "could not parse IPv6 address for ibpkey

subnet prefix %s: %s",

libsepol/src/ibpkey_record.c new file +31 -0
+		    subnet_prefix_str, strerror(errno));
+		return STATUS_ERR;
+	}
+
+	memcpy(subnet_prefix_bytes, in_addr.s6_addr, INET6_ADDRLEN);
+
+	return STATUS_SUCCESS;
+}
+
+static int ibpkey_alloc_subnet_prefix(sepol_handle_t *handle,
+				      char **subnet_prefix)
+{
+	char *tmp_subnet_prefix = malloc(INET6_ADDRLEN);
+
+	if (!tmp_subnet_prefix)
+		goto omem;
+
+	*subnet_prefix = tmp_subnet_prefix;
+	return STATUS_SUCCESS;
+
+omem:
+	ERR(handle, "out of memory");
+	return STATUS_ERR;
+}
+
+/* Converts a numeric representation (subnet_prefix_bytes)
+ * to a string representation (subnet_prefix_str)
+ */
+
+static int ibpkey_expand_subnet_prefix(sepol_handle_t *handle,
+				       char *subnet_prefix_bytes,

libsepol/src/ibpkey_record.c line 82

Quoted 10 lines
libsepol/src/ibpkey_record.c new file +10 -0
+				       char *subnet_prefix_str)
+{
+	struct in6_addr addr;
+
+	memset(&addr, 0, sizeof(struct in6_addr));
+#ifdef DARWIN
+	memcpy(&addr.s6_addr[0], subnet_prefix_bytes, 16);
+#else
+	memcpy(&addr.s6_addr32[0], subnet_prefix_bytes, 16);
+#endif

Another case where you can drop #ifdef DARWIN and just use s6_addr.

#19 lore raw

Re: [PATCH v1 7/9] semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

Quoted 101 lines · Stephen Smalley
Quoted 86 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow in
seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++
 libsemanage/include/semanage/ibpkeys_local.h  |  36 +++
 libsemanage/include/semanage/ibpkeys_policy.h |  28 ++
 libsemanage/include/semanage/semanage.h       |   3 +
 libsemanage/src/direct_api.c                  |  29 +-
 libsemanage/src/handle.h                      |  36 ++-
 libsemanage/src/ibpkey_internal.h             |  52 +++
 libsemanage/src/ibpkey_record.c               | 185 +++++++++++
 libsemanage/src/ibpkeys_file.c                | 181 +++++++++++
 libsemanage/src/ibpkeys_local.c               | 178 ++++++++++
 libsemanage/src/ibpkeys_policy.c              |  52 +++
 libsemanage/src/ibpkeys_policydb.c            |  62 ++++
 libsemanage/src/libsemanage.map               |   1 +
 libsemanage/src/policy_components.c           |   5 +-
 libsemanage/src/semanage_store.c              |   1 +
 libsemanage/src/semanage_store.h              |   1 +
 libsemanage/src/semanageswig.i                |   3 +
 libsemanage/src/semanageswig_python.i         |  43 +++
 libsemanage/utils/semanage_migrate_store      |   3 +-
 libsepol/include/sepol/ibpkey_record.h        |  77 +++++
 libsepol/include/sepol/ibpkeys.h              |  44 +++
 libsepol/include/sepol/sepol.h                |   2 +
 libsepol/src/ibpkey_internal.h                |  21 ++
 libsepol/src/ibpkey_record.c                  | 448
++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263 +++++++++++++++
 python/semanage/semanage                      |  60 +++-
 python/semanage/seobject.py                   | 255 +++++++++++++++
 27 files changed, 2129 insertions(+), 16 deletions(-)
 create mode 100644 libsemanage/include/semanage/ibpkey_record.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_local.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h
 create mode 100644 libsemanage/src/ibpkey_internal.h
 create mode 100644 libsemanage/src/ibpkey_record.c
 create mode 100644 libsemanage/src/ibpkeys_file.c
 create mode 100644 libsemanage/src/ibpkeys_local.c
 create mode 100644 libsemanage/src/ibpkeys_policy.c
 create mode 100644 libsemanage/src/ibpkeys_policydb.c
 create mode 100644 libsepol/include/sepol/ibpkey_record.h
 create mode 100644 libsepol/include/sepol/ibpkeys.h
 create mode 100644 libsepol/src/ibpkey_internal.h
 create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c
libsemanage/include/semanage/ibpkey_record.h new file +8 -0
new file mode 100644
index 0000000..d76aaae
@@ -0,0 +1,76 @@
+/* Copyright (C) 2017 Mellanox Technologies Inc */
+
+#ifndef _SEMANAGE_IBPKEY_RECORD_H_
+#define _SEMANAGE_IBPKEY_RECORD_H_
+
+#include <semanage/context_record.h>
+#include <semanage/handle.h>
+#include <stddef.h>

libsemanage/include/semanage/ibpkey_record.h line 18

Quoted 10 lines
libsemanage/include/semanage/ibpkey_record.h new file +10 -0
+
+#ifndef _SEMANAGE_IBPKEY_DEFINED_
+struct semanage_ibpkey;
+struct semanage_ibpkey_key;
+typedef struct semanage_ibpkey semanage_ibpkey_t;
+typedef struct semanage_ibpkey_key semanage_ibpkey_key_t;
+#define _SEMANAGE_IBPKEY_DEFINED_
+#endif
+
+#define INET6_ADDRLEN 16

We shouldn't expose this in a public header; it's an implementation detail. Likely could/should define it as sizeof(struct in6_addr) to ensure consistency?

Quoted 2 lines

libsemanage/include/semanage/ibpkey_record.h line 19

Quoted 1 line
libsemanage/include/semanage/ibpkey_record.h new file +1 -0
+#define INET6_ADDRLEN 16

Ditto

Changed to sizeof(struct in6_addr) for these.

Quoted 7 lines

libsemanage/include/semanage/ibpkey_record.h line 24

Quoted 5 lines
libsemanage/include/semanage/ibpkey_record.h new file +5 -0
+#ifdef DARWIN
+	memcpy(&addr.s6_addr[0], subnet_prefix_bytes, 16);
+#else
+	memcpy(&addr.s6_addr32[0], subnet_prefix_bytes, 16);
+#endif

Another case where you can drop #ifdef DARWIN and just use s6_addr.

Done

#20 lore raw

Re: [PATCH v1 7/9] semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

In reply to Dan Jurgens
Quoted 88 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow in
seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++ libsemanage/include/semanage/ibpkeys_local.h  |  36 +++ libsemanage/include/semanage/ibpkeys_policy.h |  28 ++ libsemanage/include/semanage/semanage.h       |   3 + libsemanage/src/direct_api.c                  |  29 +- libsemanage/src/handle.h                      |  36 ++- libsemanage/src/ibpkey_internal.h             |  52 +++ libsemanage/src/ibpkey_record.c               | 185 +++++++++++ libsemanage/src/ibpkeys_file.c                | 181 +++++++++++ libsemanage/src/ibpkeys_local.c               | 178 ++++++++++ libsemanage/src/ibpkeys_policy.c              |  52 +++ libsemanage/src/ibpkeys_policydb.c            |  62 ++++ libsemanage/src/libsemanage.map               |   1 + libsemanage/src/policy_components.c           |   5 +- libsemanage/src/semanage_store.c              |   1 + libsemanage/src/semanage_store.h              |   1 + libsemanage/src/semanageswig.i                |   3 + libsemanage/src/semanageswig_python.i         |  43 +++ libsemanage/utils/semanage_migrate_store      |   3 +- libsepol/include/sepol/ibpkey_record.h        |  77 +++++ libsepol/include/sepol/ibpkeys.h              |  44 +++ libsepol/include/sepol/sepol.h                |   2 + libsepol/src/ibpkey_internal.h                |  21 ++ libsepol/src/ibpkey_record.c                  | 448
++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263 +++++++++++++++ python/semanage/semanage                      |  60 +++- python/semanage/seobject.py                   | 255 +++++++++++++++

 27 files changed, 2129 insertions(+), 16 deletions(-)

 create mode 100644 libsemanage/include/semanage/ibpkey_record.h create mode 100644 libsemanage/include/semanage/ibpkeys_local.h create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h create mode 100644 libsemanage/src/ibpkey_internal.h create mode 100644 libsemanage/src/ibpkey_record.c create mode 100644 libsemanage/src/ibpkeys_file.c create mode 100644 libsemanage/src/ibpkeys_local.c create mode 100644 libsemanage/src/ibpkeys_policy.c create mode 100644 libsemanage/src/ibpkeys_policydb.c create mode 100644 libsepol/include/sepol/ibpkey_record.h create mode 100644 libsepol/include/sepol/ibpkeys.h create mode 100644 libsepol/src/ibpkey_internal.h create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c

python/semanage/seobject.py +0 -0
index 7a54373..41b0aca 100644
@@ -32,6 +32,7 @@ import socket

 from semanage import *
 PROGNAME = "policycoreutils"
 import sepolicy
+import setools
 from IPy import IP

 try:

python/semanage/seobject.py +0 -0
@@ -1309,6 +1310,260 @@ class portRecords(semanageRecords):

                 rec += ", %s" % p
             print(rec)

Quoted 8 lines

+class ibpkeyRecords(semanageRecords):
+    try:
+        q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy ()), attrs=["ibpkey_type"])
+        valid_types = sorted(str(t) for t in q.results()) +    except RuntimeError:
+        valid_types = []

This causes all semanage commands to fail (without a patched refpolicy to define ibpkey_type).

Traceback (most recent call last):
  File "/usr/sbin/semanage", line 28, in <module>
    import seobject
  File "/usr/lib64/python2.7/site-packages/seobject.py", line 1313, in <module>
    class ibpkeyRecords(semanageRecords):
  File "/usr/lib64/python2.7/site-packages/seobject.py", line 1315, in ibpkeyRecords
    q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy() ), attrs=["ibpkey_type"])
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/typequery.py", line 72, in __init__ super(TypeQuery, self).__init__(policy, **kwargs)
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/query.py", line 39, in __init__ setattr(self, name, kwargs[name])
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/descriptors.py", line 104, in __set__ self.instances[obj] = set(lookup(v) for v in value)
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/descriptors.py", line 104, in <genexpr> self.instances[obj] = set(lookup(v) for v in value)
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/policyrep/__init__.py", line 449, in lookup_typeattr return typeattr.attribute_factory(self.policy, name) File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/policyrep/typeattr.py", line 42, in attribute_factory
    qpol_symbol = _symbol_lookup(qpol_policy, name)
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux- x86_64.egg/setools/policyrep/typeattr.py", line 32, in _symbol_lookup raise exception.InvalidType("{0} is not a valid type/attribute".format(name)) setools.policyrep.exception.InvalidType: ibpkey_type is not a valid type/attribute

#21 lore raw

Re: [PATCH v1 7/9] semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

Quoted 128 lines · Stephen Smalley
Quoted 93 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow in
seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++
 libsemanage/include/semanage/ibpkeys_local.h  |  36 +++
 libsemanage/include/semanage/ibpkeys_policy.h |  28 ++
 libsemanage/include/semanage/semanage.h       |   3 +
 libsemanage/src/direct_api.c                  |  29 +-
 libsemanage/src/handle.h                      |  36 ++-
 libsemanage/src/ibpkey_internal.h             |  52 +++
 libsemanage/src/ibpkey_record.c               | 185 +++++++++++
 libsemanage/src/ibpkeys_file.c                | 181 +++++++++++
 libsemanage/src/ibpkeys_local.c               | 178 ++++++++++
 libsemanage/src/ibpkeys_policy.c              |  52 +++
 libsemanage/src/ibpkeys_policydb.c            |  62 ++++
 libsemanage/src/libsemanage.map               |   1 +
 libsemanage/src/policy_components.c           |   5 +-
 libsemanage/src/semanage_store.c              |   1 +
 libsemanage/src/semanage_store.h              |   1 +
 libsemanage/src/semanageswig.i                |   3 +
 libsemanage/src/semanageswig_python.i         |  43 +++
 libsemanage/utils/semanage_migrate_store      |   3 +-
 libsepol/include/sepol/ibpkey_record.h        |  77 +++++
 libsepol/include/sepol/ibpkeys.h              |  44 +++
 libsepol/include/sepol/sepol.h                |   2 +
 libsepol/src/ibpkey_internal.h                |  21 ++
 libsepol/src/ibpkey_record.c                  | 448
++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263 +++++++++++++++
 python/semanage/semanage                      |  60 +++-
 python/semanage/seobject.py                   | 255 +++++++++++++++
 27 files changed, 2129 insertions(+), 16 deletions(-)
 create mode 100644 libsemanage/include/semanage/ibpkey_record.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_local.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h
 create mode 100644 libsemanage/src/ibpkey_internal.h
 create mode 100644 libsemanage/src/ibpkey_record.c
 create mode 100644 libsemanage/src/ibpkeys_file.c
 create mode 100644 libsemanage/src/ibpkeys_local.c
 create mode 100644 libsemanage/src/ibpkeys_policy.c
 create mode 100644 libsemanage/src/ibpkeys_policydb.c
 create mode 100644 libsepol/include/sepol/ibpkey_record.h
 create mode 100644 libsepol/include/sepol/ibpkeys.h
 create mode 100644 libsepol/src/ibpkey_internal.h
 create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c
python/semanage/seobject.py +4 -0
index 7a54373..41b0aca 100644
@@ -32,6 +32,7 @@ import socket
 from semanage import *
 PROGNAME = "policycoreutils"
 import sepolicy
+import setools
 from IPy import IP
 
 try:
@@ -1309,6 +1310,260 @@ class portRecords(semanageRecords):
                 rec += ", %s" % p
             print(rec)
 
+class ibpkeyRecords(semanageRecords):
+    try:
+        q =

setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy ()), attrs=["ibpkey_type"])

python/semanage/seobject.py class portRecords(semanageRecords): · line 1318

Quoted 3 lines
python/semanage/seobject.py +3 -0
+        valid_types = sorted(str(t) for t in q.results())
+    except RuntimeError:
+        valid_types = []

This causes all semanage commands to fail (without a patched refpolicy to define ibpkey_type).

Traceback (most recent call last):
File "/usr/sbin/semanage", line 28, in <module>
import seobject
File "/usr/lib64/python2.7/site-packages/seobject.py", line 1313, in
<module>
class ibpkeyRecords(semanageRecords):
File "/usr/lib64/python2.7/site-packages/seobject.py", line 1315, in
ibpkeyRecords

    q =

setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy() ), attrs=["ibpkey_type"])
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/typequery.py", line 72, in __init__

    super(TypeQuery, self).__init__(policy, **kwargs)

File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/query.py", line 39, in __init__
setattr(self, name, kwargs[name])
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/descriptors.py", line 104, in __set__
self.instances[obj] = set(lookup(v) for v in value)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/descriptors.py", line 104, in <genexpr>
self.instances[obj] = set(lookup(v) for v in value)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/policyrep/__init__.py", line 449, in lookup_typeattr
return typeattr.attribute_factory(self.policy, name)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/policyrep/typeattr.py", line 42, in

Quoted 8 lines

attribute_factory
qpol_symbol = _symbol_lookup(qpol_policy, name)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-linux-
x86_64.egg/setools/policyrep/typeattr.py", line 32, in _symbol_lookup
raise exception.InvalidType("{0} is not a valid
type/attribute".format(name)) setools.policyrep.exception.InvalidType: ibpkey_type is not a valid type/attribute

Yes, it's the same with all the others too. They require attribute synchronization between the tool and the policy. I'm preparing refpolicy patches right now.

#22 lore raw

Re: [PATCH v1 7/9] semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

Quoted 158 lines · Daniel Jurgens
Quoted 148 lines · Stephen Smalley
Quoted 94 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local
storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow
in
seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++ libsemanage/include/semanage/ibpkeys_local.h  |  36 +++ libsemanage/include/semanage/ibpkeys_policy.h |  28 ++ libsemanage/include/semanage/semanage.h       |   3 + libsemanage/src/direct_api.c                  |  29 +- libsemanage/src/handle.h                      |  36 ++- libsemanage/src/ibpkey_internal.h             |  52 +++ libsemanage/src/ibpkey_record.c               | 185 +++++++++++ libsemanage/src/ibpkeys_file.c                | 181 +++++++++++ libsemanage/src/ibpkeys_local.c               | 178 ++++++++++ libsemanage/src/ibpkeys_policy.c              |  52 +++ libsemanage/src/ibpkeys_policydb.c            |  62 ++++ libsemanage/src/libsemanage.map               |   1 + libsemanage/src/policy_components.c           |   5 +- libsemanage/src/semanage_store.c              |   1 + libsemanage/src/semanage_store.h              |   1 + libsemanage/src/semanageswig.i                |   3 + libsemanage/src/semanageswig_python.i         |  43 +++ libsemanage/utils/semanage_migrate_store      |   3 +- libsepol/include/sepol/ibpkey_record.h        |  77 +++++ libsepol/include/sepol/ibpkeys.h              |  44 +++ libsepol/include/sepol/sepol.h                |   2 + libsepol/src/ibpkey_internal.h                |  21 ++ libsepol/src/ibpkey_record.c                  | 448
++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263
+++++++++++++++
 python/semanage/semanage                      |  60 +++- python/semanage/seobject.py                   | 255
+++++++++++++++

 27 files changed, 2129 insertions(+), 16 deletions(-)

 create mode 100644 libsemanage/include/semanage/ibpkey_record.h create mode 100644 libsemanage/include/semanage/ibpkeys_local.h create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h create mode 100644 libsemanage/src/ibpkey_internal.h create mode 100644 libsemanage/src/ibpkey_record.c create mode 100644 libsemanage/src/ibpkeys_file.c create mode 100644 libsemanage/src/ibpkeys_local.c create mode 100644 libsemanage/src/ibpkeys_policy.c create mode 100644 libsemanage/src/ibpkeys_policydb.c create mode 100644 libsepol/include/sepol/ibpkey_record.h create mode 100644 libsepol/include/sepol/ibpkeys.h create mode 100644 libsepol/src/ibpkey_internal.h create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c

python/semanage/seobject.py +0 -0
index 7a54373..41b0aca 100644
@@ -32,6 +32,7 @@ import socket

 from semanage import *
 PROGNAME = "policycoreutils"
 import sepolicy
+import setools
 from IPy import IP

 try:

python/semanage/seobject.py +0 -0
@@ -1309,6 +1310,260 @@ class portRecords(semanageRecords):

                 rec += ", %s" % p
             print(rec)

+class ibpkeyRecords(semanageRecords):

Quoted 8 lines

+    try:
+        q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_po licy
()), attrs=["ibpkey_type"])
+        valid_types = sorted(str(t) for t in q.results()) +    except RuntimeError:
+        valid_types = []

This causes all semanage commands to fail (without a patched refpolicy
to define ibpkey_type).

Traceback (most recent call last):
  File "/usr/sbin/semanage", line 28, in <module>
    import seobject
  File "/usr/lib64/python2.7/site-packages/seobject.py", line 1313, in
<module>
    class ibpkeyRecords(semanageRecords):
  File "/usr/lib64/python2.7/site-packages/seobject.py", line 1315, in
ibpkeyRecords
    q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_poli cy()
), attrs=["ibpkey_type"])
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/typequery.py", line 72, in __init__ super(TypeQuery, self).__init__(policy, **kwargs) File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/query.py", line 39, in __init__ setattr(self, name, kwargs[name])
  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/descriptors.py", line 104, in __set__ self.instances[obj] = set(lookup(v) for v in value) File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/descriptors.py", line 104, in <genexpr> self.instances[obj] = set(lookup(v) for v in value) File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/policyrep/__init__.py", line 449, in lookup_typeattr
    return typeattr.attribute_factory(self.policy, name) File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/policyrep/typeattr.py", line 42, in attribute_factory
    qpol_symbol = _symbol_lookup(qpol_policy, name)

Quoted 8 lines

  File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7- linux-
x86_64.egg/setools/policyrep/typeattr.py", line 32, in _symbol_lookup
    raise exception.InvalidType("{0} is not a valid type/attribute".format(name)) setools.policyrep.exception.InvalidType: ibpkey_type is not a valid type/attribute

Quoted 3 lines

Yes, it's the same with all the others too.  They require attribute synchronization between the tool and the policy.  I'm preparing refpolicy patches right now.

I think we just need to handle that exception cleanly. I agree that it is wrong that we don't do this for the other attributes, but those are long-established in refpolicy and therefore haven't shown up before (also, the particular exception has changed with the migration to setools4, so we likely just never adapted the handlers). We can't have a newer version of semanage break users with older policies.

#23 lore raw

Re: [PATCH v1 7/9] semanage: Update semanage to allow runtime labeling of Infiniband Pkeys

Quoted 160 lines · Stephen Smalley
Quoted 156 lines · Daniel Jurgens
Quoted 147 lines · Stephen Smalley
Quoted 99 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with pkey records. Add local
storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

---
v1:
Fixed semanage_pkey_exists -> semanage_ibpkey_exists in delete flow
in
seobject.py

Stephen Smalley:
- Subnet prefix can't vary in size always 16 bytes, remove size field.
- Removed extraneous change in libsepol/VERSION
- Removed ifdef DARWIN s6_addr/32 blocks in favor of s6_addr.
- Got rid of magic constant for subnet prefix size.

Jason Zaman:
- Use SETools directly to query types in seobject.py.

---
 libsemanage/include/semanage/ibpkey_record.h  |  76 +++++
 libsemanage/include/semanage/ibpkeys_local.h  |  36 +++
 libsemanage/include/semanage/ibpkeys_policy.h |  28 ++
 libsemanage/include/semanage/semanage.h       |   3 +
 libsemanage/src/direct_api.c                  |  29 +-
 libsemanage/src/handle.h                      |  36 ++-
 libsemanage/src/ibpkey_internal.h             |  52 +++
 libsemanage/src/ibpkey_record.c               | 185 +++++++++++
 libsemanage/src/ibpkeys_file.c                | 181 +++++++++++
 libsemanage/src/ibpkeys_local.c               | 178 ++++++++++
 libsemanage/src/ibpkeys_policy.c              |  52 +++
 libsemanage/src/ibpkeys_policydb.c            |  62 ++++
 libsemanage/src/libsemanage.map               |   1 +
 libsemanage/src/policy_components.c           |   5 +-
 libsemanage/src/semanage_store.c              |   1 +
 libsemanage/src/semanage_store.h              |   1 +
 libsemanage/src/semanageswig.i                |   3 +
 libsemanage/src/semanageswig_python.i         |  43 +++
 libsemanage/utils/semanage_migrate_store      |   3 +-
 libsepol/include/sepol/ibpkey_record.h        |  77 +++++
 libsepol/include/sepol/ibpkeys.h              |  44 +++
 libsepol/include/sepol/sepol.h                |   2 +
 libsepol/src/ibpkey_internal.h                |  21 ++
 libsepol/src/ibpkey_record.c                  | 448
++++++++++++++++++++++++++
 libsepol/src/ibpkeys.c                        | 263
+++++++++++++++
 python/semanage/semanage                      |  60 +++-
 python/semanage/seobject.py                   | 255
+++++++++++++++
 27 files changed, 2129 insertions(+), 16 deletions(-)
 create mode 100644 libsemanage/include/semanage/ibpkey_record.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_local.h
 create mode 100644 libsemanage/include/semanage/ibpkeys_policy.h
 create mode 100644 libsemanage/src/ibpkey_internal.h
 create mode 100644 libsemanage/src/ibpkey_record.c
 create mode 100644 libsemanage/src/ibpkeys_file.c
 create mode 100644 libsemanage/src/ibpkeys_local.c
 create mode 100644 libsemanage/src/ibpkeys_policy.c
 create mode 100644 libsemanage/src/ibpkeys_policydb.c
 create mode 100644 libsepol/include/sepol/ibpkey_record.h
 create mode 100644 libsepol/include/sepol/ibpkeys.h
 create mode 100644 libsepol/src/ibpkey_internal.h
 create mode 100644 libsepol/src/ibpkey_record.c
 create mode 100644 libsepol/src/ibpkeys.c
python/semanage/seobject.py +4 -0
index 7a54373..41b0aca 100644
@@ -32,6 +32,7 @@ import socket
 from semanage import *
 PROGNAME = "policycoreutils"
 import sepolicy
+import setools
 from IPy import IP
 
 try:
@@ -1309,6 +1310,260 @@ class portRecords(semanageRecords):
                 rec += ", %s" % p
             print(rec)
 
+class ibpkeyRecords(semanageRecords):
+    try:
+        q =

setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_po licy
()), attrs=["ibpkey_type"])

python/semanage/seobject.py class portRecords(semanageRecords): · line 1318

Quoted 3 lines
python/semanage/seobject.py +3 -0
+        valid_types = sorted(str(t) for t in q.results())
+    except RuntimeError:
+        valid_types = []

This causes all semanage commands to fail (without a patched refpolicy
to define ibpkey_type).

Traceback (most recent call last):
File "/usr/sbin/semanage", line 28, in <module>
import seobject
File "/usr/lib64/python2.7/site-packages/seobject.py", line 1313,
in
<module>
class ibpkeyRecords(semanageRecords):
File "/usr/lib64/python2.7/site-packages/seobject.py", line 1315,
in
ibpkeyRecords

    q =

setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_poli cy()
), attrs=["ibpkey_type"])
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/typequery.py", line 72, in __init__

    super(TypeQuery, self).__init__(policy, **kwargs)

File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/query.py", line 39, in __init__
setattr(self, name, kwargs[name])
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/descriptors.py", line 104, in __set__
self.instances[obj] = set(lookup(v) for v in value)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/descriptors.py", line 104, in <genexpr>
self.instances[obj] = set(lookup(v) for v in value)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/policyrep/__init__.py", line 449, in lookup_typeattr
return typeattr.attribute_factory(self.policy, name)
File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/policyrep/typeattr.py", line 42, in attribute_factory
qpol_symbol = _symbol_lookup(qpol_policy, name)

Quoted 8 lines

File "/usr/lib64/python2.7/site-packages/setools-4.0.1-py2.7-
linux-
x86_64.egg/setools/policyrep/typeattr.py", line 32, in _symbol_lookup
raise exception.InvalidType("{0} is not a valid
type/attribute".format(name)) setools.policyrep.exception.InvalidType: ibpkey_type is not a valid type/attribute

Quoted 3 lines

Yes, it's the same with all the others too. They require attribute synchronization between the tool and the policy. I'm preparing refpolicy patches right now.

Quoted 6 lines

I think we just need to handle that exception cleanly. I agree that it is wrong that we don't do this for the other attributes, but those are long-established in refpolicy and therefore haven't shown up before (also, the particular exception has changed with the migration to setools4, so we likely just never adapted the handlers). We can't have a newer version of semanage break users with older policies.

Sure, that makes sense. I'll address this and your other comments today this week and post a v2.

#24 lore raw

PATCH 8/9 semanage: Update semanage to allow runtime labeling of ibendports

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with ibendport records. Add local storage for new and modified ibendport records in ibendports.local. Update semanage to parse the ibendport command options to add, modify, and delete them.

---
v1:
Jason Zaman:
- Use SETools directly to query types in seobject.py

---
 libsemanage/include/semanage/ibendport_record.h  |  62 +++++
 libsemanage/include/semanage/ibendports_local.h  |  36 +++
 libsemanage/include/semanage/ibendports_policy.h |  28 +++
 libsemanage/include/semanage/semanage.h          |   3 +
 libsemanage/src/direct_api.c                     |  40 ++-
 libsemanage/src/handle.h                         |  38 ++-
 libsemanage/src/ibendport_internal.h             |  48 ++++
 libsemanage/src/ibendport_record.c               | 154 ++++++++++++
 libsemanage/src/ibendports_file.c                | 157 ++++++++++++
 libsemanage/src/ibendports_local.c               | 153 ++++++++++++
 libsemanage/src/ibendports_policy.c              |  55 +++++
 libsemanage/src/ibendports_policydb.c            |  62 +++++
 libsemanage/src/libsemanage.map                  |   1 +
 libsemanage/src/policy_components.c              |   4 +
 libsemanage/src/semanage_store.c                 |   1 +
 libsemanage/src/semanage_store.h                 |   1 +
 libsemanage/src/semanageswig.i                   |   3 +
 libsemanage/src/semanageswig_python.i            |  43 ++++
 libsemanage/utils/semanage_migrate_store         |   3 +-
 libsepol/include/sepol/ibendport_record.h        |  68 ++++++
 libsepol/include/sepol/ibendports.h              |  45 ++++
 libsepol/include/sepol/sepol.h                   |   2 +
 libsepol/src/ibendport_internal.h                |  18 ++
 libsepol/src/ibendport_record.c                  | 298 +++++++++++++++++++++++
 libsepol/src/ibendports.c                        | 255 +++++++++++++++++++
 python/semanage/semanage                         |  58 ++++-
 python/semanage/seobject.py                      | 239 ++++++++++++++++++
 27 files changed, 1854 insertions(+), 21 deletions(-)
 create mode 100644 libsemanage/include/semanage/ibendport_record.h
 create mode 100644 libsemanage/include/semanage/ibendports_local.h
 create mode 100644 libsemanage/include/semanage/ibendports_policy.h
 create mode 100644 libsemanage/src/ibendport_internal.h
 create mode 100644 libsemanage/src/ibendport_record.c
 create mode 100644 libsemanage/src/ibendports_file.c
 create mode 100644 libsemanage/src/ibendports_local.c
 create mode 100644 libsemanage/src/ibendports_policy.c
 create mode 100644 libsemanage/src/ibendports_policydb.c
 create mode 100644 libsepol/include/sepol/ibendport_record.h
 create mode 100644 libsepol/include/sepol/ibendports.h
 create mode 100644 libsepol/src/ibendport_internal.h
 create mode 100644 libsepol/src/ibendport_record.c
 create mode 100644 libsepol/src/ibendports.c
libsemanage/include/semanage/ibendport_record.h new file +62 -0
new file mode 100644
index 0000000..153eea0
@@ -0,0 +1,62 @@
+/*Copyright (C) 2005 Red Hat, Inc. */
+
+#ifndef _SEMANAGE_IBENDPORT_RECORD_H_
+#define _SEMANAGE_IBENDPORT_RECORD_H_
+
+#include <semanage/context_record.h>
+#include <semanage/handle.h>
+#include <stddef.h>
+
+#ifndef _SEMANAGE_IBENDPORT_DEFINED_
+struct semanage_ibendport;
+struct semanage_ibendport_key;
+typedef struct semanage_ibendport semanage_ibendport_t;
+typedef struct semanage_ibendport_key semanage_ibendport_key_t;
+#define _SEMANAGE_IBENDPORT_DEFINED_
+#endif
+
+extern int semanage_ibendport_compare(const semanage_ibendport_t *ibendport,
+				      const semanage_ibendport_key_t *key);
+
+extern int semanage_ibendport_compare2(const semanage_ibendport_t *ibendport,
+				       const semanage_ibendport_t *ibendport2);
+
+extern int semanage_ibendport_key_create(semanage_handle_t *handle,
+					 const char *ibdev_name,
+					 int port,
+					 semanage_ibendport_key_t **key_ptr);
+
+extern int semanage_ibendport_key_extract(semanage_handle_t *handle,
+					  const semanage_ibendport_t *ibendport,
+					  semanage_ibendport_key_t **key_ptr);
+
+extern void semanage_ibendport_key_free(semanage_ibendport_key_t *key);
+
+extern int semanage_ibendport_get_ibdev_name(semanage_handle_t *handle,
+					     const semanage_ibendport_t *ibendport,
+					     char **ibdev_name_ptr);
+
+extern int semanage_ibendport_set_ibdev_name(semanage_handle_t *handle,
+					     semanage_ibendport_t *ibendport,
+					     const char *ibdev_name);
+
+extern int semanage_ibendport_get_port(const semanage_ibendport_t *ibendport);
+
+extern void semanage_ibendport_set_port(semanage_ibendport_t *ibendport, int port);
+
+extern semanage_context_t *semanage_ibendport_get_con(const semanage_ibendport_t *ibendport);
+
+extern int semanage_ibendport_set_con(semanage_handle_t *handle,
+				      semanage_ibendport_t *ibendport,
+				      semanage_context_t *con);
+
+extern int semanage_ibendport_create(semanage_handle_t *handle,
+				     semanage_ibendport_t **ibendport_ptr);
+
+extern int semanage_ibendport_clone(semanage_handle_t *handle,
+				    const semanage_ibendport_t *ibendport,
+				    semanage_ibendport_t **ibendport_ptr);
+
+extern void semanage_ibendport_free(semanage_ibendport_t *ibendport);
+
+#endif
libsemanage/include/semanage/ibendports_local.h new file +36 -0
new file mode 100644
index 0000000..641dd35
@@ -0,0 +1,36 @@
+/* Copyright (C) 2017 Mellanox Technologies Inc */
+
+#ifndef _SEMANAGE_IBENDPORTS_LOCAL_H_
+#define _SEMANAGE_IBENDPORTS_LOCAL_H_
+
+#include <semanage/ibendport_record.h>
+#include <semanage/handle.h>
+
+extern int semanage_ibendport_modify_local(semanage_handle_t *handle,
+					   const semanage_ibendport_key_t *key,
+					   const semanage_ibendport_t *data);
+
+extern int semanage_ibendport_del_local(semanage_handle_t *handle,
+					const semanage_ibendport_key_t *key);
+
+extern int semanage_ibendport_query_local(semanage_handle_t *handle,
+					  const semanage_ibendport_key_t *key,
+					  semanage_ibendport_t **response);
+
+extern int semanage_ibendport_exists_local(semanage_handle_t *handle,
+					   const semanage_ibendport_key_t *key,
+					   int *response);
+
+extern int semanage_ibendport_count_local(semanage_handle_t *handle,
+					  unsigned int *response);
+
+extern int semanage_ibendport_iterate_local(semanage_handle_t *handle,
+					    int (*handler)(const semanage_ibendport_t *record,
+							   void *varg),
+					    void *handler_arg);
+
+extern int semanage_ibendport_list_local(semanage_handle_t *handle,
+					 semanage_ibendport_t ***records,
+					 unsigned int *count);
+
+#endif
libsemanage/include/semanage/ibendports_policy.h new file +28 -0
new file mode 100644
index 0000000..3fc1976
@@ -0,0 +1,28 @@
+/* Copyright (C) 2017 Mellanox Techonologies Inc */
+
+#ifndef _SEMANAGE_IBENDPORTS_POLICY_H_
+#define _SEMANAGE_IBENDPORTS_POLICY_H_
+
+#include <semanage/handle.h>
+#include <semanage/ibendport_record.h>
+
+extern int semanage_ibendport_query(semanage_handle_t *handle,
+				    const semanage_ibendport_key_t *key,
+				    semanage_ibendport_t **response);
+
+extern int semanage_ibendport_exists(semanage_handle_t *handle,
+				     const semanage_ibendport_key_t *key, int *response);
+
+extern int semanage_ibendport_count(semanage_handle_t *handle,
+				    unsigned int *response);
+
+extern int semanage_ibendport_iterate(semanage_handle_t *handle,
+				      int (*handler)(const semanage_ibendport_t *record,
+						     void *varg),
+				      void *handler_arg);
+
+extern int semanage_ibendport_list(semanage_handle_t *handle,
+				   semanage_ibendport_t ***records,
+				   unsigned int *count);
+
+#endif
libsemanage/include/semanage/semanage.h +3 -0
index cebf3f4..0489014 100644
@@ -34,6 +34,7 @@
 #include <semanage/iface_record.h>
 #include <semanage/port_record.h>
 #include <semanage/ibpkey_record.h>
+#include <semanage/ibendport_record.h>
 #include <semanage/node_record.h>
 
 /* Dbase */
@@ -49,6 +50,8 @@
 #include <semanage/ports_local.h>
 #include <semanage/ports_policy.h>
 #include <semanage/ibpkeys_local.h>
+#include <semanage/ibendports_local.h>
+#include <semanage/ibendports_policy.h>
 #include <semanage/ibpkeys_policy.h>
 #include <semanage/interfaces_local.h>
 #include <semanage/interfaces_policy.h>
libsemanage/src/direct_api.c +34 -6
index 436e334..68c1868 100644
@@ -41,6 +41,7 @@
 #include "seuser_internal.h"
 #include "port_internal.h"
 #include "ibpkey_internal.h"
+#include "ibendport_internal.h"
 #include "iface_internal.h"
 #include "boolean_internal.h"
 #include "fcontext_internal.h"
@@ -226,11 +227,19 @@ int semanage_direct_connect(semanage_handle_t * sh)
 		goto err;
 
 	if (ibpkey_file_dbase_init(sh,
-				 semanage_path(SEMANAGE_ACTIVE,
-					       SEMANAGE_IBPKEYS_LOCAL),
-				 semanage_path(SEMANAGE_TMP,
-					       SEMANAGE_IBPKEYS_LOCAL),
-				 semanage_ibpkey_dbase_local(sh)) < 0)
+				   semanage_path(SEMANAGE_ACTIVE,
+						 SEMANAGE_IBPKEYS_LOCAL),
+				   semanage_path(SEMANAGE_TMP,
+						 SEMANAGE_IBPKEYS_LOCAL),
+				   semanage_ibpkey_dbase_local(sh)) < 0)
+		goto err;
+
+	if (ibendport_file_dbase_init(sh,
+				      semanage_path(SEMANAGE_ACTIVE,
+						    SEMANAGE_IBENDPORTS_LOCAL),
+				      semanage_path(SEMANAGE_TMP,
+						    SEMANAGE_IBENDPORTS_LOCAL),
+				      semanage_ibendport_dbase_local(sh)) < 0)
 		goto err;
 
 	/* Object databases: local modifications + policy */
@@ -260,6 +269,9 @@ int semanage_direct_connect(semanage_handle_t * sh)
 	if (ibpkey_policydb_dbase_init(sh, semanage_ibpkey_dbase_policy(sh)) < 0)
 		goto err;
 
+	if (ibendport_policydb_dbase_init(sh, semanage_ibendport_dbase_policy(sh)) < 0)
+		goto err;
+
 	if (iface_policydb_dbase_init(sh, semanage_iface_dbase_policy(sh)) < 0)
 		goto err;
 
@@ -333,6 +345,7 @@ static int semanage_direct_disconnect(semanage_handle_t * sh)
 	user_join_dbase_release(semanage_user_dbase_local(sh));
 	port_file_dbase_release(semanage_port_dbase_local(sh));
 	ibpkey_file_dbase_release(semanage_ibpkey_dbase_local(sh));
+	ibendport_file_dbase_release(semanage_ibendport_dbase_local(sh));
 	iface_file_dbase_release(semanage_iface_dbase_local(sh));
 	bool_file_dbase_release(semanage_bool_dbase_local(sh));
 	fcontext_file_dbase_release(semanage_fcontext_dbase_local(sh));
@@ -345,6 +358,7 @@ static int semanage_direct_disconnect(semanage_handle_t * sh)
 	user_join_dbase_release(semanage_user_dbase_policy(sh));
 	port_policydb_dbase_release(semanage_port_dbase_policy(sh));
 	ibpkey_policydb_dbase_release(semanage_ibpkey_dbase_policy(sh));
+	ibendport_policydb_dbase_release(semanage_ibendport_dbase_policy(sh));
 	iface_policydb_dbase_release(semanage_iface_dbase_policy(sh));
 	bool_policydb_dbase_release(semanage_bool_dbase_policy(sh));
 	fcontext_file_dbase_release(semanage_fcontext_dbase_policy(sh));
@@ -1158,7 +1172,8 @@ static int semanage_direct_commit(semanage_handle_t * sh)
 
 	int do_rebuild, do_write_kernel, do_install;
 	int fcontexts_modified, ports_modified, seusers_modified,
-		disable_dontaudit, preserve_tunables, ibpkeys_modified;
+		disable_dontaudit, preserve_tunables, ibpkeys_modified,
+		ibendports_modified;
 	dbase_config_t *users = semanage_user_dbase_local(sh);
 	dbase_config_t *users_base = semanage_user_base_dbase_local(sh);
 	dbase_config_t *pusers_base = semanage_user_base_dbase_policy(sh);
@@ -1167,6 +1182,8 @@ static int semanage_direct_commit(semanage_handle_t * sh)
 	dbase_config_t *pports = semanage_port_dbase_policy(sh);
 	dbase_config_t *ibpkeys = semanage_ibpkey_dbase_local(sh);
 	dbase_config_t *pibpkeys = semanage_ibpkey_dbase_policy(sh);
+	dbase_config_t *ibendports = semanage_ibendport_dbase_local(sh);
+	dbase_config_t *pibendports = semanage_ibendport_dbase_policy(sh);
 	dbase_config_t *bools = semanage_bool_dbase_local(sh);
 	dbase_config_t *pbools = semanage_bool_dbase_policy(sh);
 	dbase_config_t *ifaces = semanage_iface_dbase_local(sh);
@@ -1181,6 +1198,7 @@ static int semanage_direct_commit(semanage_handle_t * sh)
 	/* Modified flags that we need to use more than once. */
 	ports_modified = ports->dtable->is_modified(ports->dbase);
 	ibpkeys_modified = ibpkeys->dtable->is_modified(ibpkeys->dbase);
+	ibendports_modified = ibendports->dtable->is_modified(ibendports->dbase);
 	seusers_modified = seusers->dtable->is_modified(seusers->dbase);
 	fcontexts_modified = fcontexts->dtable->is_modified(fcontexts->dbase);
 
@@ -1303,6 +1321,7 @@ rebuild:
 	 * will be modified.
 	 */
 	do_write_kernel = do_rebuild | ports_modified | ibpkeys_modified |
+		ibendports_modified |
 		bools->dtable->is_modified(bools->dbase) |
 		ifaces->dtable->is_modified(ifaces->dbase) |
 		nodes->dtable->is_modified(nodes->dbase) |
@@ -1449,6 +1468,7 @@ rebuild:
 	dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pports->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pibpkeys->dbase, out);
+	dbase_policydb_attach((dbase_policydb_t *) pibendports->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pifaces->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pbools->dbase, out);
 	dbase_policydb_attach((dbase_policydb_t *) pnodes->dbase, out);
@@ -1503,6 +1523,13 @@ rebuild:
 		if (retval < 0)
 			goto cleanup;
 	}
+
+	/* Validate local ibendports */
+	if (do_rebuild || ibendports_modified) {
+		retval = semanage_ibendport_validate_local(sh);
+		if (retval < 0)
+			goto cleanup;
+	}
 	/* ================== Write non-policydb components ========= */
 
 	/* Commit changes to components */
@@ -1583,6 +1610,7 @@ cleanup:
 	dbase_policydb_detach((dbase_policydb_t *) pusers_base->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pports->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pibpkeys->dbase);
+	dbase_policydb_detach((dbase_policydb_t *) pibendports->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pifaces->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pnodes->dbase);
 	dbase_policydb_detach((dbase_policydb_t *) pbools->dbase);
libsemanage/src/handle.h +26 -12
index 306727a..889871d 100644
@@ -79,7 +79,7 @@ struct semanage_handle {
 	struct semanage_policy_table *funcs;
 
 	/* Object databases */
-#define DBASE_COUNT      21
+#define DBASE_COUNT      23
 
 /* Local modifications */
 #define DBASE_LOCAL_USERS_BASE  0
@@ -92,21 +92,23 @@ struct semanage_handle {
 #define DBASE_LOCAL_SEUSERS     7
 #define DBASE_LOCAL_NODES       8
 #define DBASE_LOCAL_IBPKEYS     9
+#define DBASE_LOCAL_IBENDPORTS  10
 
 /* Policy + Local modifications */
-#define DBASE_POLICY_USERS_BASE  10
-#define DBASE_POLICY_USERS_EXTRA 11
-#define DBASE_POLICY_USERS       12
-#define DBASE_POLICY_PORTS       13
-#define DBASE_POLICY_INTERFACES  14
-#define DBASE_POLICY_BOOLEANS    15
-#define DBASE_POLICY_FCONTEXTS   16
-#define DBASE_POLICY_SEUSERS     17
-#define DBASE_POLICY_NODES       18
-#define DBASE_POLICY_IBPKEYS     19
+#define DBASE_POLICY_USERS_BASE  11
+#define DBASE_POLICY_USERS_EXTRA 12
+#define DBASE_POLICY_USERS       13
+#define DBASE_POLICY_PORTS       14
+#define DBASE_POLICY_INTERFACES  15
+#define DBASE_POLICY_BOOLEANS    16
+#define DBASE_POLICY_FCONTEXTS   17
+#define DBASE_POLICY_SEUSERS     18
+#define DBASE_POLICY_NODES       19
+#define DBASE_POLICY_IBPKEYS     20
+#define DBASE_POLICY_IBENDPORTS  21
 
 /* Active kernel policy */
-#define DBASE_ACTIVE_BOOLEANS    20
+#define DBASE_ACTIVE_BOOLEANS    22
 	dbase_config_t dbase[DBASE_COUNT];
 };
 
@@ -142,6 +144,12 @@ static inline
 }
 
 static inline
+    dbase_config_t * semanage_ibendport_dbase_local(semanage_handle_t * handle)
+{
+	return &handle->dbase[DBASE_LOCAL_IBENDPORTS];
+}
+
+static inline
     dbase_config_t * semanage_iface_dbase_local(semanage_handle_t * handle)
 {
 	return &handle->dbase[DBASE_LOCAL_INTERFACES];
@@ -204,6 +212,12 @@ static inline
 }
 
 static inline
+    dbase_config_t * semanage_ibendport_dbase_policy(semanage_handle_t * handle)
+{
+	return &handle->dbase[DBASE_POLICY_IBENDPORTS];
+}
+
+static inline
     dbase_config_t * semanage_iface_dbase_policy(semanage_handle_t * handle)
 {
 	return &handle->dbase[DBASE_POLICY_INTERFACES];
libsemanage/src/ibendport_internal.h new file +48 -0

48 lines not on this page · raw message

libsemanage/src/ibendport_record.c new file +154 -0

154 lines not on this page · raw message

libsemanage/src/ibendports_file.c new file +157 -0

157 lines not on this page · raw message

libsemanage/src/ibendports_local.c new file +153 -0

153 lines not on this page · raw message

libsemanage/src/ibendports_policy.c new file +55 -0

55 lines not on this page · raw message

libsemanage/src/ibendports_policydb.c new file +62 -0

62 lines not on this page · raw message

libsemanage/src/libsemanage.map +1 -0
index 041b1ce..0203669 100644
@@ -19,6 +19,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
 	  semanage_iface_*; semanage_port_*; semanage_context_*;
 	  semanage_ibpkey_*;
+	  semanage_ibendport_*;
 	  semanage_node_*;
 	  semanage_fcontext_*; semanage_access_check; semanage_set_create_store;
 	  semanage_is_connected; semanage_get_disable_dontaudit; semanage_set_disable_dontaudit;
libsemanage/src/policy_components.c +4 -0
index 136c5a7..896ac51 100644
@@ -140,6 +140,9 @@ int semanage_base_merge_components(semanage_handle_t * handle)
 
 		{semanage_ibpkey_dbase_local(handle),
 		 semanage_ibpkey_dbase_policy(handle), MODE_MODIFY},
+
+		{semanage_ibendport_dbase_local(handle),
+		 semanage_ibendport_dbase_policy(handle), MODE_MODIFY},
 	};
 	const unsigned int CCOUNT = sizeof(components) / sizeof(components[0]);
 
@@ -221,6 +224,7 @@ int semanage_commit_components(semanage_handle_t * handle)
 		semanage_bool_dbase_active(handle),
 		semanage_node_dbase_local(handle),
 		semanage_ibpkey_dbase_local(handle),
+		semanage_ibendport_dbase_local(handle),
 	};
 	const int CCOUNT = sizeof(components) / sizeof(components[0]);
 
libsemanage/src/semanage_store.c +1 -0
index f61f3b2..5642772 100644
@@ -100,6 +100,7 @@ static const char *semanage_sandbox_paths[SEMANAGE_STORE_NUM_PATHS] = {
 	"/file_contexts.template",
 	"/commit_num",
 	"/pkeys.local",
+	"/ibendports.local",
 	"/ports.local",
 	"/interfaces.local",
 	"/nodes.local",
libsemanage/src/semanage_store.h +1 -0
index c7bcf44..fcaa505 100644
@@ -45,6 +45,7 @@ enum semanage_sandbox_defs {
 	SEMANAGE_FC_TMPL,
 	SEMANAGE_COMMIT_NUM_FILE,
 	SEMANAGE_IBPKEYS_LOCAL,
+	SEMANAGE_IBENDPORTS_LOCAL,
 	SEMANAGE_PORTS_LOCAL,
 	SEMANAGE_INTERFACES_LOCAL,
 	SEMANAGE_NODES_LOCAL,
libsemanage/src/semanageswig.i +3 -0
index d3ca795..ebf39cf 100644
@@ -42,6 +42,9 @@
 %include "../include/semanage/ibpkey_record.h"
 %include "../include/semanage/ibpkeys_local.h"
 %include "../include/semanage/ibpkeys_policy.h"
+%include "../include/semanage/ibendport_record.h"
+%include "../include/semanage/ibendports_local.h"
+%include "../include/semanage/ibendports_policy.h"
 %include "../include/semanage/fcontext_record.h"
 %include "../include/semanage/fcontexts_local.h"
 %include "../include/semanage/fcontexts_policy.h"
libsemanage/src/semanageswig_python.i +43 -0

49 lines not on this page · raw message

libsemanage/utils/semanage_migrate_store +2 -1
index 325de47..9a9fac2 100755
@@ -254,7 +254,8 @@ if __name__ == "__main__":
 		"policy.kern",
 		"file_contexts",
 		"homedir_template",
-                "pkeys.local"]
+                "pkeys.local",
+                "ibendports.local"]
 
 
 	create_dir(newroot_path(), 0o755)
libsepol/include/sepol/ibendport_record.h new file +68 -0

68 lines not on this page · raw message

libsepol/include/sepol/ibendports.h new file +45 -0

45 lines not on this page · raw message

libsepol/include/sepol/sepol.h +2 -0
index 540f01d..540609a 100644
@@ -12,6 +12,7 @@ extern "C" {
 #include <sepol/context_record.h>
 #include <sepol/iface_record.h>
 #include <sepol/ibpkey_record.h>
+#include <sepol/ibendport_record.h>
 #include <sepol/port_record.h>
 #include <sepol/boolean_record.h>
 #include <sepol/node_record.h>
@@ -19,6 +20,7 @@ extern "C" {
 #include <sepol/booleans.h>
 #include <sepol/interfaces.h>
 #include <sepol/ibpkeys.h>
+#include <sepol/ibendports.h>
 #include <sepol/ports.h>
 #include <sepol/nodes.h>
 #include <sepol/users.h>
libsepol/src/ibendport_internal.h new file +18 -0
new file mode 100644
index 0000000..ed8f9b4
@@ -0,0 +1,18 @@
+#ifndef _SEPOL_IBENDPORT_INTERNAL_H_
+#define _SEPOL_IBENDPORT_INTERNAL_H_
+
+#include <sepol/ibendport_record.h>
+#include <sepol/ibendports.h>
+#include "dso.h"
+
+hidden_proto(sepol_ibendport_create)
+hidden_proto(sepol_ibendport_free)
+hidden_proto(sepol_ibendport_get_con)
+hidden_proto(sepol_ibendport_get_port)
+hidden_proto(sepol_ibendport_key_create)
+hidden_proto(sepol_ibendport_key_unpack)
+hidden_proto(sepol_ibendport_set_con)
+hidden_proto(sepol_ibendport_set_port)
+hidden_proto(sepol_ibendport_get_ibdev_name)
+hidden_proto(sepol_ibendport_set_ibdev_name)
+#endif
libsepol/src/ibendport_record.c new file +298 -0

298 lines not on this page · raw message

libsepol/src/ibendports.c new file +255 -0

255 lines not on this page · raw message

python/semanage/semanage +56 -2

94 lines not on this page · raw message

python/semanage/seobject.py +239 -0

245 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v1 8/9
#25 lore raw

Re: [PATCH v1 8/9] semanage: Update semanage to allow runtime labeling of ibendports

Quoted 20 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with ibendport records. Add local storage for new and modified ibendport records in ibendports.local. Update semanage to parse the ibendport command options to add, modify, and delete them.

---
v1:
Jason Zaman:
- Use SETools directly to query types in seobject.py

python/semanage/seobject.py +0 -0
index 41b0aca..037c9ae 100644

python/semanage/seobject.py class ibpkeyRecords(semanageRecords): · line 1571

Quoted 7 lines
python/semanage/seobject.py +4 -0
@@ -1565,6 +1565,245 @@ class ibpkeyRecords(semanageRecords):
                 rec += ", %s" % p
             print rec
 
+class ibendportRecords(semanageRecords):
+    try:
+        q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy()), attrs=["ibendport_type"])
+        valid_types = sorted(str(t) for t in q.results())

Super minor nit pick here: set() (or even frozenset()) is probably better than sorted() since you appear to only just check membership.

I probably wouldnt bother updating unless there is a v2 for some other reason.

And if want it on this or an updated version:

-- Jason

#26 lore raw

Re: [PATCH v1 8/9] semanage: Update semanage to allow runtime labeling of ibendports

Quoted 31 lines · Jason Zaman
Quoted 20 lines · Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update libsepol and libsemanage to work with ibendport records. Add local storage for new and modified ibendport records in ibendports.local. Update semanage to parse the ibendport command options to add, modify, and delete them.

---
v1:
Jason Zaman:
- Use SETools directly to query types in seobject.py

python/semanage/seobject.py +0 -0
index 41b0aca..037c9ae 100644

python/semanage/seobject.py class ibpkeyRecords(semanageRecords): · line 1571

Quoted 7 lines
python/semanage/seobject.py +4 -0
@@ -1565,6 +1565,245 @@ class ibpkeyRecords(semanageRecords):
                 rec += ", %s" % p
             print rec
 
+class ibendportRecords(semanageRecords):
+    try:
+        q = setools.TypeQuery(setools.SELinuxPolicy(sepolicy.get_installed_policy()), attrs=["ibendport_type"])
+        valid_types = sorted(str(t) for t in q.results())

Super minor nit pick here: set() (or even frozenset()) is probably better than sorted() since you appear to only just check membership.

Quoted 8 lines

I probably wouldnt bother updating unless there is a v2 for some other reason.

And if want it on this or an updated version:

-- Jason

Thanks Jason, I'll have to rebase over a patch Stephen submitted the other day, so there will be a v2 and I'll address this in it.

#27 lore raw

PATCH 9/9 semanage: Update man pages for infiniband

In reply to Dan Jurgens

From: Daniel Jurgens <[email protected]>

Update the main man page and add specific pages for ibpkeys and ibendports.

---
 python/semanage/semanage-ibendport.8 | 66 ++++++++++++++++++++++++++++++++++++
 python/semanage/semanage-ibpkey.8    | 66 ++++++++++++++++++++++++++++++++++++
 python/semanage/semanage.8           | 16 ++++++---
 3 files changed, 144 insertions(+), 4 deletions(-)
 create mode 100644 python/semanage/semanage-ibendport.8
 create mode 100644 python/semanage/semanage-ibpkey.8
python/semanage/semanage-ibendport.8 new file +66 -0
new file mode 100644
index 0000000..c3753a2
@@ -0,0 +1,66 @@
+.TH "semanage-ibendport" "8" "20170508" "" ""
+.SH "NAME"
+.B semanage\-ibendport \- SELinux Policy Management ibendport mapping tool
+.SH "SYNOPSIS"
+.B semanage ibendport [\-h] [\-n] [\-N] [\-S STORE] [ \-\-add \-t TYPE \-z IBDEV_NAME \-r RANGE port | \-\-delete \-z IBDEV_NAME port | \-\-deleteall  | \-\-extract  | \-\-list [\-C] | \-\-modify \-t TYPE \-z IBDEV_NAME \-r RANGE port ]
+
+.SH "DESCRIPTION"
+semanage is used to configure certain elements of SELinux policy without requiring modification to or recompilation from policy sources.  semanage ibendport controls the ibendport number to ibendport type definitions.
+
+.SH "OPTIONS"
+.TP
+.I  \-h, \-\-help
+show this help message and exit
+.TP
+.I   \-n, \-\-noheading
+Do not print heading when listing the specified object type
+.TP
+.I   \-N, \-\-noreload
+Do not reload policy after commit
+.TP
+.I   \-S STORE, \-\-store STORE
+Select an alternate SELinux Policy Store to manage
+.TP
+.I   \-C, \-\-locallist
+List local customizations
+.TP
+.I   \-a, \-\-add
+Add a record of the specified object type
+.TP
+.I   \-d, \-\-delete
+Delete a record of the specified object type
+.TP
+.I   \-m, \-\-modify
+Modify a record of the specified object type
+.TP
+.I   \-l, \-\-list
+List records of the specified object type
+.TP
+.I   \-E, \-\-extract
+Extract customizable commands, for use within a transaction
+.TP
+.I   \-D, \-\-deleteall
+Remove all local customizations
+.TP
+.I   \-t TYPE, \-\-type TYPE
+SELinux type for the object
+.TP
+.I   \-r RANGE, \-\-range RANGE
+MLS/MCS Security Range (MLS/MCS Systems only) SELinux Range for SELinux login mapping defaults to the SELinux user record range. SELinux Range for SELinux user defaults to s0.
+.TP
+.I \-z IBDEV_NAME, \-\-ibdev_name IBDEV_NAME
+The name of the infiniband device for the port to be labeled.  (ex. mlx5_0)
+
+.SH EXAMPLE
+.nf
+List all ibendport definitions
+# semanage ibendport \-l
+Label mlx4_0 port 2.
+# semanage ibendport \-a \-t allowed_ibendport_t \-z mlx4_0 2
+
+.SH "SEE ALSO"
+.BR selinux (8),
+.BR semanage (8)
+
+.SH "AUTHOR"
+This man page was written by Daniel Walsh <[email protected]>
python/semanage/semanage-ibpkey.8 new file +66 -0

66 lines not on this page · raw message

python/semanage/semanage.8 +12 -4
index abc4736..0bdb90f 100644
@@ -3,7 +3,7 @@
 semanage \- SELinux Policy Management tool
 
 .SH "SYNOPSIS"
-.B semanage                {import,export,login,user,port,interface,module,node,fcontext,boolean,permissive,dontaudit}
+.B semanage                {import,export,login,user,port,interface,module,node,fcontext,boolean,permissive,dontaudit,ibpkey,ibendport}
                 ...
 .B positional arguments:
 
@@ -43,6 +43,12 @@ Manage process type enforcement mode
 .B    dontaudit
 Disable/Enable dontaudit rules in policy
 
+.B    ibpkey
+Manage infiniband pkey type definitions
+
+.B    ibendport
+Manage infiniband end port type definitions
+
 .SH "DESCRIPTION"
 semanage is used to configure certain elements of
 SELinux policy without requiring modification to or recompilation
@@ -50,9 +56,9 @@ from policy sources.  This includes the mapping from Linux usernames
 to SELinux user identities (which controls the initial security context
 assigned to Linux users when they login and bounds their authorized role set)
 as well as security context mappings for various kinds of objects, such
-as network ports, interfaces, and nodes (hosts) as well as the file
-context mapping. See the EXAMPLES section below for some examples
-of common usage.  Note that the semanage login command deals with the
+as network ports, interfaces, infiniband pkeys and endports, and nodes (hosts)
+as well as the file context mapping. See the EXAMPLES section below for some
+examples of common usage.  Note that the semanage login command deals with the
 mapping from Linux usernames (logins) to SELinux user identities,
 while the semanage user command deals with the mapping from SELinux
 user identities to authorized role sets.  In most cases, only the
@@ -79,6 +85,8 @@ List help information
 .BR semanage-permissive (8),
 .BR semanage-port (8),
 .BR semanage-user (8)
+.BR semanage-ibkey (8),
+.BR semanage-ibendport (8),
 
 .SH "AUTHOR"
 This man page was written by Daniel Walsh <[email protected]>
Signature · 1 line
2.7.4