Skip to contentSkip to conversation

2 checkpolicy bugs

DISCUSSION Russell Coker 3 participants 7 messages May 24, 2002 – Jun 6, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

If I don't assign SIDs to any TCP or UDP ports then I get the following checkpolicy error:

error in the statement ending on line 31779 (token 'system_u'): parse error

Line 31779 is the following:
lo system_u:object_r:netif_lo_t system_u:object_r:netmsg_lo_t

I consider that there are two bugs in checkpolicy, firstly it doesn't accept a valid configuration with no special SIDs assigned to any TCP or UDP ports. Secondly it doesn't give me an error message that is any good to inform me of this matter.

Currently to work around this matter I've assigned a type for port 1 (tcpmux) which is never used.

Signature · 9 lines
If you send email to me or to a mailing list that I use which has >4 lines
of legalistic junk at the end then you are specifically authorizing me to do
whatever I wish with the message and all other messages from your domain, by
posting the message you agree that your long legalistic sig is void.

--
You have received this message because you are subscribed to the selinux 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

I think it's because of the way checkpolicy validates policy.conf. If you look at policy_parse.y (in .../selinux/module/checkpolicy/), a "policy" is defined such that it must have "net_contexts". If you follow that through you find that there must be at least one of everything:

net_contexts : port_contexts netif_contexts node_contexts \
opt_nfs_contexts

So to be a "valid configuration" a policy must define all these parts.

Regarding the error message, I think it's just typical of most compiler/interpreter errors when you leave out a required piece of syntax.

I think the important issue is that in order to compile a "valid" policy you may have to add things that you don't require. In a sense this is allowing unnecessary permissions, violating the principle of least privilege.

David

Quoted 37 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Russell Coker
Sent: Friday, May 24, 2002 7:09 AM
To: SE Linux
Subject: 2 checkpolicy bugs

If I don't assign SIDs to any TCP or UDP ports then I get the following checkpolicy error:

error in the statement ending on line 31779 (token 'system_u'):
parse error

Line 31779 is the following:
lo system_u:object_r:netif_lo_t system_u:object_r:netmsg_lo_t

I consider that there are two bugs in checkpolicy, firstly it doesn't accept
a valid configuration with no special SIDs assigned to any TCP or UDP ports.
Secondly it doesn't give me an error message that is any good to inform me of
this matter.

Currently to work around this matter I've assigned a type for port 1 (tcpmux)
which is never used.

--
If you send email to me or to a mailing list that I use which has >4 lines of legalistic junk at the end then you are specifically authorizing me to do
whatever I wish with the message and all other messages from your domain, by
posting the message you agree that your long legalistic sig is void.

Quoted 7 lines

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 3 lines · David Caplan

I think the important issue is that in order to compile a "valid" policy you may have to add things that you don't require. In a sense this is allowing unnecessary permissions, violating the principle of least privilege.

I'm not sure that this is accurate. In the case of port contexts, you must have at least a single definition, but this definition can merely assign the default context system_u:object_r:port_t (that is associated with the 'port' initial SID) to a single port. Since that would be the default anyway, there is no real difference in the resulting configuration. No extra permissions would be granted by this "stub" entry.

Is there some other section that poses a "least privilege" problem because it must be included?

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux 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 Russell Coker
Quoted 8 lines · Russell Coker

If I don't assign SIDs to any TCP or UDP ports then I get the following checkpolicy error:

error in the statement ending on line 31779 (token 'system_u'): parse error

Line 31779 is the following:
lo system_u:object_r:netif_lo_t system_u:object_r:netmsg_lo_t

Quoted 7 lines

I consider that there are two bugs in checkpolicy, firstly it doesn't accept a valid configuration with no special SIDs assigned to any TCP or UDP ports. Secondly it doesn't give me an error message that is any good to inform me of this matter.

Currently to work around this matter I've assigned a type for port 1 (tcpmux) which is never used.

Yes, the current policy parser requires most "sections" to be present, rather than allowing them to be optional. Permitting most sections to be optional may require other changes in order to avoid ambiguities, but is a worthwhile goal. It is already on my TODO list, but not as a high priority.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
In reply to Russell Coker
Quoted 2 lines · Russell Coker

I consider that there are two bugs in checkpolicy, firstly it doesn't accept a valid configuration with no special SIDs assigned to any TCP or UDP ports.

