Skip to contentSkip to conversation

checkpolicy: support for permissive types

PATCH Superseded Eric Paris 3 participants 4 messages Mar 11, 2008 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eric Paris

author
#0 lore raw

PATCH 1/1 checkpolicy: support for permissive types

This patch adds support for permissive types.

A very simple module to make httpd_t a permissive domain would be:

policy_module(permissiveapache, 1.0)
gen_require(`

	type httpd_t;

')
permissive httpd_t;

Obviously this syntax can be used in both the base policy and in a policy module.

---

 policy_parse.y |   43 +++++++++++++++++++++++++++++++
 policy_scan.l  |    4 ++
 test/dismod.c  |    2 -
 test/dispol.c  |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 125 insertions(+), 2 deletions(-)
policy_parse.y renamed from policy_parse.y.pre.permissive +43 -0
diff -up checkpolicy-2.0.10/policy_parse.y.pre.permissive checkpolicy-2.0.10/policy_parse.y
@@ -126,6 +126,7 @@ static int define_netif_context(void);
 static int define_ipv4_node_context(void);
 static int define_ipv6_node_context(void);
 static int define_polcap(void);
+static int define_permissive(void);
 
 typedef int (* require_func_t)();
 
@@ -201,6 +202,7 @@ typedef int (* require_func_t)();
 %token IPV6_ADDR
 %token MODULE VERSION_IDENTIFIER REQUIRE OPTIONAL
 %token POLICYCAP
+%token PERMISSIVE
 
 %left OR
 %left XOR
@@ -327,6 +329,7 @@ te_decl			: attribute_def
                         | transition_def
                         | range_trans_def
                         | te_avtab_def
+			| permissive_def
 			;
 attribute_def           : ATTRIBUTE identifier ';'
                         { if (define_attrib()) return -1;}
@@ -772,6 +775,8 @@ ipv6_addr		: IPV6_ADDR
 policycap_def		: POLICYCAP identifier ';'
 			{if (define_polcap()) return -1;}
 			;
+permissive_def		: PERMISSIVE identifier ';'
+			{if (define_permissive()) return -1;}
 
 /*********** module grammar below ***********/
 
@@ -1007,6 +1012,44 @@ static int define_polcap(void)
 	return -1;
 }
 
+static int define_permissive(void)
+{
+	char *type = NULL;
+	struct type_datum *t;
+
+	if (pass == 2) {
+		type = queue_remove(id_queue);
+		free(type);
+		return 0;
+	}
+
+	type = queue_remove(id_queue);
+
+	if (!is_id_in_scope(SYM_TYPES, type)) {
+		yyerror2("type %s is not within scope", type);
+		goto bad;
+	}
+
+	t = hashtab_search(policydbp->p_types.table, type);
+	if (!t) {
+		yyerror2("type is not defined: %s", type);
+		goto bad;
+	}
+
+	if (t->flavor == TYPE_ATTRIB) {
+		yyerror2("attributes may not be permissive: %s\n", type);
+		goto bad;
+	}
+
+	t->flags |= TYPE_FLAGS_PERMISSIVE;
+
+	free(type);
+	return 0;
+bad:
+	free(type);
+	return -1;
+}
+
 static int define_initial_sid(void)
 {
 	char *id = 0;
test/dispol.c renamed from test/dispol.c.pre.permissive +78 -0

107 lines not on this page · raw message

test/dismod.c renamed from test/dismod.c.pre.permissive +1 -1
diff -up checkpolicy-2.0.10/test/dismod.c.pre.permissive checkpolicy-2.0.10/test/dismod.c
@@ -323,7 +323,7 @@ int display_type_callback(hashtab_key_t 
 		fprintf(fp, "alias for type");
 		display_id(&policydb, fp, SYM_TYPES, type->s.value - 1, "");
 	}
-	fprintf(fp, "\n");
+	fprintf(fp, " flags:%x\n", type->flags);
 
 	return 0;
 }
policy_scan.l renamed from policy_scan.l.pre.permissive +3 -1
diff -up checkpolicy-2.0.10/policy_scan.l.pre.permissive checkpolicy-2.0.10/policy_scan.l
@@ -202,7 +202,9 @@ H1				{ return(H1); }
 h2 |
 H2				{ return(H2); }
 policycap |
-POLICYCAP			{ return(POLICYCAP);}
+POLICYCAP			{ return(POLICYCAP); }
+permissive |
+PERMISSIVE			{ return(PERMISSIVE); }
 "/"({alnum}|[_.-/])*	        { return(PATH); }
 {letter}({alnum}|[_-])*([.]?({alnum}|[_-]))*	{ return(IDENTIFIER); }
 {digit}+                        { return(NUMBER); }

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw
Quoted 6 lines · Eric Paris

This patch adds support for permissive types.

A very simple module to make httpd_t a permissive domain would be:

policy_module(permissiveapache, 1.0)
gen_require(`

Quoted 9 lines
	type httpd_t;

')
permissive httpd_t;

Obviously this syntax can be used in both the base policy and in a policy module.

Comments below, otherwise looks fine.

policy_parse.y static int define_polcap(void) return

Quoted 45 lines

---

policy_parse.y | 43 +++++++++++++++++++++++++++++++ policy_scan.l

 |    4 ++ test/dismod.c  |    2 -
 test/dispol.c  |   78
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 125 insertions(+), 2 deletions(-)

diff -up checkpolicy-2.0.10/policy_parse.y.pre.permissive checkpolicy-2.0.10/policy_parse.y
--- checkpolicy-2.0.10/policy_parse.y.pre.permissive

2008-03-11 10:18:31.000000000 -0400

+++ checkpolicy-2.0.10/policy_parse.y 2008-03-11
10:23:33.000000000 -0400

(quoted diff) +0 -0
@@ -126,6 +126,7 @@ static int define_netif_context(void);

static int define_ipv4_node_context(void); static int define_ipv6_node_context(void); static int define_polcap(void);

policy_parse.y renamed from policy_parse.y.pre.permissive +1 -0
+static int define_permissive(void);
 
 typedef int (* require_func_t)();
@@ -201,6 +202,7 @@ typedef int (* require_func_t)();  %token

IPV6_ADDR %token MODULE VERSION_IDENTIFIER REQUIRE OPTIONAL %token POLICYCAP +%token PERMISSIVE

%left OR
%left XOR

policy_parse.y renamed from policy_parse.y.pre.permissive +3 -0
@@ -327,6 +329,7 @@ te_decl			: attribute_def
                         | transition_def
                         | range_trans_def
                         | te_avtab_def
+			| permissive_def
 			;
 attribute_def           : ATTRIBUTE identifier ';'
                         { if (define_attrib()) return -1;}
@@ -772,6 +775,8 @@ ipv6_addr		: IPV6_ADDR
 policycap_def		: POLICYCAP identifier ';'
 			{if (define_polcap()) return -1;}
 			;
+permissive_def		: PERMISSIVE identifier ';'
+			{if (define_permissive()) return -1;}
 
 /*********** module grammar below ***********/
 
@@ -1007,6 +1012,44 @@ static int define_polcap(void)  	return

-1;

policy_parse.y static int define_polcap(void) · line 1025

Quoted 13 lines
policy_parse.y renamed from policy_parse.y.pre.permissive +11 -0
 }
 
