Blame SOURCES/checkpolicy-rhel.patch

1a0c16
diff --git checkpolicy-2.5/Android.mk checkpolicy-2.5/Android.mk
1a0c16
index 98f5168..3b7ff8a 100644
1a0c16
--- checkpolicy-2.5/Android.mk
1a0c16
+++ checkpolicy-2.5/Android.mk
1a0c16
@@ -12,10 +12,6 @@ common_cflags := \
1a0c16
 	-Wall -Wshadow -O2 \
1a0c16
 	-pipe -fno-strict-aliasing \
1a0c16
 
1a0c16
-ifeq ($(HOST_OS),darwin)
1a0c16
-common_cflags += -DDARWIN
1a0c16
-endif
1a0c16
-
1a0c16
 common_includes := \
1a0c16
 	$(LOCAL_PATH)/ \
1a0c16
 	$(LOCAL_PATH)/../libsepol/include/ \
1a0c16
diff --git checkpolicy-2.5/ChangeLog checkpolicy-2.5/ChangeLog
1a0c16
index dfe4908..f2216ec 100644
1a0c16
--- checkpolicy-2.5/ChangeLog
1a0c16
+++ checkpolicy-2.5/ChangeLog
1a0c16
@@ -1,3 +1,11 @@
1a0c16
+	* Extend checkpolicy pathname matching, from Stephen Smalley.
1a0c16
+	* Fix typos in test/dispol, from Petr Lautrbach.
1a0c16
+	* Set flex as default lexer, from Julien Pivotto.
1a0c16
+	* Fix checkmodule output message, from Petr Lautrbach.
1a0c16
+	* Build policy on systems not supporting DCCP protocol, from Richard Haines.
1a0c16
+	* Fail if module name different than output base filename, from James Carter
1a0c16
+	* Add support for portcon dccp protocol, from Richard Haines
1a0c16
+
1a0c16
 2.5 2016-02-23
1a0c16
 	* Add neverallow support for ioctl extended permissions, from Jeff Vander Stoep.
1a0c16
 	* fix double free on name-based type transitions, from Stephen Smalley.
1a0c16
diff --git checkpolicy-2.5/Makefile checkpolicy-2.5/Makefile
1a0c16
index e5fae3d..53a3074 100644
1a0c16
--- checkpolicy-2.5/Makefile
1a0c16
+++ checkpolicy-2.5/Makefile
1a0c16
@@ -8,6 +8,7 @@ LIBDIR ?= $(PREFIX)/lib
1a0c16
 INCLUDEDIR ?= $(PREFIX)/include
1a0c16
 TARGETS = checkpolicy checkmodule
1a0c16
 
1a0c16
+LEX = flex
1a0c16
 YACC = bison -y
1a0c16
 
1a0c16
 CFLAGS ?= -g -Wall -Werror -Wshadow -O2 -pipe -fno-strict-aliasing
1a0c16
diff --git checkpolicy-2.5/checkmodule.c checkpolicy-2.5/checkmodule.c
1a0c16
index 5957d29..53cc5a0 100644
1a0c16
--- checkpolicy-2.5/checkmodule.c
1a0c16
+++ checkpolicy-2.5/checkmodule.c
1a0c16
@@ -19,6 +19,7 @@
1a0c16
 #include <stdio.h>
1a0c16
 #include <errno.h>
1a0c16
 #include <sys/mman.h>
1a0c16
+#include <libgen.h>
1a0c16
 
1a0c16
 #include <sepol/module_to_cil.h>
1a0c16
 #include <sepol/policydb/policydb.h>
1a0c16
@@ -258,6 +259,25 @@ int main(int argc, char **argv)
1a0c16
 		}
1a0c16
 	}
1a0c16
 