I've attached a patch to checkpolicy and the example policy configuration that makes many of the policy components optional, and adds keywords as necessary to avoid ambiguities among the various kinds of context configurations. This patch has not yet been committed. Feedback is welcome.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: module/checkpolicy/policy_parse.y
===================================================================
RCS file: /cvs/lsm/selinux/module/checkpolicy/policy_parse.y,v retrieving revision 1.14

checkpolicy/policy_parse.y +48 -20
diff -u -r1.14 policy_parse.y
@@ -90,6 +90,7 @@
 %token SOURCE
 %token TARGET
 %token SAMEUSER
+%token FSCON DEVFSCON PORTCON NETIFCON NODECON NFSCON
 %token U1 U2 R1 R2 T1 T2
 %token NOT AND OR 
 %token IDENTIFIER
@@ -104,9 +105,9 @@
 %%
 policy			: classes initial_sids access_vectors 
                           { if (pass == 1) { if (policydb_index_classes(policydbp)) return -1; } }
-			  opt_mls te_rbac users constraints 
+			  opt_mls te_rbac users opt_constraints 
 			  { if (pass == 2) { if (policydb_index_others(policydbp)) return -1;} } 
-			  initial_sid_contexts fs_contexts devfs_contexts net_contexts 
+			  initial_sid_contexts opt_fs_contexts opt_devfs_contexts net_contexts 
 			;
 classes			: class_def 
 			| classes class_def
@@ -120,8 +121,11 @@
 initial_sid_def		: SID identifier
                         {if (define_initial_sid()) return -1;}
 			;
-access_vectors		: common_perms av_perms
+access_vectors		: opt_common_perms av_perms
 			;
+opt_common_perms        : common_perms
+                        |
+                        ;
 common_perms		: common_perms_def
 			| common_perms common_perms_def
 			;
@@ -141,7 +145,7 @@
 opt_mls			: mls
                         | 
 			;
-mls			: sensitivities dominance categories levels base_perms
+mls			: sensitivities dominance opt_categories levels base_perms
 			;
 sensitivities	 	: sensitivity_def 
 			| sensitivities sensitivity_def
@@ -158,6 +162,9 @@
                         | DOMINANCE '{' identifier_list '}' 
 			{if (define_dominance()) return -1;}
 			;
+opt_categories          : categories
+                        |
+                        ;
 categories 		: category_def 
 			| categories category_def
 			;
@@ -174,8 +181,11 @@
 			| LEVEL identifier ';' 
 			{if (define_level()) return -1;}
 			;
-base_perms		: common_base av_base
+base_perms		: opt_common_base av_base
 			;
+opt_common_base         : common_base
+                        |
+                        ;
 common_base		: common_base_def
 			| common_base common_base_def
 			;
@@ -271,6 +281,9 @@
 			| ROLE identifier_push '{' roles '}'
                         {$$ = (int) define_role_dom((role_datum_t*)$4); if ($$ == 0) return -1;}
 			;
+opt_constraints         : constraints
+                        |
+                        ;
 constraints		: constraint_def
 			| constraints constraint_def
 			;
@@ -373,33 +386,45 @@
 initial_sid_context_def	: SID identifier security_context_def
 			{if (define_initial_sid_context()) return -1;}
 			;
+opt_fs_contexts         : fs_contexts 
+                        |
+                        ;
 fs_contexts		: fs_context_def
 			| fs_contexts fs_context_def
 			;
-fs_context_def		: number number security_context_def security_context_def
-			{if (define_fs_context($1,$2)) return -1;}
+fs_context_def		: FSCON number number security_context_def security_context_def
+			{if (define_fs_context($2,$3)) return -1;}
 			;
-net_contexts		: port_contexts netif_contexts node_contexts opt_nfs_contexts
+net_contexts		: opt_port_contexts opt_netif_contexts opt_node_contexts opt_nfs_contexts
 			;
+opt_port_contexts       : port_contexts
+                        |
+                        ;
 port_contexts		: port_context_def
 			| port_contexts port_context_def
 			;
-port_context_def	: identifier number security_context_def
-			{if (define_port_context($2,$2)) return -1;}
-			| identifier number '-' number security_context_def
-			{if (define_port_context($2,$4)) return -1;}
+port_context_def	: PORTCON identifier number security_context_def
+			{if (define_port_context($3,$3)) return -1;}
+			| PORTCON identifier number '-' number security_context_def
+			{if (define_port_context($3,$5)) return -1;}
 			;
+opt_netif_contexts      : netif_contexts 
+                        |
+                        ;
 netif_contexts		: netif_context_def
 			| netif_contexts netif_context_def
 			;
