Add SELinux policy capability for always checking packet class.
PATCH 1/2 Add SELinux policy capability for always checking packet class.
Currently the packet class in SELinux is not checked if there are no SECMARK rules in the security or mangle netfilter tables. Some systems prefer that packets are always checked, for example, to protect the system should the netfilter rules fail to load or if the nefilter rules were maliciously flushed.
Add the always_check_network policy capability which, when enabled, treats SECMARK as enabled, even if there are no netfilter SECMARK rules.
--- security/selinux/hooks.c | 8 ++++++-- security/selinux/include/security.h | 2 ++ security/selinux/selinuxfs.c | 3 ++- security/selinux/ss/services.c | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-)
security/selinux/hooks.c +6 -2
@@ -137,12 +137,16 @@ static struct kmem_cache *sel_inode_cache;* This function checks the SECMARK reference counter to see if any SECMARK * targets are currently configured, if the reference counter is greater than * zero SECMARK is considered to be enabled. Returns true (1) if SECMARK is -* enabled, false (0) if SECMARK is disabled. +* enabled, false (0) if SECMARK is disabled. If the always_check_network +* policy capability is enabled, SECMARK is always considered enabled. * */ static int selinux_secmark_enabled (void ) { -return (atomic_read (&selinux_secmark_refcount) >0 ); +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (atomic_read (&selinux_secmark_refcount) >0 ); }/*
security/selinux/include/security.h +2 -0
@@ -68,12 +68,14 @@ extern int selinux_enabled;enum {POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , +POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm; +extern int selinux_policycap_alwaysnetwork;/* * type_datum properties
security/selinux/selinuxfs.c +2 -1
@@ -44,7 +44,8 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" , -"open_perms" +"open_perms" , +"always_check_network" };unsigned int selinux_checkreqprot =CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE ;
security/selinux/ss/services.c +3 -0
@@ -72,6 +72,7 @@int selinux_policycap_netpeer;int selinux_policycap_openperm; +int selinux_policycap_alwaysnetwork;static DEFINE_RWLOCK (policy_rwlock);
@@ -1812,6 +1813,8 @@ static void security_load_policycaps(void) POLICYDB_CAPABILITY_NETPEER); selinux_policycap_openperm =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_OPENPERM ); + selinux_policycap_alwaysnetwork =ebitmap_get_bit (&policydb.policycaps, +POLICYDB_CAPABILITY_ALWAYSNETWORK ); }static int security_preserve_bools (struct policydb *p);
Signature · 7 lines
1.7.8.6 -- 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.
PATCH 2/2 Update SELinux policy capability to always check peer class.
Update the always_check_network policy capability which, when enabled, treats peer labeling as enabled, even if there is no Netlabel or labeled IPSEC configuration.
--- security/selinux/hooks.c | 24 +++++++++++++++++++++--- 1 files changed, 21 insertions(+), 3 deletions(-)
security/selinux/hooks.c +21 -3
@@ -149,6 +149,24 @@ static int selinux_secmark_enabled(void)return (atomic_read (&selinux_secmark_refcount) >0 ); } +/** +* selinux_peerlbl_enabled - Check to see if peer labeling is currently enabled +* +* Description: +* This function checks if NetLabel or labeled IPSEC is enabled. Returns true +* (1) if any are enabled or false (0) if neither are enabled. If the +* always_check_network policy capability is enabled, peer labeling +* is always considered enabled. +* +*/ +static int selinux_peerlbl_enabled (void ) +{ +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (netlbl_enabled () ||selinux_xfrm_enabled ()); +} +/* * initialise the security for the init task */
@@ -4188,7 +4206,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)return selinux_sock_rcv_skb_compat (sk, skb, family); secmark_active =selinux_secmark_enabled (); - peerlbl_active =netlbl_enabled () ||selinux_xfrm_enabled (); + peerlbl_active =selinux_peerlbl_enabled ();if (!secmark_active && !peerlbl_active)return 0 ;
@@ -4540,7 +4558,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex, secmark_active =selinux_secmark_enabled (); netlbl_active =netlbl_enabled (); - peerlbl_active = netlbl_active ||selinux_xfrm_enabled (); + peerlbl_active =selinux_peerlbl_enabled ();if (!secmark_active && !peerlbl_active)return NF_ACCEPT ;
@@ -4692,7 +4710,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,return NF_ACCEPT ;#endif secmark_active =selinux_secmark_enabled (); - peerlbl_active =netlbl_enabled () ||selinux_xfrm_enabled (); + peerlbl_active =selinux_peerlbl_enabled ();if (!secmark_active && !peerlbl_active)return NF_ACCEPT ;
Signature · 7 lines
1.7.8.6 -- 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.
Paul Moore
maintainerRe: [PATCH 2/2] Update SELinux policy capability to always check peer class.
Quoted 5 lines · Chris PeBenito
Update the
always_check_networkpolicy capability which, when enabled, treats peer labeling as enabled, even if there is no Netlabel or labeled IPSEC configuration.Signed-off-by Chris PeBenito <[email protected]>
...
security/selinux/hooks.c static int selinux_secmark_enabled(void) · line 155
Quoted 12 lines
security/selinux/hooks.c +7
-0@@ -149,6 +149,24 @@ static int selinux_secmark_enabled(void) +static int selinux_peerlbl_enabled (void ) +{ +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (netlbl_enabled () ||selinux_xfrm_enabled ()); +}
Why not make this more consistent?
return (selinux_policycap_alwaysnetwork || ...
Signature · 8 lines
paul moore www.paul-moore.com -- 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.
Re: [PATCH 2/2] Update SELinux policy capability to always check peer class.
Quoted 24 lines · Paul Moore
Quoted 5 lines · Chris PeBenito
Update the
always_check_networkpolicy capability which, when enabled, treats peer labeling as enabled, even if there is no Netlabel or labeled IPSEC configuration.Signed-off-by Chris PeBenito <[email protected]>...
security/selinux/hooks.c static int selinux_secmark_enabled(void) · line 155
Quoted 12 lines
security/selinux/hooks.c +7
-0@@ -149,6 +149,24 @@ static int selinux_secmark_enabled(void) +static int selinux_peerlbl_enabled (void ) +{ +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (netlbl_enabled () ||selinux_xfrm_enabled ()); +}Why not make this more consistent?
Quoted 1 line
return (
selinux_policycap_alwaysnetwork|| ...
Same response as the other patch.
Signature · 8 lines
Chris PeBenito Tresys Technology, LLC www.tresys.com | oss.tresys.com -- 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.
Paul Moore
maintainerQuoted 10 lines · Chris PeBenito
Currently the packet class in SELinux is not checked if there are no SECMARK rules in the security or mangle netfilter tables. Some systems prefer that packets are always checked, for example, to protect the system should the netfilter rules fail to load or if the nefilter rules were maliciously flushed.
Add the
always_check_networkpolicy capability which, when enabled, treats SECMARK as enabled, even if there are no netfilter SECMARK rules.Signed-off-by Chris PeBenito <[email protected]>
...
Quoted 4 lines
security/selinux/hooks.c +0
-0
...
security/selinux/hooks.c static struct kmem_cache *sel_inode_cache; · line 150
Quoted 8 lines
static int
selinux_secmark_enabled(void)
{security/selinux/hooks.c +4
-1-return (atomic_read (&selinux_secmark_refcount) >0 ); +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (atomic_read (&selinux_secmark_refcount) >0 ); }
Nit picky, but why not simply:
return (selinux_policycap_alwaysnetwork || atomic_read( ...
Quoted 7 lines
/*
(quoted diff) +0
-0
b/security/selinux/include/security.hindex dde2005..981c4ac 100644security/selinux/include/security.h +0
-0@@ -68,12 +68,14 @@ extern int selinux_enabled;enum {
security/selinux/include/security.h extern int selinux_enabled; · line 78
Quoted 10 lines
security/selinux/include/security.h +2
-0POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , +POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm; +extern int selinux_policycap_alwaysnetwork;
Also nit picky, but it would seem like "selinux_policycap_netalways" is a bit more consistent with the other variables.
security/selinux/selinuxfs.c line 49
Quoted 12 lines
security/selinux/selinuxfs.c +2
-1@@ -44,7 +44,8 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" , -"open_perms" +"open_perms" , +"always_check_network" };
Similarly, I think "network_always" is more consistent.
security/selinux/ss/services.c line 75
Quoted 9 lines
a/security/selinux/ss/services.cb/security/selinux/ss/services.cindex 4321b8f..e124d8f 100644security/selinux/ss/services.c +1
-0@@ -72,6 +72,7 @@int selinux_policycap_netpeer;int selinux_policycap_openperm; +int selinux_policycap_alwaysnetwork;
See above.
Signature · 8 lines
paul moore www.paul-moore.com -- 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.
Quoted 32 lines · Paul Moore
Quoted 10 lines · Chris PeBenito
Currently the packet class in SELinux is not checked if there are no SECMARK rules in the security or mangle netfilter tables. Some systems prefer that packets are always checked, for example, to protect the system should the netfilter rules fail to load or if the nefilter rules were maliciously flushed.
Add the
always_check_networkpolicy capability which, when enabled, treats SECMARK as enabled, even if there are no netfilter SECMARK rules.Signed-off-by Chris PeBenito <[email protected]>...
Quoted 4 lines
security/selinux/hooks.c +0
-0...
security/selinux/hooks.c static struct kmem_cache *sel_inode_cache; · line 150
Quoted 8 lines
static int
selinux_secmark_enabled(void)
{security/selinux/hooks.c +4
-1-return (atomic_read (&selinux_secmark_refcount) >0 ); +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (atomic_read (&selinux_secmark_refcount) >0 ); }Nit picky, but why not simply:
Quoted 1 line
return (
selinux_policycap_alwaysnetwork|| atomic_read( ...
Sure it can be done that way, but I'd argue that the intent is clearer the way its implemented in the patch.
Quoted 14 lines
Quoted 14 lines
/*
(quoted diff) +0
-0
b/security/selinux/include/security.hindex dde2005..981c4ac 100644security/selinux/include/security.h +1
-0@@ -68,12 +68,14 @@ extern int selinux_enabled;enum {POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , +POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
Quoted 6 lines
security/selinux/include/security.h extern int selinux_enabled; · line 78
Quoted 3 lines
security/selinux/include/security.h +1
-0extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm; +extern int selinux_policycap_alwaysnetwork;Also nit picky, but it would seem like "
selinux_policycap_netalways" is a bit more consistent with the other variables.
This response stems on what you wrote on a later cunch about the capability name, so you should probably read below first.
I don't agree. If you go by current capabilities names/variables, based on the ordering of the words in the capability name, the words in the variable are in the same order. e.g.
NETwork_PEER_controls -> selinux_policycap_netpeer OPEN_PERMs -> selinux_policycap_openperm
hence
ALWAYS_check_NETWORK -> selinux_policycap_alwaysnetwork
Quoted 6 lines
Quoted 6 lines
security/selinux/selinuxfs.c +0
-0@@ -44,7 +44,8 @@/* Policy capability filenames */
Quoted 8 lines
security/selinux/selinuxfs.c line 49
Quoted 6 lines
security/selinux/selinuxfs.c +2
-1static char *policycap_names[] = {"network_peer_controls" , -"open_perms" +"open_perms" , +"always_check_network" };Similarly, I think "
network_always" is more consistent.
Earlier discussions concluded with this capability name. (to be specific the discussion resolved with always_check_packets, but that was before the peer class was included)
Signature · 8 lines
Chris PeBenito Tresys Technology, LLC www.tresys.com | oss.tresys.com -- 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.
Paul Moore
maintainerQuoted 11 lines · Christopher J. PeBenito
Quoted 10 lines · Paul Moore
Quoted 9 lines · Chris PeBenito
static int
selinux_secmark_enabled(void)
{security/selinux/hooks.c +4
-1-return (atomic_read (&selinux_secmark_refcount) >0 ); +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (atomic_read (&selinux_secmark_refcount) >0 );
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
}
Nit picky, but why not simply:
return (selinux_policycap_alwaysnetwork|| atomic_read( ...Sure it can be done that way, but I'd argue that the intent is clearer the way its implemented in the patch.
It looks very hacky and inconsistent to me.
Oh well, you can sort it out with Eric.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
(quoted diff) +0
-0
b/security/selinux/include/security.hindex dde2005..981c4ac 100644security/selinux/include/security.h +1
-0@@ -68,12 +68,14 @@ extern int selinux_enabled;enum {POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , +POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+extern int
selinux_policycap_alwaysnetwork;Also nit picky, but it would seem like "
selinux_policycap_netalways" is a bit more consistent with the other variables.This response stems on what you wrote on a later cunch about the capability name, so you should probably read below first.
What?
I don't believe I ever commented on the capability names until now, please correct me with a link to the archives if I'm mistaken.
Quoted 10 lines
I don't agree. If you go by current capabilities names/variables, based on the ordering of the words in the capability name, the words in the variable are in the same order. e.g.
NETwork_PEER_controls->selinux_policycap_netpeerOPEN_PERMs->selinux_policycap_openpermhence
ALWAYS_check_NETWORK->selinux_policycap_alwaysnetwork
I look at it as a bit of "namespacing" ... "netpeer" enables the network peer controls, "openperm" affects the open permission. Since this capability affects the network controls I believe "netalways" makes more sense.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
security/selinux/selinuxfs.c +2
-1@@ -44,7 +44,8 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" , -"open_perms" +"open_perms" , +"always_check_network"
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
};
Similarly, I think "
network_always" is more consistent.Earlier discussions concluded with this capability name. (to be specific the discussion resolved with
always_check_packets, but that was before the peer class was included)
Once again, I don't believe I ever commented on the name of the capability, but I am now. Disregard my comments or incorporate them, that is up to you, and ultimately Eric, to decide.
Signature · 8 lines
paul moore www.paul-moore.com -- 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.
Quoted 21 lines · Paul Moore
Quoted 19 lines · Christopher J. PeBenito
Quoted 18 lines
Quoted 15 lines
security/selinux/selinuxfs.c +2
-1@@ -44,7 +44,8 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" , -"open_perms" +"open_perms" , +"always_check_network" Quoted 1 line
};
Similarly, I think "
network_always" is more consistent.
Quoted 7 lines
Quoted 3 lines
Earlier discussions concluded with this capability name. (to be specific the discussion resolved with
always_check_packets, but that was before the peer class was included)Once again, I don't believe I ever commented on the name of the capability, but I am now. Disregard my comments or incorporate them, that is up to you, and ultimately Eric, to decide.
My apologies, you did not comment on the capability name in the previous thread.
Signature · 8 lines
Chris PeBenito Tresys Technology, LLC www.tresys.com | oss.tresys.com -- 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.
Quoted 30 lines · Christopher J. PeBenito
Quoted 29 lines · Paul Moore
Quoted 10 lines · Chris PeBenito
Currently the packet class in SELinux is not checked if there are no SECMARK rules in the security or mangle netfilter tables. Some systems prefer that packets are always checked, for example, to protect the system should the netfilter rules fail to load or if the nefilter rules were maliciously flushed.
Add the
always_check_networkpolicy capability which, when enabled, treats SECMARK as enabled, even if there are no netfilter SECMARK rules.Signed-off-by Chris PeBenito <[email protected]>...
Quoted 4 lines
security/selinux/hooks.c +0
-0...
security/selinux/hooks.c static struct kmem_cache *sel_inode_cache; · line 150
Quoted 8 lines
static int
selinux_secmark_enabled(void)
{security/selinux/hooks.c +4
-1-return (atomic_read (&selinux_secmark_refcount) >0 ); +if (selinux_policycap_alwaysnetwork) +return 1 ; +else +return (atomic_read (&selinux_secmark_refcount) >0 ); }Nit picky, but why not simply:
Quoted 2 lines
Quoted 1 line
return (
selinux_policycap_alwaysnetwork|| atomic_read( ...Sure it can be done that way, but I'd argue that the intent is clearer the way its implemented in the patch.
Oh come on, no one does
if (...)
return x;
else
return y;Much better to do
if (...)
return x;
return y;The else is unnecessary.
Quoted 45 lines
Quoted 16 lines
Quoted 16 lines
/*
(quoted diff) +0
-0
b/security/selinux/include/security.hindex dde2005..981c4ac 100644security/selinux/include/security.h +1
-0@@ -68,12 +68,14 @@ extern int selinux_enabled;enum {POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , +POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)Quoted 5 lines
security/selinux/include/security.h extern int selinux_enabled; · line 78
Quoted 3 lines
security/selinux/include/security.h +1
-0extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm; +extern int selinux_policycap_alwaysnetwork;Also nit picky, but it would seem like "
selinux_policycap_netalways" is a bit more consistent with the other variables.This response stems on what you wrote on a later cunch about the capability name, so you should probably read below first.
I don't agree. If you go by current capabilities names/variables, based on the ordering of the words in the capability name, the words in the variable are in the same order. e.g.
NETwork_PEER_controls->selinux_policycap_netpeerOPEN_PERMs->selinux_policycap_openpermhence
ALWAYS_check_NETWORK->selinux_policycap_alwaysnetworkQuoted 5 lines
Quoted 5 lines
security/selinux/selinuxfs.c +0
-0@@ -44,7 +44,8 @@Quoted 8 lines
security/selinux/selinuxfs.c line 49
Quoted 7 lines
security/selinux/selinuxfs.c +2
-1/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" , -"open_perms" +"open_perms" , +"always_check_network" };Similarly, I think "
network_always" is more consistent.
Quoted 3 lines
Earlier discussions concluded with this capability name. (to be specific the discussion resolved with
always_check_packets, but that was before the peer class was included)
--
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.