1a0c16
+	if (policy_type != POLICY_BASE && outfile) {
1a0c16
+		char *mod_name = modpolicydb.name;
1a0c16
+		char *out_path = strdup(outfile);
1a0c16
+		if (out_path == NULL) {
1a0c16
+			fprintf(stderr, "%s:  out of memory\n", argv[0]);
1a0c16
+			exit(1);
1a0c16
+		}
1a0c16
+		char *out_name = basename(out_path);
1a0c16
+		char *separator = strrchr(out_name, '.');
1a0c16
+		if (separator) {
1a0c16
+			*separator = '\0';
1a0c16
+		}
1a0c16
+		if (strcmp(mod_name, out_name) != 0) {
1a0c16
+			fprintf(stderr,	"%s:  Module name %s is different than the output base filename %s\n", argv[0], mod_name, out_name);
1a0c16
+			exit(1);
1a0c16
+		}
1a0c16
+		free(out_path);
1a0c16
+	}
1a0c16
+
1a0c16
 	if (modpolicydb.policy_type == POLICY_BASE && !cil) {
1a0c16
 		/* Verify that we can successfully expand the base module. */
1a0c16
 		policydb_t kernpolicydb;
1a0c16
@@ -294,7 +314,7 @@ int main(int argc, char **argv)
1a0c16
 
1a0c16
 		if (!cil) {
1a0c16
 			printf("%s:  writing binary representation (version %d) to %s\n",
1a0c16
-				   argv[0], policyvers, file);
1a0c16
+				   argv[0], policyvers, outfile);
1a0c16
 
1a0c16
 			if (write_binary_policy(&modpolicydb, outfp) != 0) {
1a0c16
 				fprintf(stderr, "%s:  error writing %s\n", argv[0], outfile);
1a0c16
diff --git checkpolicy-2.5/checkpolicy.c checkpolicy-2.5/checkpolicy.c
7533bf
index 9da661e..f682355 100644
1a0c16
--- checkpolicy-2.5/checkpolicy.c
1a0c16
+++ checkpolicy-2.5/checkpolicy.c
1a0c16
@@ -22,6 +22,7 @@
1a0c16
  *
1a0c16
  *	Policy Module support.
1a0c16
  *
1a0c16
+ * Copyright (C) 2017 Mellanox Technologies Inc.
1a0c16
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
1a0c16
  * Copyright (C) 2003 - 2005 Tresys Technology, LLC
1a0c16
  * Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
7533bf
@@ -64,13 +65,19 @@
1a0c16
 #include <sys/stat.h>
1a0c16
 #include <sys/socket.h>
1a0c16
 #include <netinet/in.h>
1a0c16
+#ifndef IPPROTO_DCCP
1a0c16
+#define IPPROTO_DCCP 33
1a0c16
+#endif
7533bf
+#ifndef IPPROTO_SCTP
7533bf
+#define IPPROTO_SCTP 132
7533bf
+#endif
1a0c16
 #include <arpa/inet.h>
1a0c16
 #include <fcntl.h>
1a0c16
 #include <stdio.h>
1a0c16
 #include <errno.h>
1a0c16
 #include <sys/mman.h>
1a0c16
 
1a0c16
-#ifdef DARWIN
1a0c16
+#ifdef __APPLE__
1a0c16
 #include <ctype.h>
1a0c16
 #endif
1a0c16
 
7533bf
@@ -679,6 +686,8 @@ int main(int argc, char **argv)
1a0c16
 	printf("h)  change a boolean value\n");
1a0c16
 	printf("i)  display constraint expressions\n");
1a0c16
 	printf("j)  display validatetrans expressions\n");
1a0c16
+	printf("k)  Call ibpkey_sid\n");
1a0c16
+	printf("l)  Call ibendport_sid\n");
1a0c16
 #ifdef EQUIVTYPES
1a0c16
 	printf("z)  Show equivalent types\n");
1a0c16
 #endif
7533bf
@@ -919,6 +928,10 @@ int main(int argc, char **argv)
1a0c16
 				protocol = IPPROTO_TCP;
1a0c16
 			else if (!strcmp(ans, "udp") || !strcmp(ans, "UDP"))
1a0c16
 				protocol = IPPROTO_UDP;
1a0c16
+			else if (!strcmp(ans, "dccp") || !strcmp(ans, "DCCP"))
1a0c16
+				protocol = IPPROTO_DCCP;
7533bf
+			else if (!strcmp(ans, "sctp") || !strcmp(ans, "SCTP"))
7533bf
+				protocol = IPPROTO_SCTP;
1a0c16
 			else {
1a0c16
 				printf("unknown protocol\n");
1a0c16
 				break;
7533bf
@@ -1198,6 +1211,50 @@ int main(int argc, char **argv)
1a0c16
 				    "\nNo validatetrans expressions found.\n");
1a0c16
 			}
1a0c16
 			break;
1a0c16
+		case 'k':
1a0c16
+			{
1a0c16
+				char *p;
1a0c16
+				struct in6_addr addr6;
1a0c16
+				uint64_t subnet_prefix;
1a0c16
+				unsigned int pkey;
1a0c16
+
1a0c16
+				printf("subnet prefix?  ");
1a0c16
+				FGETS(ans, sizeof(ans), stdin);
1a0c16
+				ans[strlen(ans) - 1] = 0;
1a0c16
+				p = (char *)&addr6;
1a0c16
+
1a0c16
+				if (inet_pton(AF_INET6, ans, p) < 1) {
1a0c16
+					printf("error parsing subnet prefix\n");
1a0c16
+					break;
1a0c16
+				}
1a0c16
+
1a0c16
+				memcpy(&subnet_prefix, p, sizeof(subnet_prefix));
1a0c16
+				printf("pkey? ");
1a0c16
+				FGETS(ans, sizeof(ans), stdin);
1a0c16
+				pkey = atoi(ans);
1a0c16
+				sepol_ibpkey_sid(subnet_prefix, pkey, &ssid);
1a0c16
+				printf("sid %d\n", ssid);
1a0c16
+			}
1a0c16
+			break;
1a0c16
+		case 'l':
1a0c16
+			printf("device name (eg. mlx4_0)?  ");
1a0c16
+			FGETS(ans, sizeof(ans), stdin);
1a0c16
+			ans[strlen(ans) - 1] = 0;
1a0c16
+
1a0c16
+			name = malloc((strlen(ans) + 1) * sizeof(char));
1a0c16
+			if (!name) {
1a0c16
+				fprintf(stderr, "couldn't malloc string.\n");
1a0c16
+				break;
1a0c16
+			}
1a0c16
+			strcpy(name, ans);
1a0c16
+
1a0c16
+			printf("port? ");
1a0c16
+			FGETS(ans, sizeof(ans), stdin);
1a0c16
+			port = atoi(ans);
1a0c16
+			sepol_ibendport_sid(name, port, &ssid);
1a0c16
+			printf("sid %d\n", ssid);
1a0c16
+			free(name);
1a0c16
+			break;
1a0c16
 #ifdef EQUIVTYPES
1a0c16
 		case 'z':
1a0c16
 			identify_equiv_types();
1a0c16
diff --git checkpolicy-2.5/policy_define.c checkpolicy-2.5/policy_define.c
7533bf
index ee20fea..a275e33 100644
1a0c16
--- checkpolicy-2.5/policy_define.c
1a0c16
+++ checkpolicy-2.5/policy_define.c
1a0c16
@@ -20,6 +20,7 @@
1a0c16
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
1a0c16
  * Copyright (C) 2003 - 2008 Tresys Technology, LLC
1a0c16
  * Copyright (C) 2007 Red Hat Inc.
1a0c16
+ * Copyright (C) 2017 Mellanox Techonologies Inc.
1a0c16
  *	This program is free software; you can redistribute it and/or modify
1a0c16
  *  	it under the terms of the GNU General Public License as published by
1a0c16
  *	the Free Software Foundation, version 2.
7533bf
@@ -36,6 +37,12 @@
1a0c16
 #include <string.h>
1a0c16
 #include <sys/socket.h>
1a0c16
 #include <netinet/in.h>
1a0c16
+#ifndef IPPROTO_DCCP
1a0c16
+#define IPPROTO_DCCP 33
1a0c16
+#endif
7533bf
+#ifndef IPPROTO_SCTP
7533bf
+#define IPPROTO_SCTP 132
7533bf
+#endif
1a0c16
 #include <arpa/inet.h>
1a0c16
 #include <stdlib.h>
1a0c16
 #include <limits.h>
7533bf
@@ -4876,6 +4883,10 @@ int define_port_context(unsigned int low, unsigned int high)
1a0c16
 		protocol = IPPROTO_TCP;
1a0c16
 	} else if ((strcmp(id, "udp") == 0) || (strcmp(id, "UDP") == 0)) {
1a0c16
 		protocol = IPPROTO_UDP;
1a0c16
+	} else if ((strcmp(id, "dccp") == 0) || (strcmp(id, "DCCP") == 0)) {
1a0c16
+		protocol = IPPROTO_DCCP;
7533bf
+	} else if ((strcmp(id, "sctp") == 0) || (strcmp(id, "SCTP") == 0)) {
7533bf
+		protocol = IPPROTO_SCTP;
1a0c16
 	} else {
1a0c16
 		yyerror2("unrecognized protocol %s", id);
1a0c16
 		free(newc);
7533bf
@@ -4931,6 +4942,192 @@ int define_port_context(unsigned int low, unsigned int high)
1a0c16
 	return -1;
1a0c16
 }