+static int define_permissive(void)
+{
+	char *type = NULL;
+	struct type_datum *t;
+
+	if (pass == 2) {
+		type = queue_remove(id_queue);
+		free(type);
+		return 0;
+	}
+

I think this should be pass == 1. It doesn't need to be on pass 1 since it won't be adding symbols needed for pass 2 and it makes it a little more resilient to ordering issues.

policy_parse.y static int define_polcap(void)

Quoted 8 lines
policy_parse.y renamed from policy_parse.y.pre.permissive +8 -0
+	type = queue_remove(id_queue);
+
+	if (!is_id_in_scope(SYM_TYPES, type)) {
+		yyerror2("type %s is not within scope", type);
+		goto bad;
+	}
+
+	t = hashtab_search(policydbp->p_types.table, type); +	if (!t)

{

Quoted 25 lines
policy_parse.y renamed from policy_parse.y.pre.permissive +18 -0
+		yyerror2("type is not defined: %s", type);
+		goto bad;
+	}
+
+	if (t->flavor == TYPE_ATTRIB) {
+		yyerror2("attributes may not be permissive:
 %s\n", type);
+		goto bad;
+	}
+
+	t->flags |= TYPE_FLAGS_PERMISSIVE;
+
+	free(type);
+	return 0;
+bad:
+	free(type);
+	return -1;
+}
+
 static int define_initial_sid(void)
 {
 	char *id = 0;

diff -up checkpolicy-2.0.10/test/dispol.c.pre.permissive checkpolicy-2.0.10/test/dispol.c
--- checkpolicy-2.0.10/test/dispol.c.pre.permissive

Quoted 3 lines
2008-03-11 10:18:31.000000000 -0400

+++ checkpolicy-2.0.10/test/dispol.c 2008-03-11
10:19:00.000000000 -0400

This should be a separate patch

<snip>

policy_scan.l H1 { return(H1); } · line 205

Quoted 12 lines

diff -up checkpolicy-2.0.10/policy_scan.l.pre.permissive checkpolicy-2.0.10/policy_scan.l
--- checkpolicy-2.0.10/policy_scan.l.pre.permissive

2008-03-11 10:18:31.000000000 -0400

+++ checkpolicy-2.0.10/policy_scan.l 2008-03-11
10:19:00.000000000 -0400

policy_scan.l renamed from policy_scan.l.pre.permissive +1 -1
@@ -202,7 +202,9 @@ H1				{ return(H1); }
 h2 |
 H2				{ return(H2); }
 policycap |
-POLICYCAP			{ return(POLICYCAP);}
+POLICYCAP			{ return(POLICYCAP); }

Whitespace?

policy_scan.l H1 { return(H1); } · line 210

Quoted 5 lines
policy_scan.l renamed from policy_scan.l.pre.permissive +2 -0
+permissive |
+PERMISSIVE			{ return(PERMISSIVE); }
 "/"({alnum}|[_.-/])*	        { return(PATH); }
 {letter}({alnum}|[_-])*([.]?({alnum}|[_-]))*	{ return(IDENTIFIER); }
 {digit}+                        { return(NUMBER); }

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

author
#2 lore raw
Quoted 19 lines · Joshua Brindle
Quoted 6 lines · Eric Paris

This patch adds support for permissive types.

A very simple module to make httpd_t a permissive domain would be:

policy_module(permissiveapache, 1.0)
gen_require(`

Quoted 9 lines
	type httpd_t;

')
permissive httpd_t;

Obviously this syntax can be used in both the base policy and in a policy module.

Comments below, otherwise looks fine.

Quoted 15 lines

policy_parse.y static int define_polcap(void) · line 1025

Quoted 11 lines
policy_parse.y renamed from policy_parse.y.pre.permissive +11 -0
+static int define_permissive(void)
+{
+	char *type = NULL;
+	struct type_datum *t;
+
+	if (pass == 2) {
+		type = queue_remove(id_queue);
+		free(type);
+		return 0;
+	}
+

I think this should be pass == 1. It doesn't need to be on pass 1 since it won't be adding symbols needed for pass 2 and it makes it a little more resilient to ordering issues.

Makes sense.

Quoted 6 lines
Quoted 6 lines

diff -up checkpolicy-2.0.10/policy_scan.l.pre.permissive checkpolicy-2.0.10/policy_scan.l
--- checkpolicy-2.0.10/policy_scan.l.pre.permissive

2008-03-11 10:18:31.000000000 -0400

+++ checkpolicy-2.0.10/policy_scan.l 2008-03-11
10:19:00.000000000 -0400

Quoted 8 lines

policy_scan.l H1 { return(H1); } · line 205

Quoted 6 lines
policy_scan.l renamed from policy_scan.l.pre.permissive +1 -1
@@ -202,7 +202,9 @@ H1				{ return(H1); }
 h2 |
 H2				{ return(H2); }
 policycap |
-POLICYCAP			{ return(POLICYCAP);}
+POLICYCAP			{ return(POLICYCAP); }

Whitespace?

Yup, turns out I like consistency :)

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
In reply to Eric Paris
Quoted 60 lines · Eric Paris

This patch adds support for permissive types.

A very simple module to make httpd_t a permissive domain would be:

policy_module(permissiveapache, 1.0)
gen_require(`

	type httpd_t;

')
permissive httpd_t;

Obviously this syntax can be used in both the base policy and in a policy module.

---

 policy_parse.y |   43 +++++++++++++++++++++++++++++++
 policy_scan.l  |    4 ++
 test/dismod.c  |    2 -
 test/dispol.c  |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 125 insertions(+), 2 deletions(-)

diff -up checkpolicy-2.0.10/policy_parse.y.pre.permissive checkpolicy-2.0.10/policy_parse.y

policy_parse.y renamed from policy_parse.y.pre.permissive +5 -0
@@ -126,6 +126,7 @@ static int define_netif_context(void);
 static int define_ipv4_node_context(void);
 static int define_ipv6_node_context(void);
 static int define_polcap(void);
+static int define_permissive(void);
 
 typedef int (* require_func_t)();
 
@@ -201,6 +202,7 @@ typedef int (* require_func_t)();
 %token IPV6_ADDR
 %token MODULE VERSION_IDENTIFIER REQUIRE OPTIONAL
 %token POLICYCAP
+%token PERMISSIVE
 
 %left OR
 %left XOR
@@ -327,6 +329,7 @@ te_decl			: attribute_def
                         | transition_def
                         | range_trans_def
                         | te_avtab_def
+			| permissive_def
 			;
 attribute_def           : ATTRIBUTE identifier ';'
                         { if (define_attrib()) return -1;}
@@ -772,6 +775,8 @@ ipv6_addr		: IPV6_ADDR
 policycap_def		: POLICYCAP identifier ';'
 			{if (define_polcap()) return -1;}
 			;
+permissive_def		: PERMISSIVE identifier ';'
+			{if (define_permissive()) return -1;}
 
 /*********** module grammar below ***********/
 

policy_parse.y static int define_polcap(void) · line 1016

Quoted 5 lines
policy_parse.y renamed from policy_parse.y.pre.permissive +2 -0
@@ -1007,6 +1012,44 @@ static int define_polcap(void)
 	return -1;
 }
 
+static int define_permissive(void)
+{

The action functions have been moved out to a separate .c file (policy_define.[ch]) in the latest checkpolicy, so someone will have to move this over for merge. Trivial, of course.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.