-netif_context_def	: identifier security_context_def security_context_def
-			{if (define_netif_context()) return -1;}
+netif_context_def	: NETIFCON identifier security_context_def security_context_def
+			{if (define_netif_context()) return -1;} 
 			;
+opt_node_contexts       : node_contexts 
+                        |
+                        ;
 node_contexts		: node_context_def
 			| node_contexts node_context_def
 			;
-node_context_def	: ipv4_addr_def ipv4_addr_def security_context_def
-			{if (define_node_context($1,$2)) return -1;}
+node_context_def	: NODECON ipv4_addr_def ipv4_addr_def security_context_def
+			{if (define_node_context($2,$3)) return -1;}
 			;
 opt_nfs_contexts        : nfs_contexts
                         |
@@ -407,15 +432,18 @@
 nfs_contexts		: nfs_context_def
 			| nfs_contexts nfs_context_def
 			;
-nfs_context_def	        : ipv4_addr_def ipv4_addr_def security_context_def security_context_def
-			{if (define_nfs_context($1,$2)) return -1;}
+nfs_context_def	        : NFSCON ipv4_addr_def ipv4_addr_def security_context_def security_context_def
+			{if (define_nfs_context($2,$3)) return -1;}
 			;
+opt_devfs_contexts      : devfs_contexts
+                        | 
+                        ;
 devfs_contexts	        : devfs_context_def
 			| devfs_contexts devfs_context_def
 			;
-devfs_context_def	: path '-' identifier security_context_def
+devfs_context_def	: DEVFSCON path '-' identifier security_context_def
 			{if (define_devfs_context(1)) return -1;}
-                        | path security_context_def
+                        | DEVFSCON path security_context_def
 			{if (define_devfs_context(0)) return -1;}
 			;
 ipv4_addr_def		: number '.' number '.' number '.' number

Index: module/checkpolicy/policy_scan.l
===================================================================
RCS file: /cvs/lsm/selinux/module/checkpolicy/policy_scan.l,v retrieving revision 1.5

checkpolicy/policy_scan.l +12 -0
diff -u -r1.5 policy_scan.l
@@ -90,6 +90,18 @@
 DOMBY				{ return(DOMBY);}
 INCOMP |
 incomp				{ return(INCOMP);}
+fscon |
+FSCON                           { return(FSCON);}
+devfscon |
+DEVFSCON                        { return(DEVFSCON);}
+portcon |
+PORTCON                        { return(PORTCON);}
+netifcon |                     
+NETIFCON                       { return(NETIFCON);}
+nodecon |                     
+NODECON                       { return(NODECON);}
+nfscon |                     
+NFSCON                       { return(NFSCON);}
 r1 |
 R1				{ return(R1); }
 r2 |

Index: policy/devfs_contexts
===================================================================
RCS file: /cvs/lsm/selinux/policy/devfs_contexts,v retrieving revision 1.5

devfs_contexts +32 -32

69 lines not on this page · raw message

Index: policy/fs_contexts
===================================================================
RCS file: /cvs/lsm/selinux/policy/fs_contexts,v
retrieving revision 1.1.1.1

fs_contexts +1 -1
diff -u -r1.1.1.1 fs_contexts
@@ -7,6 +7,6 @@
 #
 # major minor fs_context default_file_context
 #
-3 2 system_u:object_r:fs_t system_u:object_r:file_t
+fscon 3 2 system_u:object_r:fs_t system_u:object_r:file_t
 
 # FLASK

Index: policy/net_contexts
===================================================================
RCS file: /cvs/lsm/selinux/policy/net_contexts,v
retrieving revision 1.7

net_contexts +24 -24

71 lines not on this page · raw message

#5 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 3 lines · Russell Coker

I consider that there are two bugs in checkpolicy, firstly it doesn't accept a valid configuration with no special SIDs assigned to any TCP or UDP ports.

I've attached a patch to checkpolicy and the example policy configuration that makes many of the policy components optional, and adds keywords as necessary to avoid ambiguities among the various kinds of context configurations. This patch has not yet been committed. Feedback is welcome.

This patch seems great to me! Having the labels at the start of each line makes a lot of sense and will make tracking problems easier.

What we need now is a patch to make it display entire lines of policy.conf on errors.

Signature · 3 lines
I do not get viruses because I do not use MS software.
If you use Outlook then please do not put my email address in your
address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line

From field.

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
Quoted 2 lines · Russell Coker

This patch seems great to me! Having the labels at the start of each line makes a lot of sense and will make tracking problems easier.

This patch has now been committed to the sourceforge CVS.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.