1a0c16
 
1a0c16
+int define_ibpkey_context(unsigned int low, unsigned int high)
1a0c16
+{
1a0c16
+	ocontext_t *newc, *c, *l, *head;
1a0c16
+	struct in6_addr subnet_prefix;
1a0c16
+	char *id;
1a0c16
+	int rc = 0;
1a0c16
+
1a0c16
+	if (policydbp->target_platform != SEPOL_TARGET_SELINUX) {
1a0c16
+		yyerror("ibpkeycon not supported for target");
1a0c16
+		return -1;
1a0c16
+	}
1a0c16
+
1a0c16
+	if (pass == 1) {
1a0c16
+		id = (char *)queue_remove(id_queue);
1a0c16
+		free(id);
1a0c16
+		parse_security_context(NULL);
1a0c16
+		return 0;
1a0c16
+	}
1a0c16
+
1a0c16
+	newc = malloc(sizeof(*newc));
1a0c16
+	if (!newc) {
1a0c16
+		yyerror("out of memory");
1a0c16
+		return -1;
1a0c16
+	}
1a0c16
+	memset(newc, 0, sizeof(*newc));
1a0c16
+
1a0c16
+	id = queue_remove(id_queue);
1a0c16
+	if (!id) {
1a0c16
+		yyerror("failed to read the subnet prefix");
1a0c16
+		rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	rc = inet_pton(AF_INET6, id, &subnet_prefix);
1a0c16
+	free(id);
1a0c16
+	if (rc < 1) {
1a0c16
+		yyerror("failed to parse the subnet prefix");
1a0c16
+		if (rc == 0)
1a0c16
+			rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	if (subnet_prefix.s6_addr[2] || subnet_prefix.s6_addr[3]) {
1a0c16
+		yyerror("subnet prefix should be 0's in the low order 64 bits.");
1a0c16
+		rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	if (low > 0xffff || high > 0xffff) {
1a0c16
+		yyerror("pkey value too large, pkeys are 16 bits.");
1a0c16
+		rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	memcpy(&newc->u.ibpkey.subnet_prefix, &subnet_prefix.s6_addr[0],
1a0c16
+	       sizeof(newc->u.ibpkey.subnet_prefix));
1a0c16
+
1a0c16
+	newc->u.ibpkey.low_pkey = low;
1a0c16
+	newc->u.ibpkey.high_pkey = high;
1a0c16
+
1a0c16
+	if (low > high) {
1a0c16
+		yyerror2("low pkey %d exceeds high pkey %d", low, high);
1a0c16
+		rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	rc = parse_security_context(&newc->context[0]);
1a0c16
+	if (rc)
1a0c16
+		goto out;
1a0c16
+
1a0c16
+	/* Preserve the matching order specified in the configuration. */
1a0c16
+	head = policydbp->ocontexts[OCON_IBPKEY];
1a0c16
+	for (l = NULL, c = head; c; l = c, c = c->next) {
1a0c16
+		unsigned int low2, high2;
1a0c16
+
1a0c16
+		low2 = c->u.ibpkey.low_pkey;
1a0c16
+		high2 = c->u.ibpkey.high_pkey;
1a0c16
+
1a0c16
+		if (low == low2 && high == high2 &&
1a0c16
+		    c->u.ibpkey.subnet_prefix == newc->u.ibpkey.subnet_prefix) {
1a0c16
+			yyerror2("duplicate ibpkeycon entry for %d-%d ",
1a0c16
+				 low, high);
1a0c16
+			rc = -1;
1a0c16
+			goto out;
1a0c16
+		}
1a0c16
+		if (low2 <= low && high2 >= high &&
1a0c16
+		    c->u.ibpkey.subnet_prefix == newc->u.ibpkey.subnet_prefix) {
1a0c16
+			yyerror2("ibpkeycon entry for %d-%d hidden by earlier entry for %d-%d",
1a0c16
+				 low, high, low2, high2);
1a0c16
+			rc = -1;
1a0c16
+			goto out;
1a0c16
+		}
1a0c16
+	}
1a0c16
+
1a0c16
+	if (l)
1a0c16
+		l->next = newc;
1a0c16
+	else
1a0c16
+		policydbp->ocontexts[OCON_IBPKEY] = newc;
1a0c16
+
1a0c16
+	return 0;
1a0c16
+
1a0c16
+out:
1a0c16
+	free(newc);
1a0c16
+	return rc;
1a0c16
+}
1a0c16
+
1a0c16
+int define_ibendport_context(unsigned int port)
1a0c16
+{
1a0c16
+	ocontext_t *newc, *c, *l, *head;
1a0c16
+	char *id;
1a0c16
+	int rc = 0;
1a0c16
+
1a0c16
+	if (policydbp->target_platform != SEPOL_TARGET_SELINUX) {
1a0c16
+		yyerror("ibendportcon not supported for target");
1a0c16
+		return -1;
1a0c16
+	}
1a0c16
+
1a0c16
+	if (pass == 1) {
1a0c16
+		id = (char *)queue_remove(id_queue);
1a0c16
+		free(id);
1a0c16
+		parse_security_context(NULL);
1a0c16
+		return 0;
1a0c16
+	}
1a0c16
+
1a0c16
+	if (port > 0xff || port == 0) {
1a0c16
+		yyerror("Invalid ibendport port number, should be 0 < port < 256");
1a0c16
+		return -1;
1a0c16
+	}
1a0c16
+
1a0c16
+	newc = malloc(sizeof(*newc));
1a0c16
+	if (!newc) {
1a0c16
+		yyerror("out of memory");
1a0c16
+		return -1;
1a0c16
+	}
1a0c16
+	memset(newc, 0, sizeof(*newc));
1a0c16
+
1a0c16
+	newc->u.ibendport.dev_name = queue_remove(id_queue);
1a0c16
+	if (!newc->u.ibendport.dev_name) {
1a0c16
+		yyerror("failed to read infiniband device name.");
1a0c16
+		rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	if (strlen(newc->u.ibendport.dev_name) > IB_DEVICE_NAME_MAX - 1) {
1a0c16
+		yyerror("infiniband device name exceeds max length of 63.");
1a0c16
+		rc = -1;
1a0c16
+		goto out;
1a0c16
+	}
1a0c16
+
1a0c16
+	newc->u.ibendport.port = port;
1a0c16
+
1a0c16
+	if (parse_security_context(&newc->context[0])) {
1a0c16
+		free(newc);
1a0c16
+		return -1;
1a0c16
+	}
1a0c16
+
1a0c16
+	/* Preserve the matching order specified in the configuration. */
1a0c16
+	head = policydbp->ocontexts[OCON_IBENDPORT];
1a0c16
+	for (l = NULL, c = head; c; l = c, c = c->next) {
1a0c16
+		unsigned int port2;
1a0c16
+
1a0c16
+		port2 = c->u.ibendport.port;
1a0c16
+
1a0c16
+		if (port == port2 &&
1a0c16
+		    !strcmp(c->u.ibendport.dev_name,
1a0c16
+			     newc->u.ibendport.dev_name)) {
1a0c16
+			yyerror2("duplicate ibendportcon entry for %s port %u",
1a0c16
+				 newc->u.ibendport.dev_name, port);
1a0c16
+			rc = -1;
1a0c16
+			goto out;
1a0c16
+		}
1a0c16
+	}
1a0c16
+
1a0c16
+	if (l)
1a0c16
+		l->next = newc;
1a0c16
+	else
1a0c16
+		policydbp->ocontexts[OCON_IBENDPORT] = newc;
1a0c16
+
1a0c16
+	return 0;
1a0c16
+
1a0c16
+out:
1a0c16
+	free(newc->u.ibendport.dev_name);
1a0c16
+	free(newc);
1a0c16
+	return rc;
1a0c16
+}
1a0c16
+
1a0c16
 int define_netif_context(void)
1a0c16
 {
1a0c16
 	ocontext_t *newc, *c, *head;
7533bf
@@ -5135,7 +5332,7 @@ int define_ipv6_node_context(void)
1a0c16
 
1a0c16
 	memset(newc, 0, sizeof(ocontext_t));
1a0c16
 
1a0c16
-#ifdef DARWIN
1a0c16
+#ifdef __APPLE__
1a0c16
 	memcpy(&newc->u.node6.addr[0], &addr.s6_addr[0], 16);
1a0c16
 	memcpy(&newc->u.node6.mask[0], &mask.s6_addr[0], 16);
1a0c16
 #else
1a0c16
diff --git checkpolicy-2.5/policy_define.h checkpolicy-2.5/policy_define.h
1a0c16
index 964baae..3282aed 100644
1a0c16
--- checkpolicy-2.5/policy_define.h
1a0c16
+++ checkpolicy-2.5/policy_define.h
1a0c16
@@ -43,6 +43,8 @@ int define_level(void);
1a0c16
 int define_netif_context(void);
1a0c16
 int define_permissive(void);
1a0c16
 int define_polcap(void);
1a0c16
+int define_ibpkey_context(unsigned int low, unsigned int high);
1a0c16
+int define_ibendport_context(unsigned int port);
1a0c16
 int define_port_context(unsigned int low, unsigned int high);
1a0c16
 int define_pirq_context(unsigned int pirq);
1a0c16
 int define_iomem_context(uint64_t low, uint64_t high);
1a0c16
diff --git checkpolicy-2.5/policy_parse.y checkpolicy-2.5/policy_parse.y
1a0c16
index 3b6a2f8..35b7a33 100644
1a0c16
--- checkpolicy-2.5/policy_parse.y
1a0c16
+++ checkpolicy-2.5/policy_parse.y
1a0c16
@@ -21,6 +21,7 @@
1a0c16
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
1a0c16
  * Copyright (C) 2003 - 2008 Tresys Technology, LLC
1a0c16
  * Copyright (C) 2007 Red Hat Inc.
1a0c16
+ * Copyright (C) 2017 Mellanox Technologies Inc.
1a0c16
  *	This program is free software; you can redistribute it and/or modify
1a0c16
  *  	it under the terms of the GNU General Public License as published by
1a0c16
  *	the Free Software Foundation, version 2.
1a0c16
@@ -134,6 +135,8 @@ typedef int (* require_func_t)(int pass);
1a0c16
 %token TARGET
1a0c16
 %token SAMEUSER
1a0c16
 %token FSCON PORTCON NETIFCON NODECON 
1a0c16
+%token IBPKEYCON
1a0c16
+%token IBENDPORTCON
1a0c16
 %token PIRQCON IOMEMCON IOPORTCON PCIDEVICECON DEVICETREECON
1a0c16
 %token FSUSEXATTR FSUSETASK FSUSETRANS
1a0c16
 %token GENFSCON
1a0c16
@@ -169,7 +172,7 @@ base_policy             : { if (define_policy(pass, 0) == -1) return -1; }
1a0c16
 			  opt_default_rules opt_mls te_rbac users opt_constraints 
1a0c16
                          { if (pass == 1) { if (policydb_index_bools(policydbp)) return -1;}
1a0c16
 			   else if (pass == 2) { if (policydb_index_others(NULL, policydbp, 0)) return -1;}}
1a0c16
-			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts
1a0c16
+			  initial_sid_contexts opt_fs_contexts opt_fs_uses opt_genfs_contexts net_contexts opt_dev_contexts opt_ibpkey_contexts opt_ibendport_contexts
1a0c16
 			;
1a0c16
 classes			: class_def 
1a0c16
 			| classes class_def
1a0c16
@@ -695,7 +698,7 @@ fs_contexts		: fs_context_def
1a0c16
 fs_context_def		: FSCON number number security_context_def security_context_def
1a0c16
 			{if (define_fs_context($2,$3)) return -1;}
1a0c16
 			;
1a0c16
-net_contexts		: opt_port_contexts opt_netif_contexts opt_node_contexts 
1a0c16
+net_contexts		: opt_port_contexts opt_netif_contexts opt_node_contexts
1a0c16
 			;
1a0c16
 opt_port_contexts       : port_contexts
1a0c16
                         |
1a0c16
@@ -708,6 +711,26 @@ port_context_def	: PORTCON identifier number security_context_def
1a0c16
 			| PORTCON identifier number '-' number security_context_def
1a0c16
 			{if (define_port_context($3,$5)) return -1;}
1a0c16
 			;
1a0c16
+opt_ibpkey_contexts     : ibpkey_contexts
1a0c16
+                        |
1a0c16
+                        ;
1a0c16
+ibpkey_contexts		: ibpkey_context_def
1a0c16
+			| ibpkey_contexts ibpkey_context_def
1a0c16
+			;
1a0c16
+ibpkey_context_def	: IBPKEYCON ipv6_addr number security_context_def
1a0c16
+			{if (define_ibpkey_context($3,$3)) return -1;}
1a0c16
+			| IBPKEYCON ipv6_addr number '-' number security_context_def
1a0c16
+			{if (define_ibpkey_context($3,$5)) return -1;}
1a0c16
+			;
1a0c16
+opt_ibendport_contexts	: ibendport_contexts
1a0c16
+			|
1a0c16
+			;
1a0c16
+ibendport_contexts	: ibendport_context_def
1a0c16
+                        | ibendport_contexts ibendport_context_def
1a0c16
+                        ;
1a0c16
+ibendport_context_def	: IBENDPORTCON identifier number security_context_def
1a0c16
+                        {if (define_ibendport_context($3)) return -1;}
1a0c16
+                        ;
1a0c16
 opt_netif_contexts      : netif_contexts 
1a0c16
                         |
1a0c16
                         ;
1a0c16
diff --git checkpolicy-2.5/policy_scan.l checkpolicy-2.5/policy_scan.l
1a0c16
index 22da338..f38dd22 100644
1a0c16
--- checkpolicy-2.5/policy_scan.l
1a0c16
+++ checkpolicy-2.5/policy_scan.l
1a0c16
@@ -12,6 +12,7 @@
1a0c16
  *	Added support for binary policy modules
1a0c16
  *
1a0c16
  * Copyright (C) 2003-5 Tresys Technology, LLC
1a0c16
+ * Copyright (C) 2017 Mellanox Technologies Inc.
1a0c16
  *	This program is free software; you can redistribute it and/or modify
1a0c16
  *  	it under the terms of the GNU General Public License as published by
1a0c16
  *	the Free Software Foundation, version 2.
1a0c16
@@ -181,6 +182,10 @@ INCOMP |
1a0c16
 incomp				{ return(INCOMP);}
1a0c16
 fscon |
1a0c16
 FSCON                           { return(FSCON);}
1a0c16
+ibpkeycon |
1a0c16
+IBPKEYCON			{ return(IBPKEYCON);}
1a0c16
+ibendportcon |
1a0c16
+IBENDPORTCON			{ return(IBENDPORTCON);}
1a0c16
 portcon |
1a0c16
 PORTCON				{ return(PORTCON);}
1a0c16
 netifcon |                     
1a0c16
@@ -249,9 +254,9 @@ high |
1a0c16
 HIGH				{ return(HIGH); }
1a0c16
 low |
1a0c16
 LOW				{ return(LOW); }
1a0c16
-"/"({alnum}|[_\.\-/])*	        { return(PATH); }
1a0c16
-\""/"[ !#-~]*\" 		{ return(QPATH); }
1a0c16
-\"({alnum}|[_\.\-\+\~\: ])+\"	{ return(FILENAME); }
1a0c16
+"/"[^ \n\r\t\f]*	        { return(PATH); }
1a0c16
+\""/"[^\"\n]*\" 		{ return(QPATH); }
1a0c16
+\"[^"/"\"\n]+\"	{ return(FILENAME); }
1a0c16
 {letter}({alnum}|[_\-])*([\.]?({alnum}|[_\-]))*	{ return(IDENTIFIER); }
1a0c16
 {digit}+|0x{hexval}+            { return(NUMBER); }
1a0c16
 {alnum}*{letter}{alnum}*        { return(FILESYSTEM); }
1a0c16
diff --git checkpolicy-2.5/test/dismod.c checkpolicy-2.5/test/dismod.c
1a0c16
index 08b039d..c91ab93 100644
1a0c16
--- checkpolicy-2.5/test/dismod.c
1a0c16
+++ checkpolicy-2.5/test/dismod.c
1a0c16
@@ -243,6 +243,13 @@ int display_avrule(avrule_t * avrule, policydb_t * policy,
1a0c16
 		}
1a0c16
 	} else if (avrule->specified & AVRULE_NEVERALLOW) {
1a0c16
 		fprintf(fp, "  neverallow");
1a0c16
+	} else if (avrule->specified & AVRULE_XPERMS) {
1a0c16
+		if (avrule->specified & AVRULE_XPERMS_ALLOWED)
1a0c16
+			fprintf(fp, "allowxperm ");
1a0c16
+		else if (avrule->specified & AVRULE_XPERMS_AUDITALLOW)
1a0c16
+			fprintf(fp, "auditallowxperm ");
1a0c16
+		else if (avrule->specified & AVRULE_XPERMS_DONTAUDIT)
1a0c16
+			fprintf(fp, "dontauditxperm ");
1a0c16
 	} else {
1a0c16
 		fprintf(fp, "     ERROR: no valid rule type specified\n");
1a0c16
 		return -1;
1a0c16
@@ -282,6 +289,24 @@ int display_avrule(avrule_t * avrule, policydb_t * policy,
1a0c16
 				   policy, fp);
1a0c16
 	} else if (avrule->specified & AVRULE_TYPE) {
1a0c16
 		display_id(policy, fp, SYM_TYPES, avrule->perms->data - 1, "");
1a0c16
+	} else if (avrule->specified & AVRULE_XPERMS) {
1a0c16
+		avtab_extended_perms_t xperms;
1a0c16
+		int i;
1a0c16
+
1a0c16
+		if (avrule->xperms->specified == AVRULE_XPERMS_IOCTLFUNCTION)
1a0c16
+			xperms.specified = AVTAB_XPERMS_IOCTLFUNCTION;
1a0c16
+		else if (avrule->xperms->specified == AVRULE_XPERMS_IOCTLDRIVER)
1a0c16
+			xperms.specified = AVTAB_XPERMS_IOCTLDRIVER;
1a0c16
+		else {
1a0c16
+			fprintf(fp, "     ERROR: no valid xperms specified\n");
1a0c16
+			return -1;
1a0c16
+		}
1a0c16
+
1a0c16
+		xperms.driver = avrule->xperms->driver;
1a0c16
+		for (i = 0; i < EXTENDED_PERMS_LEN; i++)
1a0c16
+			xperms.perms[i] = avrule->xperms->perms[i];
1a0c16
+
1a0c16
+		fprintf(fp, "%s", sepol_extended_perms_to_string(&xperms));
1a0c16
 	}
1a0c16
 
1a0c16
 	fprintf(fp, ";\n");
1a0c16
diff --git checkpolicy-2.5/test/dispol.c checkpolicy-2.5/test/dispol.c
1a0c16
index 86f5688..a78ce81 100644
1a0c16
--- checkpolicy-2.5/test/dispol.c
1a0c16
+++ checkpolicy-2.5/test/dispol.c
1a0c16
@@ -252,11 +252,11 @@ int display_cond_expressions(policydb_t * p, FILE * fp)
1a0c16
 int display_handle_unknown(policydb_t * p, FILE * out_fp)
1a0c16
 {
1a0c16
 	if (p->handle_unknown == ALLOW_UNKNOWN)
1a0c16
-		fprintf(out_fp, "Allow unknown classes and permisions\n");
1a0c16
+		fprintf(out_fp, "Allow unknown classes and permissions\n");
1a0c16
 	else if (p->handle_unknown == DENY_UNKNOWN)
1a0c16
-		fprintf(out_fp, "Deny unknown classes and permisions\n");
1a0c16
+		fprintf(out_fp, "Deny unknown classes and permissions\n");
1a0c16
 	else if (p->handle_unknown == REJECT_UNKNOWN)
1a0c16
-		fprintf(out_fp, "Reject unknown classes and permisions\n");
1a0c16
+		fprintf(out_fp, "Reject unknown classes and permissions\n");
1a0c16
 	return 0;
1a0c16
 }
1a0c16
 
1a0c16
@@ -349,7 +349,7 @@ int menu(void)
1a0c16
 	printf("\nSelect a command:\n");
1a0c16
 	printf("1)  display unconditional AVTAB\n");
1a0c16
 	printf("2)  display conditional AVTAB (entirely)\n");
1a0c16
-	printf("3)  display conditional AVTAG (only ENABLED rules)\n");
1a0c16
+	printf("3)  display conditional AVTAB (only ENABLED rules)\n");
1a0c16
 	printf("4)  display conditional AVTAB (only DISABLED rules)\n");
1a0c16
 	printf("5)  display conditional bools\n");
1a0c16
 	printf("6)  display conditional expressions\n");