Update to the labeled networking patches for 2.6.25
Subsystems (7)
RFC PATCH v8 2/18 NetLabel: Cleanup the LSM domain hash functions
In reply to Paul MooreThe NetLabel/LSM domain hash table search function used an argument to specify if the default entry should be returned if an exact match couldn't be found in the hash table. This is a bit against the kernel's style so make two separate functions to represent the separate behaviors.
---
net/netlabel/netlabel_domainhash.c | 47 ++++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 13 deletions(-)
net/netlabel/netlabel_domainhash.c +34 -13
@@ -109,17 +109,14 @@ static u32 netlbl_domhsh_hash(const char *key)/** * netlbl_domhsh_search - Search for a domain entry * @domain: the domain -* @def: return default if no match is found * * Description: * Searches the domain hash table and returns a pointer to the hash table -* entry if found, otherwise NULL is returned. If @def is non-zero and a -* match is not found in the domain hash table the default mapping is returned -* if it exists. The caller is responsibile for the rcu hash table locks -* (i.e. the caller much call rcu_read_[un]lock()). +* entry if found, otherwise NULL is returned. The caller is responsibile for +* the rcu hash table locks (i.e. the caller much call rcu_read_[un]lock()). * */ -static struct netlbl_dom_map *netlbl_domhsh_search (const char *domain,u32 def) +static struct netlbl_dom_map *netlbl_domhsh_search (const char *domain) {u32 bkt;struct netlbl_dom_map *iter;
@@ -133,10 +130,31 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, u32 def)return iter; } -if (def !=0 ) { - iter =rcu_dereference (netlbl_domhsh_def); -if (iter !=NULL && iter->valid) -return iter; +return NULL ; +} + +/** +* netlbl_domhsh_search_def - Search for a domain entry +* @domain: the domain +* @def: return default if no match is found +* +* Description: +* Searches the domain hash table and returns a pointer to the hash table +* entry if an exact match is found, if an exact match is not present in the +* hash table then the default entry is returned if valid otherwise NULL is +* returned. The caller is responsibile for the rcu hash table locks +* (i.e. the caller much call rcu_read_[un]lock()). +* +*/ +static struct netlbl_dom_map *netlbl_domhsh_search_def (const char *domain) +{ +struct netlbl_dom_map *entry; + + entry =netlbl_domhsh_search (domain); +if (entry ==NULL ) { + entry =rcu_dereference (netlbl_domhsh_def); +if (entry !=NULL && entry->valid) +return entry; }return NULL ;
@@ -224,7 +242,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,if (entry->domain !=NULL ) { bkt =netlbl_domhsh_hash (entry->domain);spin_lock (&netlbl_domhsh_lock); -if (netlbl_domhsh_search (entry->domain,0 ) ==NULL ) +if (netlbl_domhsh_search (entry->domain) ==NULL )list_add_tail_rcu (&entry->list, &rcu_dereference (netlbl_domhsh)->tbl[bkt]);else
@@ -307,7 +325,10 @@ int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info)struct audit_buffer *audit_buf;rcu_read_lock (); - entry =netlbl_domhsh_search (domain, (domain !=NULL ?0 :1 )); +if (domain) + entry =netlbl_domhsh_search (domain); +else + entry =netlbl_domhsh_search_def (domain);if (entry ==NULL ) goto remove_return;switch (entry->type) {
@@ -377,7 +398,7 @@ int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info)*/ struct netlbl_dom_map *netlbl_domhsh_getentry (const char *domain) { -return netlbl_domhsh_search (domain,1 ); +return netlbl_domhsh_search_def (domain); }/**
--
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.
RFC PATCH v8 12/18 SELinux: Add new peer permissions to the Flask definitions
In reply to Paul MooreAdd additional Flask definitions to support the new "peer" object class.
---
security/selinux/include/av_perm_to_string.h | 3 +++ security/selinux/include/av_permissions.h | 3 +++ security/selinux/include/class_to_string.h | 7 +++++++ security/selinux/include/flask.h | 1 + 4 files changed, 14 insertions(+), 0 deletions(-)
security/selinux/include/av_perm_to_string.h +3 -0
@@ -159,3 +159,6 @@ S_(SECCLASS_DCCP_SOCKET, DCCP_SOCKET__NODE_BIND, "node_bind") S_(SECCLASS_DCCP_SOCKET, DCCP_SOCKET__NAME_CONNECT, "name_connect") S_(SECCLASS_MEMPROTECT, MEMPROTECT__MMAP_ZERO, "mmap_zero") + S_(SECCLASS_PEER, PEER__INGRESS, "ingress") + S_(SECCLASS_PEER, PEER__EGRESS, "egress") +S_ (SECCLASS_PEER ,PEER__RECV ,"recv" )
security/selinux/include/av_permissions.h +3 -0
@@ -824,3 +824,6 @@#define DCCP_SOCKET__NODE_BIND 0x00400000UL#define DCCP_SOCKET__NAME_CONNECT 0x00800000UL#define MEMPROTECT__MMAP_ZERO 0x00000001UL +#define PEER__INGRESS 0x00000001UL +#define PEER__EGRESS 0x00000002UL +#define PEER__RECV 0x00000004UL
security/selinux/include/class_to_string.h +7 -0
@@ -64,3 +64,10 @@ S_(NULL) S_("dccp_socket") S_("memprotect") + S_(NULL) + S_(NULL) + S_(NULL) + S_(NULL) + S_(NULL) + S_(NULL) + S_("peer")
security/selinux/include/flask.h +1 -0
@@ -50,6 +50,7 @@#define SECCLASS_KEY 58#define SECCLASS_DCCP_SOCKET 60#define SECCLASS_MEMPROTECT 61 +#define SECCLASS_PEER 68/* * Security identifier indices for initial entities
--
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.
RFC PATCH v8 9/18 SELinux: Only store the network interface's ifindex
In reply to Paul MooreInstead of storing the packet's network interface name store the ifindex. This allows us to defer the need to lookup the net_device structure until the audit record is generated meaning that in the majority of cases we never need to bother with this at all.
---
security/selinux/avc.c | 15 ++++++++++++--- security/selinux/hooks.c | 4 ++-- security/selinux/include/avc.h | 7 +++++-- 3 files changed, 19 insertions(+), 7 deletions(-)
security/selinux/avc.c +12 -3
@@ -661,9 +661,18 @@ void avc_audit(u32 ssid, u32 tsid, "daddr", "dest");break ; } -if (a->u.net.netif) -audit_log_format (ab," netif=%s" , - a->u.net.netif); +if (a->u.net.netif >=0 ) { +struct net_device *dev; + +/* NOTE: we always use init's namespace */ + dev =dev_get_by_index (&init_net, + a->u.net.netif); +if (dev) { +audit_log_format (ab," netif=%s" , + dev->name); +dev_put (dev); + } + }break ; } }
security/selinux/hooks.c +2 -2
@@ -3691,7 +3691,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) family =PF_INET ;AVC_AUDIT_DATA_INIT (&ad,NET ); - ad.u.net.netif = skb->dev ? skb->dev->name :"[unknown]" ; + ad.u.net.netif = skb->iif; ad.u.net.family = family; err =selinux_parse_skb (skb, &ad, &addrp, &len,1 ,NULL );
@@ -4023,7 +4023,7 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, sksec = sk->sk_security;AVC_AUDIT_DATA_INIT (&ad,NET ); - ad.u.net.netif = dev->name; + ad.u.net.netif = dev->ifindex; ad.u.net.family = family; err =selinux_parse_skb (skb, &ad, &addrp, &len,0 , &proto);
security/selinux/include/avc.h +5 -2
@@ -51,7 +51,7 @@ struct avc_audit_data {struct inode *inode; } fs;struct { -char *netif; +int netif;struct sock *sk;u16 family;__be16 dport;
@@ -77,7 +77,10 @@ struct avc_audit_data {/* Initialize an AVC audit data structure. */ #define AVC_AUDIT_DATA_INIT (_d,_t) \ - { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; } + { memset((_d), 0, sizeof(struct avc_audit_data)); \ + (_d)->type = AVC_AUDIT_DATA_##_t; \ + if ((_d)->type == AVC_AUDIT_DATA_NET) \ + (_d)->u.net.netif = -1; }/* * AVC statistics
--
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.
v8 cover Update to the labeled networking patches for 2.6.25
Another update to the labeled networking patchset, the lblnet-2.6_testing git tree on infradead.org has been updated too for those of you who prefer to get the changes that way.
With this version of the patchset I'm now considering the patches "feature complete" for 2.6.25. However, the push to get the features done in time has meant that my testing has been, and continues to be, pretty light so please don't consider this patch ready for inclusion anywhere yet. I'm posting these changes for people to review and test.
Since v7 there have been quite a few changes, although they have all been in support of the big change - packet ingress/egress controls (formerly know as "flow controls" to some SELinux folks). This should allow SELinux (and other LSMs) to provide packet level access control to all IP traffic entering and leaving the system. The two other big changes, the shift from skb->dev to skb->iif and the SELinux network node caching mechanism, are in support of these new controls although other aspects of the SELinux code benefit as well (check out the patches).
Comments are always welcome and people willing to help test are even more welcome. I'll get some SELinux policy patches out next week to help enable the new functionality and if everything is still looking okay I'll ping Andew Morton to see if I can get the latest version of these patches included in the -mm tree (previous versions are already included).
Thanks.
Signature · 8 lines
paul moore linux security @ hp -- 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.
RFC PATCH v8 1/18 NetLabel: Remove unneeded RCU read locks
This patch removes some unneeded RCU read locks as we can treat the reads as "safe" even without RCU. It also converts the NetLabel configuration refcount from a spinlock protected u32 into atomic_t to be more consistent with the rest of the kernel.
---
net/netlabel/netlabel_cipso_v4.c | 5 ++- net/netlabel/netlabel_kapi.c | 3 +- net/netlabel/netlabel_mgmt.c | 63 ++----------------------------------- net/netlabel/netlabel_mgmt.h | 7 ++-- net/netlabel/netlabel_unlabeled.c | 17 ++-------- 5 files changed, 15 insertions(+), 80 deletions(-)
net/netlabel/netlabel_cipso_v4.c +3 -2
@@ -38,6 +38,7 @@#include <net/genetlink.h> #include <net/netlabel.h> #include <net/cipso_ipv4.h> +#include <asm/atomic.h> #include "netlabel_user.h" #include "netlabel_cipso_v4.h"
@@ -421,7 +422,7 @@ static int netlbl_cipsov4_add(struct sk_buff *skb, struct genl_info *info)break ; }if (ret_val ==0 ) -netlbl_mgmt_protocount_inc (); +atomic_inc (&netlabel_mgmt_protocount); audit_buf =netlbl_audit_start_common (AUDIT_MAC_CIPSOV4_ADD , &audit_info);
@@ -698,7 +699,7 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info) &audit_info, netlbl_cipsov4_doi_free);if (ret_val ==0 ) -netlbl_mgmt_protocount_dec (); +atomic_dec (&netlabel_mgmt_protocount); audit_buf =netlbl_audit_start_common (AUDIT_MAC_CIPSOV4_DEL , &audit_info);
net/netlabel/netlabel_kapi.c +2 -1
@@ -34,6 +34,7 @@#include <net/netlabel.h> #include <net/cipso_ipv4.h> #include <asm/bug.h> +#include <asm/atomic.h> #include "netlabel_domainhash.h" #include "netlabel_unlabeled.h"
@@ -262,7 +263,7 @@ int netlbl_enabled(void)/* At some point we probably want to expose this mechanism to the user * as well so that admins can toggle NetLabel regardless of the * configuration */ -return (netlbl_mgmt_protocount_value () >0 ?1 :0 ); +return (atomic_read (&netlabel_mgmt_protocount) >0 ); }/**
net/netlabel/netlabel_mgmt.c +3 -60
80 lines not on this page · raw message
net/netlabel/netlabel_mgmt.h +3 -4
@@ -32,6 +32,7 @@#define _NETLABEL_MGMT_H#include <net/netlabel.h> +#include <asm/atomic.h> /* * The following NetLabel payloads are supported by the management interface.
@@ -168,9 +169,7 @@ enum {/* NetLabel protocol functions */ int netlbl_mgmt_genl_init (void ); -/* NetLabel misc management functions */ -void netlbl_mgmt_protocount_inc (void ); -void netlbl_mgmt_protocount_dec (void ); -u32 netlbl_mgmt_protocount_value (void ); +/* NetLabel configured protocol reference counter */ +extern atomic_t netlabel_mgmt_protocount;#endif
net/netlabel/netlabel_unlabeled.c +4 -13
@@ -155,11 +155,9 @@ static int netlbl_unlabel_list(struct sk_buff *skb, struct genl_info *info) goto list_failure; } -rcu_read_lock (); ret_val =nla_put_u8 (ans_skb,NLBL_UNLABEL_A_ACPTFLG , netlabel_unlabel_acceptflg); -rcu_read_unlock ();if (ret_val !=0 ) goto list_failure;
@@ -245,17 +243,10 @@ int netlbl_unlabel_genl_init(void)*/ int netlbl_unlabel_getattr (struct netlbl_lsm_secattr *secattr) { -int ret_val; - -rcu_read_lock (); -if (netlabel_unlabel_acceptflg ==1 ) { -netlbl_secattr_init (secattr); - ret_val =0 ; - }else - ret_val = -ENOMSG ; -rcu_read_unlock (); - -return ret_val; +if (netlabel_unlabel_acceptflg ==0 ) +return -ENOMSG ; +netlbl_secattr_init (secattr); +return 0 ; }/**
--
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.
RFC PATCH v8 3/18 NetLabel: Consolidate the LSM domain mapping/hashing locks
In reply to Paul MooreCurrently we use two separate spinlocks to protect both the hash/mapping table and the default entry. This could be considered a bit foolish because it adds complexity without offering any real performance advantage. This patch removes the dedicated default spinlock and protects the default entry with the hash/mapping table spinlock.
---
net/netlabel/netlabel_domainhash.c | 30 +++++++++--------------------- 1 files changed, 9 insertions(+), 21 deletions(-)
net/netlabel/netlabel_domainhash.c +9 -21
@@ -54,9 +54,6 @@ struct netlbl_domhsh_tbl {* hash table should be okay */ static DEFINE_SPINLOCK (netlbl_domhsh_lock);static struct netlbl_domhsh_tbl *netlbl_domhsh =NULL ; - -/* Default domain mapping */ -static DEFINE_SPINLOCK (netlbl_domhsh_def_lock);static struct netlbl_dom_map *netlbl_domhsh_def =NULL ;/*
@@ -239,24 +236,22 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,INIT_RCU_HEAD (&entry->rcu);rcu_read_lock (); +spin_lock (&netlbl_domhsh_lock);if (entry->domain !=NULL ) { bkt =netlbl_domhsh_hash (entry->domain); -spin_lock (&netlbl_domhsh_lock);if (netlbl_domhsh_search (entry->domain) ==NULL )list_add_tail_rcu (&entry->list, &rcu_dereference (netlbl_domhsh)->tbl[bkt]);else ret_val = -EEXIST ; -spin_unlock (&netlbl_domhsh_lock); }else {INIT_LIST_HEAD (&entry->list); -spin_lock (&netlbl_domhsh_def_lock);if (rcu_dereference (netlbl_domhsh_def) ==NULL )rcu_assign_pointer (netlbl_domhsh_def, entry);else ret_val = -EEXIST ; -spin_unlock (&netlbl_domhsh_def_lock); } +spin_unlock (&netlbl_domhsh_lock); audit_buf =netlbl_audit_start_common (AUDIT_MAC_MAP_ADD , audit_info);if (audit_buf !=NULL ) { audit_log_format(audit_buf,
@@ -337,23 +332,16 @@ int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info) entry->domain);break ; } -if (entry !=rcu_dereference (netlbl_domhsh_def)) { -spin_lock (&netlbl_domhsh_lock); -if (entry->valid) { - entry->valid =0 ; +spin_lock (&netlbl_domhsh_lock); +if (entry->valid) { + entry->valid =0 ; +if (entry !=rcu_dereference (netlbl_domhsh_def))list_del_rcu (&entry->list); - ret_val =0 ; - } -spin_unlock (&netlbl_domhsh_lock); - }else { -spin_lock (&netlbl_domhsh_def_lock); -if (entry->valid) { - entry->valid =0 ; +else rcu_assign_pointer (netlbl_domhsh_def,NULL ); - ret_val =0 ; - } -spin_unlock (&netlbl_domhsh_def_lock); + ret_val =0 ; } +spin_unlock (&netlbl_domhsh_lock); audit_buf =netlbl_audit_start_common (AUDIT_MAC_MAP_DEL , audit_info);if (audit_buf !=NULL ) {
--
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.
RFC PATCH v8 5/18 LSM: Add secctx_to_secid() LSM hook
In reply to Paul MooreAdd a secctx_to_secid() LSM hook to go along with the existing secid_to_secctx() LSM hook. This patch also includes the SELinux implementation for this hook.
---
include/linux/security.h | 13 +++++++++++++ security/dummy.c | 6 ++++++ security/security.c | 6 ++++++ security/selinux/hooks.c | 6 ++++++ 4 files changed, 31 insertions(+), 0 deletions(-)
include/linux/security.h +13 -0
@@ -1183,6 +1183,10 @@ struct request_sock;* Convert secid to security context. * @secid contains the security ID. * @secdata contains the pointer that stores the converted security context. +* @secctx_to_secid: +* Convert security context to secid. +* @secid contains the pointer to the generated security ID. +* @secdata contains the security context. * * @release_secctx: * Release the security context.
@@ -1371,6 +1375,7 @@ struct security_operations {int (*getprocattr)(struct task_struct *p,char *name,char **value);int (*setprocattr)(struct task_struct *p,char *name,void *value,size_t size);int (*secid_to_secctx)(u32 secid,char **secdata,u32 *seclen); +int (*secctx_to_secid)(char *secdata,u32 seclen,u32 *secid);void (*release_secctx)(char *secdata,u32 seclen);#ifdef CONFIG_SECURITY_NETWORK
@@ -1603,6 +1608,7 @@ int security_setprocattr(struct task_struct *p, char *name, void *value, size_tint security_netlink_send (struct sock *sk,struct sk_buff *skb);int security_netlink_recv (struct sk_buff *skb,int cap);int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen); +int security_secctx_to_secid (char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen);#else /* CONFIG_SECURITY */
@@ -2280,6 +2286,13 @@ static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclereturn -EOPNOTSUPP ; } +static inline int security_secctx_to_secid (char *secdata, +u32 seclen, +u32 *secid) +{ +return -EOPNOTSUPP ; +} +static inline void security_release_secctx (char *secdata,u32 seclen) { }
security/dummy.c +6 -0
@@ -928,6 +928,11 @@ static int dummy_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)return -EOPNOTSUPP ; } +static int dummy_secctx_to_secid (char *secdata,u32 seclen,u32 *secid) +{ +return -EOPNOTSUPP ; +} +static void dummy_release_secctx (char *secdata,u32 seclen) { }
@@ -1086,6 +1091,7 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, getprocattr);set_to_dummy_if_null (ops, setprocattr);set_to_dummy_if_null (ops, secid_to_secctx); +set_to_dummy_if_null (ops, secctx_to_secid);set_to_dummy_if_null (ops, release_secctx);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);
security/security.c +6 -0
@@ -816,6 +816,12 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) }EXPORT_SYMBOL (security_secid_to_secctx); +int security_secctx_to_secid (char *secdata,u32 seclen,u32 *secid) +{ +return security_ops->secctx_to_secid (secdata, seclen, secid); +} +EXPORT_SYMBOL (security_secctx_to_secid); +void security_release_secctx (char *secdata,u32 seclen) {return security_ops->release_secctx (secdata, seclen);
security/selinux/hooks.c +6 -0
@@ -4710,6 +4710,11 @@ static int selinux_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)return security_sid_to_context (secid, secdata, seclen); } +static int selinux_secctx_to_secid (char *secdata,u32 seclen,u32 *secid) +{ +return security_context_to_sid (secdata, seclen, secid); +} +static void selinux_release_secctx (char *secdata,u32 seclen) {kfree (secdata);
@@ -4898,6 +4903,7 @@ static struct security_operations selinux_ops = { .setprocattr = selinux_setprocattr, .secid_to_secctx = selinux_secid_to_secctx, + .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx, .unix_stream_connect = selinux_socket_unix_stream_connect,
--
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.
RFC PATCH v8 14/18 SELinux: Enable dynamic enable/disable of the network access checks
In reply to Paul MooreThis patch introduces a mechanism for checking when labeled IPsec or SECMARK are in use by keeping introducing a configuration reference counter for each subsystem. In the case of labeled IPsec, whenever a labeled SA or SPD entry is created the labeled IPsec/XFRM reference count is increased and when the entry is removed it is decreased. In the case of SECMARK, when a SECMARK target is created the reference count is increased and later decreased when the target is removed. These reference counters allow SELinux to quickly determine if either of these subsystems are enabled.
NetLabel already has a similar mechanism which provides the netlbl_enabled() function.
This patch also renames the selinux_relabel_packet_permission() function to selinux_secmark_relabel_packet_permission() as the original name and description were misleading in that they referenced a single packet label which is not the case.
---
include/linux/selinux.h | 45 +++++++++++++++++++++++++++++++------- net/netfilter/xt_SECMARK.c | 13 ++++++++++- security/selinux/exports.c | 20 +++++++++++++++-- security/selinux/hooks.c | 46 +++++++++++++++++++++++++++++++-------- security/selinux/include/xfrm.h | 12 ++++++++++ security/selinux/xfrm.c | 18 ++++++++++++++- 6 files changed, 132 insertions(+), 22 deletions(-)
include/linux/selinux.h +37 -8
@@ -120,16 +120,35 @@ void selinux_get_task_sid(struct task_struct *tsk, u32 *sid);int selinux_string_to_sid (char *str,u32 *sid);/** -* selinux_relabel_packet_permission - check permission to relabel a packet -* @sid: ID value to be applied to network packet (via SECMARK, most likely) +* selinux_secmark_relabel_packet_permission - secmark permission check +* @sid: SECMARK ID value to be applied to network packet * -* Returns 0 if the current task is allowed to label packets with the -* supplied security ID. Note that it is implicit that the packet is always -* being relabeled from the default unlabled value, and that the access -* control decision is made in the AVC. +* Returns 0 if the current task is allowed to set the SECMARK label of +* packets with the supplied security ID. Note that it is implicit that +* the packet is always being relabeled from the default unlabeled value, +* and that the access control decision is made in the AVC. */ -int selinux_relabel_packet_permission (u32 sid); +int selinux_secmark_relabel_packet_permission (u32 sid); +/** +* selinux_secmark_refcount_inc - increments the secmark use counter +* +* SELinux keeps track of the current SECMARK targets in use so it knows +* when to apply SECMARK label access checks to network packets. This +* function incements this reference count to indicate that a new SECMARK +* target has been configured. +*/ +void selinux_secmark_refcount_inc (void ); + +/** +* selinux_secmark_refcount_dec - decrements the secmark use counter +* +* SELinux keeps track of the current SECMARK targets in use so it knows +* when to apply SECMARK label access checks to network packets. This +* function decements this reference count to indicate that one of the +* existing SECMARK targets has been removed/flushed. +*/ +void selinux_secmark_refcount_dec (void );#else static inline int selinux_audit_rule_init(u32 field, u32 op,
@@ -184,11 +203,21 @@ static inline int selinux_string_to_sid(const char *str, u32 *sid)return 0 ; } -static inline int selinux_relabel_packet_permission (u32 sid) +static inline int selinux_secmark_relabel_packet_permission (u32 sid) {return 0 ; } +static inline void selinux_secmark_refcount_inc (void ) +{ +return ; +} + +static inline void selinux_secmark_refcount_dec (void ) +{ +return ; +} +#endif /* CONFIG_SECURITY_SELINUX */ #endif /* _LINUX_SELINUX_H */
net/netfilter/xt_SECMARK.c +12 -1
@@ -72,12 +72,13 @@ static bool checkentry_selinux(struct xt_secmark_target_info *info)return false; } - err =selinux_relabel_packet_permission (sel->selsid); + err =selinux_secmark_relabel_packet_permission (sel->selsid);if (err) { printk(KERN_INFO PFX "unable to obtain relabeling permission\n");return false; } +selinux_secmark_refcount_inc ();return true; }
@@ -109,11 +110,20 @@ static bool checkentry(const char *tablename, const void *entry,return true; } +void destroy (const struct xt_target *target,void *targinfo) +{ +switch (mode) { +case SECMARK_MODE_SEL : +selinux_secmark_refcount_dec (); + } +} +static struct xt_target xt_secmark_target[]__read_mostly = { { .name ="SECMARK" , .family =AF_INET , .checkentry = checkentry, + .destroy = destroy, .target = target, .targetsize =sizeof (struct xt_secmark_target_info ), .table ="mangle" ,
@@ -123,6 +133,7 @@ static struct xt_target xt_secmark_target[] __read_mostly = { .name = "SECMARK", .family = AF_INET6, .checkentry = checkentry, + .destroy = destroy, .target = target, .targetsize = sizeof(struct xt_secmark_target_info), .table = "mangle",
security/selinux/exports.c +18 -2
@@ -17,10 +17,14 @@#include <linux/selinux.h> #include <linux/fs.h> #include <linux/ipc.h> +#include <asm/atomic.h> #include "security.h" #include "objsec.h" +/* SECMARK reference count */ +extern atomic_t selinux_secmark_refcount; +int selinux_sid_to_string (u32 sid,char **ctx,u32 *ctxlen) {if (selinux_enabled)
@@ -74,7 +78,7 @@ int selinux_string_to_sid(char *str, u32 *sid) }EXPORT_SYMBOL_GPL (selinux_string_to_sid); -int selinux_relabel_packet_permission (u32 sid) +int selinux_secmark_relabel_packet_permission (u32 sid) {if (selinux_enabled) {struct task_security_struct *tsec = current->security;
@@ -84,4 +88,16 @@ int selinux_relabel_packet_permission(u32 sid) }return 0 ; } -EXPORT_SYMBOL_GPL (selinux_relabel_packet_permission); +EXPORT_SYMBOL_GPL (selinux_secmark_relabel_packet_permission); + +void selinux_secmark_refcount_inc (void ) +{ +atomic_inc (&selinux_secmark_refcount); +} +EXPORT_SYMBOL_GPL (selinux_secmark_refcount_inc); + +void selinux_secmark_refcount_dec (void ) +{ +atomic_dec (&selinux_secmark_refcount); +} +EXPORT_SYMBOL_GPL (selinux_secmark_refcount_dec);
security/selinux/hooks.c +37 -9
79 lines not on this page · raw message
security/selinux/include/xfrm.h +12 -0
@@ -32,6 +32,13 @@ static inline struct inode_security_struct *get_sock_isec(struct sock *sk) }#ifdef CONFIG_SECURITY_NETWORK_XFRM +extern atomic_t selinux_xfrm_refcount; + +static inline int selinux_xfrm_enabled (void ) +{ +return (atomic_read (&selinux_xfrm_refcount) >0 ); +} +int selinux_xfrm_sock_rcv_skb (u32 sid,struct sk_buff *skb,struct avc_audit_data *ad); int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
@@ -43,6 +50,11 @@ static inline void selinux_xfrm_notify_policyload(void) atomic_inc(&flow_cache_genid); }#else +static inline int selinux_xfrm_enabled (void ) +{ +return 0 ; +} +static inline int selinux_xfrm_sock_rcv_skb (u32 isec_sid,struct sk_buff *skb,struct avc_audit_data *ad) {
security/selinux/xfrm.c +16 -2
@@ -46,11 +46,14 @@#include <net/checksum.h> #include <net/udp.h> #include <asm/semaphore.h> +#include <asm/atomic.h> #include "avc.h" #include "objsec.h" #include "xfrm.h" +/* Labeled XFRM instance counter */ +atomic_t selinux_xfrm_refcount =ATOMIC_INIT (0 );/* * Returns true if an LSM/SELinux context
@@ -293,6 +296,9 @@ int selinux_xfrm_policy_alloc(struct xfrm_policy *xp,BUG_ON (!uctx); err =selinux_xfrm_sec_ctx_alloc (&xp->security, uctx,0 ); +if (err ==0 ) +atomic_inc (&selinux_xfrm_refcount); +return err; }
@@ -340,10 +346,13 @@ int selinux_xfrm_policy_delete(struct xfrm_policy *xp)struct xfrm_sec_ctx *ctx = xp->security;int rc =0 ; -if (ctx) +if (ctx) { rc =avc_has_perm (tsec->sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL ); +if (rc ==0 ) +atomic_dec (&selinux_xfrm_refcount); + }return rc; }
@@ -360,6 +369,8 @@ int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *uctBUG_ON (!x); err =selinux_xfrm_sec_ctx_alloc (&x->security, uctx, secid); +if (err ==0 ) +atomic_inc (&selinux_xfrm_refcount);return err; }
@@ -382,10 +393,13 @@ int selinux_xfrm_state_delete(struct xfrm_state *x)struct xfrm_sec_ctx *ctx = x->security;int rc =0 ; -if (ctx) +if (ctx) { rc =avc_has_perm (tsec->sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL ); +if (rc ==0 ) +atomic_dec (&selinux_xfrm_refcount); + }return rc; }
--
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.
RFC PATCH v8 7/18 NetLabel: Add IP address family information to the netlbl_skbuff_getattr() function
In reply to Paul MooreIn order to do any sort of IP header inspection of incoming packets we need to know which address family, AF_INET/AF_INET6/etc., it belongs to and since the sk_buff structure does not store this information we need to pass along the address family separate from the packet itself.
---
include/net/netlabel.h | 2 ++ net/netlabel/netlabel_kapi.c | 2 ++ security/selinux/hooks.c | 24 ++++++++++++++++++------ security/selinux/include/netlabel.h | 8 +++++++- security/selinux/netlabel.c | 12 +++++++++--- 5 files changed, 38 insertions(+), 10 deletions(-)
include/net/netlabel.h +2 -0
@@ -363,6 +363,7 @@ int netlbl_sock_setattr(struct sock *sk,int netlbl_sock_getattr (struct sock *sk,struct netlbl_lsm_secattr *secattr);int netlbl_skbuff_getattr (const struct sk_buff *skb, +u16 family,struct netlbl_lsm_secattr *secattr);void netlbl_skbuff_err (struct sk_buff *skb,int error);
@@ -415,6 +416,7 @@ static inline int netlbl_sock_getattr(struct sock *sk,return -ENOSYS ; }static inline int netlbl_skbuff_getattr (const struct sk_buff *skb, +u16 family,struct netlbl_lsm_secattr *secattr) {return -ENOSYS ;
net/netlabel/netlabel_kapi.c +2 -0
@@ -332,6 +332,7 @@ int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr)/** * netlbl_skbuff_getattr - Determine the security attributes of a packet * @skb: the packet +* @family: protocol family * @secattr: the security attributes * * Description:
@@ -342,6 +343,7 @@ int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr)* */ int netlbl_skbuff_getattr (const struct sk_buff *skb, +u16 family,struct netlbl_lsm_secattr *secattr) { if (CIPSO_V4_OPTEXIST(skb) &&
security/selinux/hooks.c +18 -6
@@ -3192,6 +3192,7 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,/** * selinux_skb_extlbl_sid - Determine the external label of a packet * @skb: the packet +* @family: protocol family * @sid: the packet's SID * * Description:
@@ -3204,13 +3205,16 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,* selinux_netlbl_skbuff_getsid(). * */ -static void selinux_skb_extlbl_sid (struct sk_buff *skb,u32 *sid) +static void selinux_skb_extlbl_sid (struct sk_buff *skb, +u16 family, +u32 *sid) {u32 xfrm_sid;u32 nlbl_sid;selinux_skb_xfrm_sid (skb, &xfrm_sid);if (selinux_netlbl_skbuff_getsid (skb, + family, (xfrm_sid ==SECSID_NULL ?SECINITSID_NETMSG : xfrm_sid), &nlbl_sid) !=0 )
@@ -3703,7 +3707,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)if (err) goto out; - err =selinux_netlbl_sock_rcv_skb (sksec, skb, &ad); + err =selinux_netlbl_sock_rcv_skb (sksec, skb, family, &ad);if (err) goto out;
@@ -3760,11 +3764,19 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff * {u32 peer_secid =SECSID_NULL ;int err =0 ; +u16 family; + +if (sock) + family = sock->sk->sk_family; +else if (skb->sk) + family = skb->sk->sk_family; +else + family =PF_UNSPEC ; -if (sock && sock->sk->sk_family ==PF_UNIX ) +if (sock && family ==PF_UNIX )selinux_get_inode_sid (SOCK_INODE (sock), &peer_secid);else if (skb) -selinux_skb_extlbl_sid (skb, &peer_secid); +selinux_skb_extlbl_sid (skb, family, &peer_secid);if (peer_secid ==SECSID_NULL ) err = -EINVAL ;
@@ -3825,7 +3837,7 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,u32 newsid;u32 peersid; -selinux_skb_extlbl_sid (skb, &peersid); +selinux_skb_extlbl_sid (skb, sk->sk_family, &peersid);if (peersid ==SECSID_NULL ) { req->secid = sksec->sid; req->peer_secid =SECSID_NULL ;
@@ -3863,7 +3875,7 @@ static void selinux_inet_conn_established(struct sock *sk, {struct sk_security_struct *sksec = sk->sk_security; -selinux_skb_extlbl_sid (skb, &sksec->peer_sid); +selinux_skb_extlbl_sid (skb, sk->sk_family, &sksec->peer_sid); } static void selinux_req_classify_flow(const struct request_sock *req,
security/selinux/include/netlabel.h +7 -1
@@ -46,13 +46,17 @@ void selinux_netlbl_sk_security_init(struct sk_security_struct *ssec,void selinux_netlbl_sk_security_clone (struct sk_security_struct *ssec,struct sk_security_struct *newssec); -int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u32 base_sid,u32 *sid); +int selinux_netlbl_skbuff_getsid (struct sk_buff *skb, +u16 family, +u32 base_sid, +u32 *sid);void selinux_netlbl_sock_graft (struct sock *sk,struct socket *sock);int selinux_netlbl_socket_post_create (struct socket *sock);int selinux_netlbl_inode_permission (struct inode *inode,int mask);int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb, +u16 family,struct avc_audit_data *ad); int selinux_netlbl_socket_setsockopt(struct socket *sock, int level,
@@ -83,6 +87,7 @@ static inline void selinux_netlbl_sk_security_clone( }static inline int selinux_netlbl_skbuff_getsid (struct sk_buff *skb, +u16 family,u32 base_sid,u32 *sid) {
@@ -106,6 +111,7 @@ static inline int selinux_netlbl_inode_permission(struct inode *inode, }static inline int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb, +u16 family,struct avc_audit_data *ad) {return 0 ;
security/selinux/netlabel.c +9 -3
@@ -141,6 +141,7 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,/** * selinux_netlbl_skbuff_getsid - Get the sid of a packet using NetLabel * @skb: the packet +* @family: protocol family * @base_sid: the SELinux SID to use as a context for MLS only attributes * @sid: the SID *
@@ -150,7 +151,10 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,* assign to the packet. Returns zero on success, negative values on failure. * */ -int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u32 base_sid,u32 *sid) +int selinux_netlbl_skbuff_getsid (struct sk_buff *skb, +u16 family, +u32 base_sid, +u32 *sid) {int rc;struct netlbl_lsm_secattr secattr;
@@ -161,7 +165,7 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb, u32 base_sid, u32 *sid) }netlbl_secattr_init (&secattr); - rc =netlbl_skbuff_getattr (skb, &secattr); + rc =netlbl_skbuff_getattr (skb, family, &secattr);if (rc ==0 && secattr.flags !=NETLBL_SECATTR_NONE ) { rc =security_netlbl_secattr_to_sid (&secattr, base_sid, sid); if (rc == 0 &&
@@ -289,6 +293,7 @@ int selinux_netlbl_inode_permission(struct inode *inode, int mask)* selinux_netlbl_sock_rcv_skb - Do an inbound access check using NetLabel * @sksec: the sock's sk_security_struct * @skb: the packet +* @family: protocol family * @ad: the audit data * * Description:
@@ -299,6 +304,7 @@ int selinux_netlbl_inode_permission(struct inode *inode, int mask)*/ int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb, +u16 family,struct avc_audit_data *ad) {int rc;
@@ -310,7 +316,7 @@ int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec,return 0 ;netlbl_secattr_init (&secattr); - rc =netlbl_skbuff_getattr (skb, &secattr); + rc =netlbl_skbuff_getattr (skb, family, &secattr);if (rc ==0 && secattr.flags !=NETLBL_SECATTR_NONE ) { rc = security_netlbl_secattr_to_sid(&secattr, SECINITSID_NETMSG,
--
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.
RFC PATCH v8 15/18 SELinux: Allow NetLabel to directly cache SIDs
In reply to Paul MooreNow that the SELinux NetLabel "base SID" is always the netmsg initial SID we can do a big optimization - caching the SID and not just the MLS attributes. This not only saves a lot of per-packet memory allocations and copies but it has a nice side effect of removing a chunk of code.
---
security/selinux/hooks.c | 6 -- security/selinux/include/netlabel.h | 2 - security/selinux/include/security.h | 2 - security/selinux/netlabel.c | 55 ++++++++++------ security/selinux/ss/services.c | 124 ++++++----------------------------- 5 files changed, 55 insertions(+), 134 deletions(-)
security/selinux/hooks.c +1 -5
@@ -3231,11 +3231,7 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid)u32 nlbl_type;selinux_skb_xfrm_sid (skb, &xfrm_sid); -selinux_netlbl_skbuff_getsid (skb, - family, -SECINITSID_NETMSG , - &nlbl_type, - &nlbl_sid); +selinux_netlbl_skbuff_getsid (skb, family, &nlbl_type, &nlbl_sid); if (security_net_peersid_resolve(nlbl_sid, nlbl_type, xfrm_sid,
security/selinux/include/netlabel.h +0 -2
@@ -48,7 +48,6 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u16 family, -u32 base_sid,u32 *type,u32 *sid);
@@ -89,7 +88,6 @@ static inline void selinux_netlbl_sk_security_clone(static inline int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u16 family, -u32 base_sid,u32 *type,u32 *sid) {
security/selinux/include/security.h +0 -2
@@ -124,7 +124,6 @@ int security_genfs_sid(const char *fstype, char *name, u16 sclass,#ifdef CONFIG_NETLABEL int security_netlbl_secattr_to_sid (struct netlbl_lsm_secattr *secattr, -u32 base_sid,u32 *sid); int security_netlbl_sid_to_secattr(u32 sid,
@@ -132,7 +131,6 @@ int security_netlbl_sid_to_secattr(u32 sid,#else static inline int security_netlbl_secattr_to_sid (struct netlbl_lsm_secattr *secattr, -u32 base_sid,u32 *sid) {return -EIDRM ;
security/selinux/netlabel.c +34 -21
91 lines not on this page · raw message
security/selinux/ss/services.c +20 -104
180 lines not on this page · raw message
--
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.
RFC PATCH v8 6/18 LSM: Add inet_sys_snd_skb() LSM hook
In reply to Paul MooreAdd an inet_sys_snd_skb() LSM hook to allow the LSM to provide packet level access control for all outbound packets. Using the existing postroute_last netfilter hook turns out to be problematic as it is can be invoked multiple times for a single packet, e.g. individual IPsec transforms, adding unwanted overhead and complicating the security policy.
---
include/linux/security.h | 11 +++++++++++ net/ipv4/ip_output.c | 7 +++++++ net/ipv6/ip6_output.c | 5 +++++ security/dummy.c | 8 +++++++- security/security.c | 6 ++++++ 5 files changed, 36 insertions(+), 1 deletions(-)
include/linux/security.h +11 -0
@@ -876,6 +876,10 @@ struct request_sock;* Sets the connection's peersid to the secmark on skb. * @req_classify_flow: * Sets the flow's sid to the openreq sid. +* @inet_sys_snd_skb: +* Check permissions on outgoing network packets. +* @skb is the packet to check +* @family is the packet's address family * * Security hooks for XFRM operations. *
@@ -1416,6 +1420,7 @@ struct security_operations {void (*inet_csk_clone)(struct sock *newsk,const struct request_sock *req);void (*inet_conn_established)(struct sock *sk,struct sk_buff *skb);void (*req_classify_flow)(const struct request_sock *req,struct flowi *fl); +int (*inet_sys_snd_skb)(struct sk_buff *skb,int family);#endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM
@@ -2328,6 +2333,7 @@ void security_sk_free(struct sock *sk);void security_sk_clone (const struct sock *sk,struct sock *newsk);void security_sk_classify_flow (struct sock *sk,struct flowi *fl);void security_req_classify_flow (const struct request_sock *req,struct flowi *fl); +int security_inet_sys_snd_skb (struct sk_buff *skb,int family);void security_sock_graft (struct sock *sk,struct socket *parent);int security_inet_conn_request (struct sock *sk,struct sk_buff *skb,struct request_sock *req);
@@ -2471,6 +2477,11 @@ static inline void security_req_classify_flow(const struct request_sock *req, st { } +static inline int security_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +return 0 ; +} +static inline void security_sock_graft (struct sock * sk,struct socket *parent) { }
net/ipv4/ip_output.c +7 -0
@@ -204,6 +204,8 @@ static inline int ip_skb_dst_mtu(struct sk_buff *skb)static int ip_finish_output (struct sk_buff *skb) { +int err; +#if defined(CONFIG_NETFILTER ) && defined(CONFIG_XFRM )/* Policy lookup after SNAT yielded a new policy */ if (skb->dst->xfrm !=NULL ) {
@@ -211,6 +213,11 @@ static int ip_finish_output(struct sk_buff *skb) return dst_output(skb); }#endif + + err =security_inet_sys_snd_skb (skb,AF_INET ); +if (err) +return err; +if (skb->len >ip_skb_dst_mtu (skb) && !skb_is_gso (skb))return ip_fragment (skb, ip_finish_output2);else
net/ipv6/ip6_output.c +5 -0
@@ -72,8 +72,13 @@ static __inline__ void ipv6_select_ident(struct sk_buff *skb, struct frag_hdr *fstatic int ip6_output_finish (struct sk_buff *skb) { +int err;struct dst_entry *dst = skb->dst; + err =security_inet_sys_snd_skb (skb,AF_INET6 ); +if (err) +return err; +if (dst->hh)return neigh_hh_output (dst->hh, skb);else if (dst->neighbour)
security/dummy.c +7 -1
@@ -848,6 +848,11 @@ static inline void dummy_req_classify_flow(const struct request_sock *req, struct flowi *fl) { } + +static inline int dummy_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +return 0 ; +}#endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM
@@ -1122,7 +1127,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, inet_csk_clone);set_to_dummy_if_null (ops, inet_conn_established);set_to_dummy_if_null (ops, req_classify_flow); -#endif /* CONFIG_SECURITY_NETWORK */ +set_to_dummy_if_null (ops, inet_sys_snd_skb); +#endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM set_to_dummy_if_null (ops, xfrm_policy_alloc_security);set_to_dummy_if_null (ops, xfrm_policy_clone_security);
security/security.c +6 -0
@@ -961,6 +961,12 @@ void security_req_classify_flow(const struct request_sock *req, struct flowi *fl }EXPORT_SYMBOL (security_req_classify_flow); +int security_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +return security_ops->inet_sys_snd_skb (skb, family); +} +EXPORT_SYMBOL (security_inet_sys_snd_skb); +void security_sock_graft (struct sock *sk,struct socket *parent) { security_ops->sock_graft (sk, parent);
--
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.
RFC PATCH v8 8/18 SELinux: Convert the netif code to use ifindex values
In reply to Paul MooreThe current SELinux netif code requires the caller have a valid net_device struct pointer to lookup network interface information. However, we don't always have a valid net_device pointer so convert the netif code to use the ifindex values we always have as part of the sk_buff. This patch also removes the default message SID from the network interface record, it is not being used and therefore is "dead code".
---
security/selinux/hooks.c | 4 - security/selinux/include/netif.h | 4 - security/selinux/include/objsec.h | 5 - security/selinux/include/security.h | 3 security/selinux/netif.c | 254 ++++++++++++++++++++--------------- security/selinux/ss/services.c | 10 - 6 files changed, 155 insertions(+), 125 deletions(-)
security/selinux/hooks.c +2 -2
@@ -3616,7 +3616,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,if (!skb->dev) goto out; - err =sel_netif_sids (skb->dev, &if_sid,NULL ); + err =sel_netif_sid (skb->iif, &if_sid);if (err) goto out;
@@ -3942,7 +3942,7 @@ static int selinux_ip_postroute_last_compat(struct sock *sk, struct net_device * isec = inode->i_security; - err =sel_netif_sids (dev, &if_sid,NULL ); + err =sel_netif_sid (dev->ifindex, &if_sid);if (err) goto out;
security/selinux/include/netif.h +3 -1
@@ -7,6 +7,8 @@* Author: James Morris <[email protected]> * * Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]> +* Copyright (C) 2007 Hewlett-Packard Development Company, L.P. +* Paul Moore, <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2,
@@ -15,7 +17,7 @@#ifndef _SELINUX_NETIF_H_#define _SELINUX_NETIF_H_ -int sel_netif_sids (struct net_device *dev,u32 *if_sid,u32 *msg_sid); +int sel_netif_sid (int ifindex,u32 *sid);#endif /* _SELINUX_NETIF_H_ */
security/selinux/include/objsec.h +2 -3
@@ -95,9 +95,8 @@ struct bprm_security_struct { };struct netif_security_struct { -struct net_device *dev;/* back pointer */ -u32 if_sid;/* SID for this interface */ -u32 msg_sid;/* default SID for messages received on this interface */ +int ifindex;/* device index */ +u32 sid;/* SID for this interface */ };struct sk_security_struct {
security/selinux/include/security.h +1 -2
@@ -77,8 +77,7 @@ int security_get_user_sids(u32 callsid, char *username,int security_port_sid (u16 domain,u16 type,u8 protocol,u16 port,u32 *out_sid); -int security_netif_sid (char *name,u32 *if_sid, -u32 *msg_sid); +int security_netif_sid (char *name,u32 *if_sid);int security_node_sid (u16 domain,void *addr,u32 addrlen,u32 *out_sid);
security/selinux/netif.c +145 -109
363 lines not on this page · raw message
security/selinux/ss/services.c +2 -8
@@ -1478,11 +1478,8 @@ out:* security_netif_sid - Obtain the SID for a network interface. * @name: interface name * @if_sid: interface SID -* @msg_sid: default SID for received packets */ -int security_netif_sid (char *name, -u32 *if_sid, -u32 *msg_sid) +int security_netif_sid (char *name,u32 *if_sid) {int rc =0 ;struct ocontext *c;
@@ -1510,11 +1507,8 @@ int security_netif_sid(char *name, goto out; } *if_sid = c->sid[0 ]; - *msg_sid = c->sid[1 ]; - }else { + }else *if_sid =SECINITSID_NETIF ; - *msg_sid =SECINITSID_NETMSG ; - } out:POLICY_RDUNLOCK ;
--
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.
RFC PATCH v8 17/18 NetLabel: Add auditing to the static labeling mechanism
In reply to Paul MooreThis patch adds auditing support to the NetLabel static labeling mechanism.
---
include/linux/audit.h | 2 net/netlabel/netlabel_unlabeled.c | 207 ++++++++++++++++++++++++++++++++++--- 2 files changed, 195 insertions(+), 14 deletions(-)
include/linux/audit.h +2 -0
@@ -115,6 +115,8 @@#define AUDIT_MAC_IPSEC_ADDSPD 1413/* Not used */ #define AUDIT_MAC_IPSEC_DELSPD 1414/* Not used */ #define AUDIT_MAC_IPSEC_EVENT 1415/* Audit an IPSec event */ +#define AUDIT_MAC_UNLBL_STCADD 1416/* NetLabel: add a static label */ +#define AUDIT_MAC_UNLBL_STCDEL 1417/* NetLabel: del a static label */ #define AUDIT_FIRST_KERN_ANOM_MSG 1700#define AUDIT_LAST_KERN_ANOM_MSG 1799
net/netlabel/netlabel_unlabeled.c +193 -14
386 lines not on this page · raw message
--
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.
RFC PATCH v8 4/18 NetLabel: Add secid token support to the NetLabel secattr struct
In reply to Paul MooreThis patch adds support to the NetLabel LSM secattr struct for a secid token and a type field, paving the way for full LSM/SELinux context support and "static" or "fallback" labels. In addition, this patch adds a fair amount of documentation to the core NetLabel structures used as part of the NetLabel kernel API.
---
include/net/netlabel.h | 91 ++++++++++++++++++++++++++++++------- net/ipv4/cipso_ipv4.c | 59 +++++++++++++++--------- net/netlabel/netlabel_unlabeled.c | 1 security/selinux/ss/mls.c | 10 ++-- security/selinux/ss/services.c | 5 ++ 5 files changed, 120 insertions(+), 46 deletions(-)
include/net/netlabel.h +73 -18
@@ -105,17 +105,49 @@ struct netlbl_dom_map;/* Domain mapping operations */ int netlbl_domhsh_remove (const char *domain,struct netlbl_audit *audit_info); -/* LSM security attributes */ +/* +* LSM security attributes +*/ + +/** +* struct netlbl_lsm_cache - NetLabel LSM security attribute cache +* @refcount: atomic reference counter +* @free: LSM supplied function to free the cache data +* @data: LSM supplied cache data +* +* Description: +* This structure is provided for LSMs which wish to make use of the NetLabel +* caching mechanism to store LSM specific data/attributes in the NetLabel +* cache. If the LSM has to perform a lot of translation from the NetLabel +* security attributes into it's own internal representation then the cache +* mechanism can provide a way to eliminate some or all of that translation +* overhead on a cache hit. +* +*/ struct netlbl_lsm_cache {atomic_t refcount;void (*free) (const void *data);void *data; }; -/* The catmap bitmap field MUST be a power of two in length and large + +/** +* struct netlbl_lsm_secattr_catmap - NetLabel LSM secattr category bitmap +* @startbit: the value of the lowest order bit in the bitmap +* @bitmap: the category bitmap +* @next: pointer to the next bitmap "node" or NULL +* +* Description: +* This structure is used to represent category bitmaps. Due to the large +* number of categories supported by most labeling protocols it is not +* practical to transfer a full bitmap internally so NetLabel adopts a sparse +* bitmap structure modeled after SELinux's ebitmap structure. +* The catmap bitmap field MUST be a power of two in length and large * enough to hold at least 240 bits. Special care (i.e. check the code!) * should be used when changing these values as the LSM implementation * probably has functions which rely on the sizes of these types to speed -* processing. */ +* processing. +* +*/ #define NETLBL_CATMAP_MAPTYPE u64#define NETLBL_CATMAP_MAPCNT 4#define NETLBL_CATMAP_MAPSIZE (sizeof(NETLBL_CATMAP_MAPTYPE) * 8)
@@ -127,22 +159,48 @@ struct netlbl_lsm_secattr_catmap {NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT ];struct netlbl_lsm_secattr_catmap *next; }; + +/** +* struct netlbl_lsm_secattr - NetLabel LSM security attributes +* @flags: indicate which attributes are contained in this structure +* @type: indicate the NLTYPE of the attributes +* @domain: the NetLabel LSM domain +* @cache: NetLabel LSM specific cache +* @attr.mls: MLS sensitivity label +* @attr.mls.cat: MLS category bitmap +* @attr.mls.lvl: MLS sensitivity level +* @attr.secid: LSM specific secid token +* +* Description: +* This structure is used to pass security attributes between NetLabel and the +* LSM modules. The flags field is used to specify which fields within the +* struct are valid and valid values can be created by bitwise OR'ing the +* NETLBL_SECATTR_* defines. The domain field is typically set by the LSM to +* specify domain specific configuration settings and is not usually used by +* NetLabel itself when returning security attributes to the LSM. +* +*/ #define NETLBL_SECATTR_NONE 0x00000000#define NETLBL_SECATTR_DOMAIN 0x00000001#define NETLBL_SECATTR_CACHE 0x00000002#define NETLBL_SECATTR_MLS_LVL 0x00000004#define NETLBL_SECATTR_MLS_CAT 0x00000008 +#define NETLBL_SECATTR_SECID 0x00000010#define NETLBL_SECATTR_CACHEABLE (NETLBL_SECATTR_MLS_LVL | \ - NETLBL_SECATTR_MLS_CAT) + NETLBL_SECATTR_MLS_CAT | \ + NETLBL_SECATTR_SECID)struct netlbl_lsm_secattr {u32 flags; - +u32 type;char *domain; - -u32 mls_lvl; -struct netlbl_lsm_secattr_catmap *mls_cat; -struct netlbl_lsm_cache *cache; +union { +struct { +struct netlbl_lsm_secattr_catmap *cat; +u32 lvl; + } mls; +u32 secid; + } attr; };/*
@@ -231,10 +289,7 @@ static inline void netlbl_secattr_catmap_free(*/ static inline void netlbl_secattr_init (struct netlbl_lsm_secattr *secattr) { - secattr->flags =0 ; - secattr->domain =NULL ; - secattr->mls_cat =NULL ; - secattr->cache =NULL ; +memset (secattr,0 ,sizeof (*secattr)); }/**
@@ -248,11 +303,11 @@ static inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)*/ static inline void netlbl_secattr_destroy (struct netlbl_lsm_secattr *secattr) { -if (secattr->cache) -netlbl_secattr_cache_free (secattr->cache);kfree (secattr->domain); -if (secattr->mls_cat) -netlbl_secattr_catmap_free (secattr->mls_cat); +if (secattr->flags &NETLBL_SECATTR_CACHE ) +netlbl_secattr_cache_free (secattr->cache); +if (secattr->flags &NETLBL_SECATTR_MLS_CAT ) +netlbl_secattr_catmap_free (secattr->attr.mls.cat); }/**
@@ -300,7 +355,7 @@ int netlbl_secattr_catmap_setrng(struct netlbl_lsm_secattr_catmap *catmap, gfp_t flags);/* -* LSM protocol operations +* LSM protocol operations (NetLabel LSM/kernel API) */ int netlbl_enabled (void ); int netlbl_sock_setattr(struct sock *sk,
net/ipv4/cipso_ipv4.c +37 -22
176 lines not on this page · raw message
net/netlabel/netlabel_unlabeled.c +1 -0
@@ -246,6 +246,7 @@ int netlbl_unlabel_getattr(struct netlbl_lsm_secattr *secattr)if (netlabel_unlabel_acceptflg ==0 )return -ENOMSG ;netlbl_secattr_init (secattr); + secattr->type =NETLBL_NLTYPE_UNLABELED ;return 0 ; }
security/selinux/ss/mls.c +5 -5
@@ -569,7 +569,7 @@ void mls_export_netlbl_lvl(struct context *context,if (!selinux_mls_enabled)return ; - secattr->mls_lvl = context->range.level[0 ].sens -1 ; + secattr->attr.mls.lvl = context->range.level[0 ].sens -1 ; secattr->flags |=NETLBL_SECATTR_MLS_LVL ; }
@@ -589,7 +589,7 @@ void mls_import_netlbl_lvl(struct context *context,if (!selinux_mls_enabled)return ; - context->range.level[0 ].sens = secattr->mls_lvl +1 ; + context->range.level[0 ].sens = secattr->attr.mls.lvl +1 ; context->range.level[1 ].sens = context->range.level[0 ].sens; }
@@ -612,8 +612,8 @@ int mls_export_netlbl_cat(struct context *context,return 0 ; rc =ebitmap_netlbl_export (&context->range.level[0 ].cat, - &secattr->mls_cat); -if (rc ==0 && secattr->mls_cat !=NULL ) + &secattr->attr.mls.cat); +if (rc ==0 && secattr->attr.mls.cat !=NULL ) secattr->flags |=NETLBL_SECATTR_MLS_CAT ;return rc;
@@ -640,7 +640,7 @@ int mls_import_netlbl_cat(struct context *context,return 0 ; rc =ebitmap_netlbl_import (&context->range.level[0 ].cat, - secattr->mls_cat); + secattr->attr.mls.cat);if (rc !=0 ) goto import_netlbl_cat_failure;
security/selinux/ss/services.c +4 -1
@@ -2547,6 +2547,9 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,default : goto netlbl_secattr_to_sid_return; } + }else if (secattr->flags &NETLBL_SECATTR_SECID ) { + *sid = secattr->attr.secid; + rc =0 ; }else if (secattr->flags &NETLBL_SECATTR_MLS_LVL ) { ctx =sidtab_search (&sidtab, base_sid);if (ctx ==NULL )
@@ -2558,7 +2561,7 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,mls_import_netlbl_lvl (&ctx_new, secattr);if (secattr->flags &NETLBL_SECATTR_MLS_CAT ) {if (ebitmap_netlbl_import (&ctx_new.range.level[0 ].cat, - secattr->mls_cat) !=0 ) + secattr->attr.mls.cat) !=0 ) goto netlbl_secattr_to_sid_return; ctx_new.range.level[1 ].cat.highbit = ctx_new.range.level[0 ].cat.highbit;
--
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.
RFC PATCH v8 13/18 SELinux: Better integration between peer labeling subsystems
In reply to Paul MooreRework the handling of network peer labels so that the different peer labeling subsystems work better together. This includes moving both subsystems to a single "peer" object class which involves not only changes to the permission checks but an improved method of consolidating multiple packet peer labels. As part of this work the inbound packet permission check code has been heavily modified to handle both the old and new behavior in as sane a fashion as possible.
---
security/selinux/hooks.c | 204 +++++++++++++++++++---------------- security/selinux/include/netlabel.h | 3 + security/selinux/include/objsec.h | 2 security/selinux/include/security.h | 4 + security/selinux/netlabel.c | 10 +- security/selinux/ss/services.c | 85 +++++++++++++++ 6 files changed, 208 insertions(+), 100 deletions(-)
security/selinux/hooks.c +112 -92
@@ -50,6 +50,7 @@#include <net/icmp.h> #include <net/ip.h> /* for local_port_range[] */ #include <net/tcp.h> /* struct or_callable used in sock_rcv_skb */ +#include <net/net_namespace.h> #include <asm/uaccess.h> #include <asm/ioctls.h> #include <linux/bitops.h>
@@ -3189,36 +3190,39 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad, }/** -* selinux_skb_extlbl_sid - Determine the external label of a packet +* selinux_skb_peerlbl_sid - Determine the peer label of a packet * @skb: the packet * @family: protocol family -* @sid: the packet's SID +* @sid: the packet's peer label SID * * Description: -* Check the various different forms of external packet labeling and determine -* the external SID for the packet. If only one form of external labeling is -* present then it is used, if both labeled IPsec and NetLabel labels are -* present then the SELinux type information is taken from the labeled IPsec -* SA and the MLS sensitivity label information is taken from the NetLabel -* security attributes. This bit of "magic" is done in the call to -* selinux_netlbl_skbuff_getsid(). +* Check the various different forms of network peer labeling and determine +* the peer label/SID for the packet; most of the magic actually occurs in +* the security server function security_net_peersid_cmp(). The function +* returns zero if the value in @sid is valid (although it may be SECSID_NULL) +* or -EACCES if @sid is invalid due to inconsistencies with the different +* peer labels. * */ -static void selinux_skb_extlbl_sid (struct sk_buff *skb, -u16 family, -u32 *sid) +static int selinux_skb_peerlbl_sid (struct sk_buff *skb,u16 family,u32 *sid) {u32 xfrm_sid;u32 nlbl_sid; +u32 nlbl_type;selinux_skb_xfrm_sid (skb, &xfrm_sid); -if (selinux_netlbl_skbuff_getsid (skb, - family, - (xfrm_sid ==SECSID_NULL ? -SECINITSID_NETMSG : xfrm_sid), - &nlbl_sid) !=0 ) - nlbl_sid =SECSID_NULL ; - *sid = (nlbl_sid ==SECSID_NULL ? xfrm_sid : nlbl_sid); +selinux_netlbl_skbuff_getsid (skb, + family, +SECINITSID_NETMSG , + &nlbl_type, + &nlbl_sid); + +if (security_net_peersid_resolve (nlbl_sid, nlbl_type, + xfrm_sid, + sid) !=0 ) +return -EACCES ; + +return 0 ; }/* socket security operations */
@@ -3284,6 +3288,7 @@ static int selinux_socket_post_create(struct socket *sock, int family,if (sock->sk) { sksec = sock->sk->sk_security; sksec->sid = isec->sid; + sksec->sclass = isec->sclass; err =selinux_netlbl_socket_post_create (sock); }
@@ -3587,104 +3592,114 @@ static int selinux_socket_unix_may_send(struct socket *sock,return 0 ; } -static int selinux_sock_rcv_skb_compat (struct sock *sk,struct sk_buff *skb, -struct avc_audit_data *ad, -u16 family,char *addrp) +static int selinux_sock_rcv_skb_iptables_compat (struct sock *sk, +struct sk_buff *skb, +struct avc_audit_data *ad, +u16 family, +char *addrp) { -int err =0 ; -u32 netif_perm, node_perm, node_sid, if_sid, recv_perm =0 ; -struct socket *sock; -u16 sock_class =0 ; -u32 sock_sid =0 ; - -read_lock_bh (&sk->sk_callback_lock); - sock = sk->sk_socket; -if (sock) { -struct inode *inode; - inode =SOCK_INODE (sock); -if (inode) { -struct inode_security_struct *isec; - isec = inode->i_security; - sock_sid = isec->sid; - sock_class = isec->sclass; - } - } -read_unlock_bh (&sk->sk_callback_lock); -if (!sock_sid) - goto out; - -if (!skb->dev) - goto out; +int err; +struct sk_security_struct *sksec = sk->sk_security; +u16 sk_class; +u32 netif_perm, node_perm, recv_perm; +u32 port_sid, node_sid, if_sid, sk_sid; - err =sel_netif_sid (skb->iif, &if_sid); -if (err) - goto out; + sk_sid = sksec->sid; + sk_class = sksec->sclass; -switch (sock_class) { +switch (sk_class) {case SECCLASS_UDP_SOCKET : netif_perm =NETIF__UDP_RECV ; node_perm =NODE__UDP_RECV ; recv_perm =UDP_SOCKET__RECV_MSG ;break ; -case SECCLASS_TCP_SOCKET : netif_perm =NETIF__TCP_RECV ; node_perm =NODE__TCP_RECV ; recv_perm =TCP_SOCKET__RECV_MSG ;break ; -case SECCLASS_DCCP_SOCKET : netif_perm =NETIF__DCCP_RECV ; node_perm =NODE__DCCP_RECV ; recv_perm =DCCP_SOCKET__RECV_MSG ;break ; -default : netif_perm =NETIF__RAWIP_RECV ; node_perm =NODE__RAWIP_RECV ; + recv_perm =0 ;break ; } - err =avc_has_perm (sock_sid, if_sid,SECCLASS_NETIF , netif_perm, ad); + err =sel_netif_sid (skb->iif, &if_sid);if (err) - goto out; +return err; + err =avc_has_perm (sk_sid, if_sid,SECCLASS_NETIF , netif_perm, ad); +if (err) +return err; err =sel_netnode_sid (addrp, family, &node_sid);if (err) - goto out; - - err =avc_has_perm (sock_sid, node_sid,SECCLASS_NODE , node_perm, ad); +return err; + err =avc_has_perm (sk_sid, node_sid,SECCLASS_NODE , node_perm, ad);if (err) - goto out; +return err; -if (recv_perm) { -u32 port_sid; +if (!recv_perm) +return 0 ; + err =security_port_sid (sk->sk_family, sk->sk_type, + sk->sk_protocol,ntohs (ad->u.net.sport), + &port_sid); +if (err) +return err; +return avc_has_perm (sk_sid, port_sid, sk_class, recv_perm, ad); +} - err =security_port_sid (sk->sk_family, sk->sk_type, - sk->sk_protocol,ntohs (ad->u.net.sport), - &port_sid); -if (err) - goto out; +static int selinux_sock_rcv_skb_compat (struct sock *sk,struct sk_buff *skb, +struct avc_audit_data *ad, +u16 family,char *addrp) +{ +int err; +struct sk_security_struct *sksec = sk->sk_security; +u32 peer_sid; +u32 sk_sid = sksec->sid; + +if (selinux_compat_net) + err =selinux_sock_rcv_skb_iptables_compat (sk, skb, ad, + family, addrp); +else + err =avc_has_perm (sk_sid, skb->secmark,SECCLASS_PACKET , +PACKET__RECV , ad); +if (err) +return err; - err =avc_has_perm (sock_sid, port_sid, - sock_class, recv_perm, ad); +if (selinux_policycap_netpeer) { + err =selinux_skb_peerlbl_sid (skb, family, &peer_sid); +if (err) +return err; + err =avc_has_perm (sk_sid, peer_sid, +SECCLASS_PEER ,PEER__RECV , ad); + }else { + err =selinux_netlbl_sock_rcv_skb (sksec, skb, family, ad); +if (err) +return err; + err =selinux_xfrm_sock_rcv_skb (sksec->sid, skb, ad); } -out:return err; }static int selinux_socket_sock_rcv_skb (struct sock *sk,struct sk_buff *skb) { -u16 family; -char *addrp; -int err =0 ; -struct avc_audit_data ad; +int err;struct sk_security_struct *sksec = sk->sk_security; +u16 family = sk->sk_family; +u32 sk_sid = sksec->sid; +u32 peer_sid; +struct avc_audit_data ad; +char *addrp; - family = sk->sk_family;if (family !=PF_INET && family !=PF_INET6 ) - goto out; +return 0 ;/* Handle mapped IPv4 packets arriving via IPv6 sockets */ if (family ==PF_INET6 && skb->protocol ==htons (ETH_P_IP ))
@@ -3693,26 +3708,27 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)AVC_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.netif = skb->iif; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp,1 ,NULL );if (err) - goto out; +return err; -if (selinux_compat_net) - err =selinux_sock_rcv_skb_compat (sk, skb, &ad, family, addrp); -else - err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET , -PACKET__RECV , &ad); -if (err) - goto out; +/* If any sort of compatibility mode is enabled then handoff processing +* to the selinux_sock_rcv_skb_compat() function to deal with the +* special handling. We do this in an attempt to keep this function +* as fast and as clean as possible. */ +if (selinux_compat_net || !selinux_policycap_netpeer) +return selinux_sock_rcv_skb_compat (sk, skb, &ad, + family, addrp); - err =selinux_netlbl_sock_rcv_skb (sksec, skb, family, &ad); + err =avc_has_perm (sk_sid, skb->secmark,SECCLASS_PACKET , +PACKET__RECV , &ad);if (err) - goto out; +return err; - err =selinux_xfrm_sock_rcv_skb (sksec->sid, skb, &ad); -out: -return err; + err =selinux_skb_peerlbl_sid (skb, family, &peer_sid); +if (err) +return err; +return avc_has_perm (sk_sid, peer_sid,SECCLASS_PEER ,PEER__RECV , &ad); } static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *optval,
@@ -3775,7 +3791,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *if (sock && family ==PF_UNIX )selinux_get_inode_sid (SOCK_INODE (sock), &peer_secid);else if (skb) -selinux_skb_extlbl_sid (skb, family, &peer_secid); +selinux_skb_peerlbl_sid (skb, family, &peer_secid);if (peer_secid ==SECSID_NULL ) err = -EINVAL ;
@@ -3801,6 +3817,7 @@ static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk) newssec->sid = ssec->sid; newssec->peer_sid = ssec->peer_sid; + newssec->sclass = ssec->sclass;selinux_netlbl_sk_security_clone (ssec, newssec); }
@@ -3824,6 +3841,7 @@ static void selinux_sock_graft(struct sock* sk, struct socket *parent)if (sk->sk_family ==PF_INET || sk->sk_family ==PF_INET6 || sk->sk_family ==PF_UNIX ) isec->sid = sksec->sid; + sksec->sclass = isec->sclass;selinux_netlbl_sock_graft (sk, parent); }
@@ -3836,7 +3854,9 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,u32 newsid;u32 peersid; -selinux_skb_extlbl_sid (skb, sk->sk_family, &peersid); + err =selinux_skb_peerlbl_sid (skb, sk->sk_family, &peersid); +if (err) +return err;if (peersid ==SECSID_NULL ) { req->secid = sksec->sid; req->peer_secid =SECSID_NULL ;
@@ -3874,7 +3894,7 @@ static void selinux_inet_conn_established(struct sock *sk, {struct sk_security_struct *sksec = sk->sk_security; -selinux_skb_extlbl_sid (skb, sk->sk_family, &sksec->peer_sid); +selinux_skb_peerlbl_sid (skb, sk->sk_family, &sksec->peer_sid); } static void selinux_req_classify_flow(const struct request_sock *req,
security/selinux/include/netlabel.h +3 -0
@@ -49,6 +49,7 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u16 family,u32 base_sid, +u32 *type,u32 *sid);void selinux_netlbl_sock_graft (struct sock *sk,struct socket *sock);
@@ -89,8 +90,10 @@ static inline void selinux_netlbl_sk_security_clone(static inline int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u16 family,u32 base_sid, +u32 *type,u32 *sid) { + *type =NETLBL_NLTYPE_NONE ; *sid =SECSID_NULL ;return 0 ; }
security/selinux/include/objsec.h +1 -1
@@ -112,8 +112,8 @@ struct sk_security_struct {struct sock *sk;/* back pointer to sk object */ u32 sid;/* SID of this object */ u32 peer_sid;/* SID of peer */ -#ifdef CONFIG_NETLABEL u16 sclass;/* sock security class */ +#ifdef CONFIG_NETLABEL enum {/* NetLabel state */ NLBL_UNSET =0 , NLBL_REQUIRE,
security/selinux/include/security.h +4 -0
@@ -99,6 +99,10 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,int security_sid_mls_copy (u32 sid,u32 mls_sid,u32 *new_sid); +int security_net_peersid_resolve (u32 nlbl_sid,u32 nlbl_type, +u32 xfrm_sid, +u32 *peer_sid); +int security_get_classes (char ***classes,int *nclasses);int security_get_permissions (char *class,char ***perms,int *nperms);int security_get_reject_unknown (void );
security/selinux/netlabel.c +3 -7
@@ -134,7 +134,6 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,* lock as other threads could have access to ssec */ rcu_read_lock ();selinux_netlbl_sk_security_reset (newssec, ssec->sk->sk_family); - newssec->sclass = ssec->sclass;rcu_read_unlock (); }
@@ -143,6 +142,7 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,* @skb: the packet * @family: protocol family * @base_sid: the SELinux SID to use as a context for MLS only attributes +* @type: NetLabel labeling protocol type * @sid: the SID * * Description:
@@ -154,6 +154,7 @@ void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec,int selinux_netlbl_skbuff_getsid (struct sk_buff *skb,u16 family,u32 base_sid, +u32 *type,u32 *sid) {int rc;
@@ -174,6 +175,7 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb,netlbl_cache_add (skb, &secattr); }else *sid =SECSID_NULL ; + *type = secattr.type;netlbl_secattr_destroy (&secattr);return rc;
@@ -191,13 +193,10 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb,*/ void selinux_netlbl_sock_graft (struct sock *sk,struct socket *sock) { -struct inode_security_struct *isec =SOCK_INODE (sock)->i_security;struct sk_security_struct *sksec = sk->sk_security;struct netlbl_lsm_secattr secattr;u32 nlbl_peer_sid; - sksec->sclass = isec->sclass; -rcu_read_lock ();if (sksec->nlbl_state !=NLBL_REQUIRE ) {
@@ -235,11 +234,8 @@ int selinux_netlbl_socket_post_create(struct socket *sock) {int rc =0 ;struct sock *sk = sock->sk; -struct inode_security_struct *isec =SOCK_INODE (sock)->i_security;struct sk_security_struct *sksec = sk->sk_security; - sksec->sclass = isec->sclass; -rcu_read_lock ();if (sksec->nlbl_state ==NLBL_REQUIRE ) rc =selinux_netlbl_sock_setsid (sk, sksec->sid);
security/selinux/ss/services.c +85 -0
91 lines not on this page · raw message
--
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.
RFC PATCH v8 10/18 SELinux: Add a network node caching mechanism similar to the sel_netif_*() functions
In reply to Paul MooreThis patch adds a SELinux IP address/node SID caching mechanism similar to the sel_netif_*() functions. The node SID queries in the SELinux hooks files are also modified to take advantage of this new functionality. In addition, remove the address length information from the sk_buff parsing routines as it is redundant since we already have the address family.
---
security/selinux/Makefile | 9 + security/selinux/hooks.c | 33 ++- security/selinux/include/netnode.h | 32 +++ security/selinux/include/objsec.h | 9 + security/selinux/netnode.c | 351 ++++++++++++++++++++++++++++++++++++ 5 files changed, 417 insertions(+), 17 deletions(-)
security/selinux/Makefile +8 -1
@@ -4,7 +4,14 @@ obj-$(CONFIG_SECURITY_SELINUX) := selinux.o ss/ -selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o netif.o exports.o +selinux-y := avc.o \ + hooks.o \ + selinuxfs.o \ + netlink.o \ + nlmsgtab.o \ + netif.o \ + netnode.o \ + exports.o selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.o
security/selinux/hooks.c +17 -16
@@ -76,6 +76,7 @@#include "avc.h" #include "objsec.h" #include "netif.h" +#include "netnode.h" #include "xfrm.h" #include "netlabel.h"
@@ -3158,7 +3159,7 @@ out:#endif /* IPV6 */ static int selinux_parse_skb (struct sk_buff *skb,struct avc_audit_data *ad, -char **addrp,int *len,int src,u8 *proto) +char **addrp,int src,u8 *proto) {int ret =0 ;
@@ -3167,7 +3168,6 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad, ret =selinux_parse_skb_ipv4 (skb, ad, proto);if (ret || !addrp)break ; - *len =4 ; *addrp = (char *)(src ? &ad->u.net.v4info.saddr : &ad->u.net.v4info.daddr);break ;
@@ -3177,7 +3177,6 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad, ret =selinux_parse_skb_ipv6 (skb, ad, proto);if (ret || !addrp)break ; - *len =16 ; *addrp = (char *)(src ? &ad->u.net.v6info.saddr : &ad->u.net.v6info.daddr);break ;
@@ -3377,7 +3376,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, inbreak ; } - err =security_node_sid (family, addrp, addrlen, &sid); + err =sel_netnode_sid (addrp, family, &sid);if (err) goto out;
@@ -3589,7 +3588,8 @@ static int selinux_socket_unix_may_send(struct socket *sock, }static int selinux_sock_rcv_skb_compat (struct sock *sk,struct sk_buff *skb, -struct avc_audit_data *ad,u16 family,char *addrp,int len) +struct avc_audit_data *ad, +u16 family,char *addrp) {int err =0 ;u32 netif_perm, node_perm, node_sid, if_sid, recv_perm =0 ;
@@ -3649,7 +3649,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,if (err) goto out; - err =security_node_sid (family, addrp, len, &node_sid); + err =sel_netnode_sid (addrp, family, &node_sid);if (err) goto out;
@@ -3678,7 +3678,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) {u16 family;char *addrp; -int len, err =0 ; +int err =0 ;struct avc_audit_data ad;struct sk_security_struct *sksec = sk->sk_security;
@@ -3694,13 +3694,12 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ad.u.net.netif = skb->iif; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp, &len,1 ,NULL ); + err =selinux_parse_skb (skb, &ad, &addrp,1 ,NULL );if (err) goto out;if (selinux_compat_net) - err =selinux_sock_rcv_skb_compat (sk, skb, &ad, family, - addrp, len); + err =selinux_sock_rcv_skb_compat (sk, skb, &ad, family, addrp);else err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__RECV , &ad);
@@ -3922,9 +3921,11 @@ out:#ifdef CONFIG_NETFILTER -static int selinux_ip_postroute_last_compat (struct sock *sk,struct net_device *dev, +static int selinux_ip_postroute_last_compat (struct sock *sk, +struct net_device *dev,struct avc_audit_data *ad, -u16 family,char *addrp,int len) +u16 family, +char *addrp) {int err =0 ;u32 netif_perm, node_perm, node_sid, if_sid, send_perm =0 ;
@@ -3975,7 +3976,7 @@ static int selinux_ip_postroute_last_compat(struct sock *sk, struct net_device *if (err) goto out; - err =security_node_sid (family, addrp, len, &node_sid); + err =sel_netnode_sid (addrp, family, &node_sid);if (err) goto out;
@@ -4009,7 +4010,7 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, u16 family) {char *addrp; -int len, err =0 ; +int err =0 ;struct sock *sk;struct avc_audit_data ad;struct net_device *dev = (struct net_device *)out;
@@ -4026,13 +4027,13 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, ad.u.net.netif = dev->ifindex; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp, &len,0 , &proto); + err =selinux_parse_skb (skb, &ad, &addrp,0 , &proto);if (err) goto out;if (selinux_compat_net) err =selinux_ip_postroute_last_compat (sk, dev, &ad, - family, addrp, len); + family, addrp);else err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__SEND , &ad);
security/selinux/include/netnode.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Network node table +* +* SELinux must keep a mapping of network nodes to labels/SIDs. This +* mapping is maintained as part of the normal policy but a fast cache is +* needed to reduce the lookup overhead since most of these queries happen on +* a per-packet basis. +* +* Author: Paul Moore <[email protected]> +* +*/ + +/* +* (c) Copyright Hewlett-Packard Development Company, L.P., 2007 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _SELINUX_NETNODE_H +#define _SELINUX_NETNODE_H + +int sel_netnode_sid (void *addr,u16 family,u32 *sid); + +#endif
security/selinux/include/objsec.h +9 -0
@@ -99,6 +99,15 @@ struct netif_security_struct {u32 sid;/* SID for this interface */ }; +struct netnode_security_struct { +union { +__be32 ipv4;/* IPv4 node address */ +struct in6_addr ipv6;/* IPv6 node address */ + } addr; +u32 sid;/* SID for this node */ +u16 family;/* address family */ +}; +struct sk_security_struct {struct sock *sk;/* back pointer to sk object */ u32 sid;/* SID of this object */
security/selinux/netnode.c new file +351 -0
351 lines not on this page · raw message
--
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.
RFC PATCH v8 16/18 NetLabel: Introduce static network labels for unlabeled connections
In reply to Paul MooreMost trusted OSs, with the exception of Linux, have the ability to specify static security labels for unlabeled networks. This patch adds this ability to the NetLabel packet labeling framework.
If the NetLabel subsystem is called to determine the security attributes of an incoming packet it first checks to see if any recognized NetLabel packet labeling protocols are in-use on the packet. If none can be found then the unlabled connection table is queried and based on the packets incoming interface and address it is matched with a security label as configured by the administrator using the netlabel_tools package. The matching security label is returned to the caller just as if the packet was explicitly labeled using a labeling protocol.
---
include/net/netlabel.h | 6 net/netlabel/netlabel_kapi.c | 16 net/netlabel/netlabel_unlabeled.c | 1367 +++++++++++++++++++++++++++++++++++++ net/netlabel/netlabel_unlabeled.h | 145 ++++ 4 files changed, 1516 insertions(+), 18 deletions(-)
include/net/netlabel.h +5 -1
@@ -67,7 +67,11 @@* NetLabel NETLINK protocol */ -#define NETLBL_PROTO_VERSION 1 +/* NetLabel NETLINK protocol version +* 1: initial version +* 2: added static labels for unlabeled connections +*/ +#define NETLBL_PROTO_VERSION 2/* NetLabel NETLINK types/families */ #define NETLBL_NLTYPE_NONE 0
net/netlabel/netlabel_kapi.c +7 -9
@@ -312,7 +312,7 @@ socket_setattr_return:* @secattr: the security attributes * * Description: -* Examines the given sock to see any NetLabel style labeling has been +* Examines the given sock to see if any NetLabel style labeling has been * applied to the sock, if so it parses the socket label and returns the * security attributes in @secattr. Returns zero on success, negative values * on failure.
@@ -320,13 +320,7 @@ socket_setattr_return:*/ int netlbl_sock_getattr (struct sock *sk,struct netlbl_lsm_secattr *secattr) { -int ret_val; - - ret_val =cipso_v4_sock_getattr (sk, secattr); -if (ret_val ==0 ) -return 0 ; - -return netlbl_unlabel_getattr (secattr); +return cipso_v4_sock_getattr (sk, secattr); }/**
@@ -350,7 +344,7 @@ int netlbl_skbuff_getattr(const struct sk_buff *skb, cipso_v4_skbuff_getattr(skb, secattr) == 0)return 0 ; -return netlbl_unlabel_getattr (secattr); +return netlbl_unlabel_getattr (skb, family, secattr); }/**
@@ -434,6 +428,10 @@ static int __init netlbl_init(void)if (ret_val !=0 ) goto init_failure; + ret_val =netlbl_unlabel_init (NETLBL_UNLHSH_BITSIZE ); +if (ret_val !=0 ) + goto init_failure; + ret_val =netlbl_netlink_init ();if (ret_val !=0 ) goto init_failure;
net/netlabel/netlabel_unlabeled.c +1360 -7
1,449 lines not on this page · raw message
net/netlabel/netlabel_unlabeled.h +144 -1
170 lines not on this page · raw message
--
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.
RFC PATCH v8 11/18 SELinux: Add a capabilities bitmap to SELinux policy version 22
In reply to Paul MooreAdd a new policy capabilities bitmap to SELinux policy version 22. This bitmap will enable the security server to query the policy to determine which features it supports.
---
security/selinux/Kconfig | 2 - security/selinux/include/security.h | 15 ++++++ security/selinux/selinuxfs.c | 89 +++++++++++++++++++++++++++++++++-- security/selinux/ss/policydb.c | 18 +++++++ security/selinux/ss/policydb.h | 2 + security/selinux/ss/services.c | 67 ++++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 8 deletions(-)
security/selinux/Kconfig +1 -1
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE int "NSA SELinux maximum supported policy format version value" depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX - range 15 21 + range 15 22 default 19 help This option sets the value for the maximum policy format version
security/selinux/include/security.h +14 -1
@@ -25,13 +25,14 @@#define POLICYDB_VERSION_MLS 19#define POLICYDB_VERSION_AVTAB 20#define POLICYDB_VERSION_RANGETRANS 21 +#define POLICYDB_VERSION_POLCAP 22/* Range of policy versions we understand*/ #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE#ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX #define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE#else -#define POLICYDB_VERSION_MAX POLICYDB_VERSION_RANGETRANS +#define POLICYDB_VERSION_MAX POLICYDB_VERSION_POLCAP#endif struct netlbl_lsm_secattr ;
@@ -39,8 +40,19 @@ struct netlbl_lsm_secattr;extern int selinux_enabled;extern int selinux_mls_enabled; +/* Policy capabilities */ +enum { +POLICYDB_CAPABILITY_NETPEER , + __POLICYDB_CAPABILITY_MAX +}; +#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1) + +extern int selinux_policycap_netpeer; +int security_load_policy (void * data,size_t len); +int security_policycap_supported (unsigned int req_cap); +#define SEL_VEC_MAX 32struct av_decision {u32 allowed;
@@ -91,6 +103,7 @@ int security_get_classes(char ***classes, int *nclasses);int security_get_permissions (char *class,char ***perms,int *nperms);int security_get_reject_unknown (void );int security_get_allow_unknown (void ); +int security_get_policycaps (int *len,int **values);#define SECURITY_FS_USE_XATTR 1/* use xattr */ #define SECURITY_FS_USE_TRANS 2/* use transition SIDs, e.g. devpts/tmpfs */
security/selinux/selinuxfs.c +85 -4
143 lines not on this page · raw message
security/selinux/ss/policydb.c +17 -1
@@ -13,6 +13,11 @@* * Added conditional policy language extensions * +* Updated: Hewlett-Packard <[email protected]> +* +* Added support for the policy capability bitmap +* +* Copyright (C) 2007 Hewlett-Packard Development Company, L.P. * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. * Copyright (C) 2003 - 2004 Tresys Technology, LLC * This program is free software; you can redistribute it and/or modify
@@ -102,6 +107,11 @@ static struct policydb_compat_info policydb_compat[] = { .sym_num = SYM_NUM, .ocon_num = OCON_NUM, }, + { + .version = POLICYDB_VERSION_POLCAP, + .sym_num = SYM_NUM, + .ocon_num = OCON_NUM, + } };static struct policydb_compat_info *policydb_lookup_compat (int version)
@@ -183,6 +193,8 @@ static int policydb_init(struct policydb *p)if (rc) goto out_free_symtab; +ebitmap_init (&p->policycaps); + out:return rc;
@@ -673,8 +685,8 @@ void policydb_destroy(struct policydb *p)ebitmap_destroy (&p->type_attr_map[i]); }kfree (p->type_attr_map); -kfree (p->undefined_perms); +ebitmap_destroy (&p->policycaps);return ; }
@@ -1554,6 +1566,10 @@ int policydb_read(struct policydb *p, void *fp) p->reject_unknown = !!(le32_to_cpu (buf[1 ]) &REJECT_UNKNOWN ); p->allow_unknown = !!(le32_to_cpu (buf[1 ]) &ALLOW_UNKNOWN ); +if (p->policyvers >=POLICYDB_VERSION_POLCAP && +ebitmap_read (&p->policycaps, fp) !=0 ) + goto bad; + info =policydb_lookup_compat (p->policyvers);if (!info) { printk(KERN_ERR "security: unable to find policy compat info "
security/selinux/ss/policydb.h +2 -0
@@ -241,6 +241,8 @@ struct policydb {/* type -> attribute reverse mapping */ struct ebitmap *type_attr_map; +struct ebitmap policycaps; +unsigned int policyvers; unsigned int reject_unknown : 1;
security/selinux/ss/services.c +66 -1
108 lines not on this page · raw message
--
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.
RFC PATCH v8 18/18 SELinux: Add network ingress and egress control permission checks
In reply to Paul MooreThis patch implements packet ingress/egress controls for SELinux which allow SELinux security policy to control the flow of all IPv4 and IPv6 packets into and out of the system. Currently SELinux does not have proper control over forwarded packets and this patch corrects this problem.
Special thanks to Venkat Yekkirala <[email protected]> whose earlier work on this topic eventually led to this patch.
---
security/selinux/hooks.c | 335 +++++++++++++++++++++++++++++++--------------- 1 files changed, 228 insertions(+), 107 deletions(-)
security/selinux/hooks.c +228 -107
@@ -12,8 +12,8 @@* Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]> * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. * <[email protected]> -* Copyright (C) 2006 Hewlett-Packard Development Company, L.P. -* Paul Moore, <[email protected]> +* Copyright (C) 2006, 2007 Hewlett-Packard Development Company, L.P. +* Paul Moore <[email protected]> * Copyright (C) 2007 Hitachi Software Engineering Co., Ltd. * Yuichi Nakamura <[email protected]> *
@@ -3608,6 +3608,71 @@ static int selinux_socket_unix_may_send(struct socket *sock,return 0 ; } +static int selinux_inet_sys_rcv_skb (int ifindex,char *addrp,u16 family, +u32 peer_sid, +struct avc_audit_data *ad) +{ +int err; +u32 if_sid; +u32 node_sid; + + err =sel_netif_sid (ifindex, &if_sid); +if (err) +return err; + err =avc_has_perm (if_sid, peer_sid,SECCLASS_PEER ,PEER__INGRESS , ad); +if (err) +return err; + + err =sel_netnode_sid (addrp, family, &node_sid); +if (err) +return err; +return avc_has_perm (node_sid, peer_sid, +SECCLASS_PEER ,PEER__INGRESS , ad); +} + +static int selinux_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +int err =0 ; + +if (!selinux_policycap_netpeer) +return 0 ; + +if (netlbl_enabled () ||selinux_xfrm_enabled ()) { +u32 if_sid; +u32 node_sid; +u32 peer_sid; +char *addrp; +struct avc_audit_data ad; + +AVC_AUDIT_DATA_INIT (&ad,NET ); + ad.u.net.netif = skb->iif; + ad.u.net.family = family; + err =selinux_parse_skb (skb, &ad, &addrp,0 ,NULL ); +if (err) +return err; + + err =selinux_skb_peerlbl_sid (skb, family, &peer_sid); +if (err) +return err; + + err =sel_netif_sid (skb->iif, &if_sid); +if (err) +return err; + err =avc_has_perm (if_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad); +if (err) +return err; + + err =sel_netnode_sid (addrp, family, &node_sid); +if (err) +return err; + err =avc_has_perm (node_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad); + } + +return err; +} + static int selinux_sock_rcv_skb_iptables_compat(struct sock *sk, struct sk_buff *skb, struct avc_audit_data *ad,
@@ -3748,6 +3813,10 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) err =selinux_skb_peerlbl_sid (skb, family, &peer_sid);if (err)return err; + err =selinux_inet_sys_rcv_skb (skb->iif, addrp, family, + peer_sid, &ad); +if (err) +return err; err =avc_has_perm (sk_sid, peer_sid,SECCLASS_PEER ,PEER__RECV , &ad); }
@@ -3965,151 +4034,175 @@ out:#ifdef CONFIG_NETFILTER -static int selinux_ip_postroute_last_compat (struct sock *sk, -struct net_device *dev, -struct avc_audit_data *ad, -u16 family, -char *addrp) +static unsigned int selinux_ip_forward (struct sk_buff *skb,int ifindex, +u16 family) { -int err =0 ; -u32 netif_perm, node_perm, node_sid, if_sid, send_perm =0 ; -struct socket *sock; -struct inode *inode; -struct inode_security_struct *isec; +if (!selinux_policycap_netpeer) +return NF_ACCEPT ; - sock = sk->sk_socket; -if (!sock) - goto out; +if (netlbl_enabled () ||selinux_xfrm_enabled ()) { +char *addrp; +u32 peer_sid; +struct avc_audit_data ad; - inode =SOCK_INODE (sock); -if (!inode) - goto out; +AVC_AUDIT_DATA_INIT (&ad,NET ); + ad.u.net.netif = ifindex; + ad.u.net.family = family; +if (selinux_parse_skb (skb, &ad, &addrp,1 ,NULL ) !=0 ) +return NF_DROP ; + +if (selinux_skb_peerlbl_sid (skb, family, &peer_sid) !=0 ) +return NF_DROP ; +if (selinux_inet_sys_rcv_skb (ifindex, addrp, family, + peer_sid, &ad) !=0 ) +return NF_DROP ; + } - isec = inode->i_security; - - err =sel_netif_sid (dev->ifindex, &if_sid); -if (err) - goto out; +return NF_ACCEPT ; +} + +static unsigned int selinux_ipv4_forward (unsigned int hooknum, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +return selinux_ip_forward (skb, in->ifindex,PF_INET ); +} + +#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) +static unsigned int selinux_ipv6_forward (unsigned int hooknum, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +return selinux_ip_forward (skb, in->ifindex,PF_INET6 ); +} +#endif /* IPV6 */ -switch (isec->sclass) { +static int selinux_ip_postroute_compat (struct sock *sk, +int ifindex, +struct avc_audit_data *ad, +u16 family,char *addrp) +{ +int err; +struct sk_security_struct *sksec = sk->sk_security; +u16 sk_class; +u32 netif_perm, node_perm, send_perm; +u32 port_sid, node_sid, if_sid, sk_sid; + + sk_sid = sksec->sid; + sk_class = sksec->sclass; + +switch (sk_class) {case SECCLASS_UDP_SOCKET : netif_perm =NETIF__UDP_SEND ; node_perm =NODE__UDP_SEND ; send_perm =UDP_SOCKET__SEND_MSG ;break ; -case SECCLASS_TCP_SOCKET : netif_perm =NETIF__TCP_SEND ; node_perm =NODE__TCP_SEND ; send_perm =TCP_SOCKET__SEND_MSG ;break ; -case SECCLASS_DCCP_SOCKET : netif_perm =NETIF__DCCP_SEND ; node_perm =NODE__DCCP_SEND ; send_perm =DCCP_SOCKET__SEND_MSG ;break ; -default : netif_perm =NETIF__RAWIP_SEND ; node_perm =NODE__RAWIP_SEND ; + send_perm =0 ;break ; } - err =avc_has_perm (isec->sid, if_sid,SECCLASS_NETIF , netif_perm, ad); + err =sel_netif_sid (ifindex, &if_sid);if (err) - goto out; +return err; + err =avc_has_perm (sk_sid, if_sid,SECCLASS_NETIF , netif_perm, ad); +if (err) +return err; err =sel_netnode_sid (addrp, family, &node_sid);if (err) - goto out; - - err =avc_has_perm (isec->sid, node_sid,SECCLASS_NODE , node_perm, ad); +return err; + err =avc_has_perm (sk_sid, node_sid,SECCLASS_NODE , node_perm, ad);if (err) - goto out; - -if (send_perm) { -u32 port_sid; - - err =security_port_sid (sk->sk_family, - sk->sk_type, - sk->sk_protocol, -ntohs (ad->u.net.dport), - &port_sid); -if (err) - goto out; +return err; - err =avc_has_perm (isec->sid, port_sid, isec->sclass, - send_perm, ad); - } -out: -return err; +if (!send_perm) +return 0 ; + err =security_port_sid (sk->sk_family, sk->sk_type, + sk->sk_protocol,ntohs (ad->u.net.dport), + &port_sid); +if (err) +return err; +return avc_has_perm (sk_sid, port_sid, sk_class, send_perm, ad); } -static unsigned int selinux_ip_postroute_last (unsigned int hooknum, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *), -u16 family) +static unsigned int selinux_ip_postroute (struct sk_buff *skb,int ifindex, +u16 family) { -char *addrp; -int err =0 ; +int err;struct sock *sk; -struct avc_audit_data ad; -struct net_device *dev = (struct net_device *)out;struct sk_security_struct *sksec; +struct avc_audit_data ad; +char *addrp;u8 proto; sk = skb->sk;if (!sk) - goto out; - +return NF_ACCEPT ; sksec = sk->sk_security;AVC_AUDIT_DATA_INIT (&ad,NET ); - ad.u.net.netif = dev->ifindex; + ad.u.net.netif = ifindex; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp,0 , &proto);if (err) - goto out; +return NF_DROP ;if (selinux_compat_net) - err =selinux_ip_postroute_last_compat (sk, dev, &ad, - family, addrp); + err =selinux_ip_postroute_compat (sk, ifindex, &ad, + family, addrp);else err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__SEND , &ad); -if (err) - goto out; +return NF_DROP ; - err =selinux_xfrm_postroute_last (sksec->sid, skb, &ad, proto); -out: -return err ?NF_DROP :NF_ACCEPT ; +if (!selinux_policycap_netpeer) { +/* If the network peer controls are enabled we handle all the +* outbound peer label access checks in the +* selinux_inet_sys_snd_skb() hook. */ + err =selinux_xfrm_postroute_last (sksec->sid, skb, &ad, proto); +if (err) +return NF_DROP ; + } + +return NF_ACCEPT ; } -static unsigned int selinux_ipv4_postroute_last (unsigned int hooknum, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int selinux_ipv4_postroute (unsigned int hooknum, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -return selinux_ip_postroute_last (hooknum, skb, in, out, okfn,PF_INET ); +return selinux_ip_postroute (skb, out->ifindex,PF_INET ); }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) - -static unsigned int selinux_ipv6_postroute_last (unsigned int hooknum, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)) +static unsigned int selinux_ipv6_postroute (unsigned int hooknum, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -return selinux_ip_postroute_last (hooknum, skb, in, out, okfn,PF_INET6 ); +return selinux_ip_postroute (skb, out->ifindex,PF_INET6 ); } -#endif /* IPV6 */ #endif /* CONFIG_NETFILTER */
@@ -4991,6 +5084,7 @@ static struct security_operations selinux_ops = { .inet_csk_clone = selinux_inet_csk_clone, .inet_conn_established = selinux_inet_conn_established, .req_classify_flow = selinux_req_classify_flow, + .inet_sys_snd_skb = selinux_inet_sys_snd_skb, #ifdef CONFIG_SECURITY_NETWORK_XFRM .xfrm_policy_alloc_security = selinux_xfrm_policy_alloc,
@@ -5094,22 +5188,40 @@ security_initcall(selinux_init);#if defined(CONFIG_NETFILTER ) -static struct nf_hook_ops selinux_ipv4_op = { - .hook = selinux_ipv4_postroute_last, - .owner =THIS_MODULE , - .pf =PF_INET , - .hooknum =NF_IP_POST_ROUTING , - .priority =NF_IP_PRI_SELINUX_LAST , +static struct nf_hook_ops selinux_ipv4_ops[] = { + { + .hook = selinux_ipv4_postroute, + .owner =THIS_MODULE , + .pf =PF_INET , + .hooknum =NF_IP_POST_ROUTING , + .priority =NF_IP_PRI_SELINUX_LAST , + }, + { + .hook = selinux_ipv4_forward, + .owner =THIS_MODULE , + .pf =PF_INET , + .hooknum =NF_IP_FORWARD , + .priority =NF_IP_PRI_SELINUX_FIRST , + } };#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -static struct nf_hook_ops selinux_ipv6_op = { - .hook = selinux_ipv6_postroute_last, - .owner =THIS_MODULE , - .pf =PF_INET6 , - .hooknum =NF_IP6_POST_ROUTING , - .priority =NF_IP6_PRI_SELINUX_LAST , +static struct nf_hook_ops selinux_ipv6_ops[] = { + { + .hook = selinux_ipv6_postroute, + .owner =THIS_MODULE , + .pf =PF_INET6 , + .hooknum =NF_IP6_POST_ROUTING , + .priority =NF_IP6_PRI_SELINUX_LAST , + }, + { + .hook = selinux_ipv6_forward, + .owner =THIS_MODULE , + .pf =PF_INET6 , + .hooknum =NF_IP6_FORWARD , + .priority =NF_IP6_PRI_SELINUX_FIRST , + } };#endif /* IPV6 */
@@ -5117,22 +5229,27 @@ static struct nf_hook_ops selinux_ipv6_op = {static int __init selinux_nf_ip_init (void ) {int err =0 ; +u32 iter;if (!selinux_enabled) goto out;printk (KERN_DEBUG "SELinux: Registering netfilter hooks\n" ); - err =nf_register_hook (&selinux_ipv4_op); -if (err) -panic ("SELinux: nf_register_hook for IPv4: error %d\n" , err); +for (iter =0 ; iter <ARRAY_SIZE (selinux_ipv4_ops); iter++) { + err =nf_register_hook (&selinux_ipv4_ops[iter]); +if (err) +panic ("SELinux: nf_register_hook for IPv4: error %d\n" , + err); + }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) - - err =nf_register_hook (&selinux_ipv6_op); -if (err) -panic ("SELinux: nf_register_hook for IPv6: error %d\n" , err); - +for (iter =0 ; iter <ARRAY_SIZE (selinux_ipv6_ops); iter++) { + err =nf_register_hook (&selinux_ipv6_ops[iter]); +if (err) +panic ("SELinux: nf_register_hook for IPv6: error %d\n" , + err); + }#endif /* IPV6 */ out:
@@ -5144,11 +5261,15 @@ __initcall(selinux_nf_ip_init);#ifdef CONFIG_SECURITY_SELINUX_DISABLE static void selinux_nf_ip_exit (void ) { +u32 iter; +printk (KERN_DEBUG "SELinux: Unregistering netfilter hooks\n" ); -nf_unregister_hook (&selinux_ipv4_op); +for (iter =0 ; iter <ARRAY_SIZE (selinux_ipv4_ops); iter++) +nf_unregister_hook (&selinux_ipv4_ops[iter]);#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -nf_unregister_hook (&selinux_ipv6_op); +for (iter =0 ; iter <ARRAY_SIZE (selinux_ipv6_ops); iter++) +nf_unregister_hook (&selinux_ipv6_ops[iter]);#endif /* IPV6 */ }#endif
--
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: [RFC PATCH v8 18/18] SELinux: Add network ingress and egress control permission checks
Quoted 7 lines · Paul Moore
This patch implements packet ingress/egress controls for SELinux which allow SELinux security policy to control the flow of all IPv4 and IPv6 packets into and out of the system. Currently SELinux does not have proper control over forwarded packets and this patch corrects this problem.
Special thanks to Venkat Yekkirala <[email protected]> whose earlier work on this topic eventually led to this patch.
I've been thinking about this over the weekend and realized a few things ...
{snip}
Quoted 14 lines
security/selinux/hooks.c +14
-0+static int selinux_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +int err =0 ; + +if (!selinux_policycap_netpeer) +return 0 ; + +if (netlbl_enabled () ||selinux_xfrm_enabled ()) { +u32 if_sid; +u32 node_sid; +u32 peer_sid; +char *addrp; +struct avc_audit_data ad; +
security/selinux/hooks.c static int selinux_socket_unix_may_send(struct socket *sock, · line 3656
Quoted 10 lines
security/selinux/hooks.c +10
-0+AVC_AUDIT_DATA_INIT (&ad,NET ); + ad.u.net.netif = skb->iif; + ad.u.net.family = family; + err =selinux_parse_skb (skb, &ad, &addrp,0 ,NULL ); +if (err) +return err; + + err =selinux_skb_peerlbl_sid (skb, family, &peer_sid); +if (err) +return err;
I realized I made a mistake here: we should check to see if the skb has a socket associated with it and if it does get the peer_sid from there instead. If there is no socket to be found then do what we are already going above.
security/selinux/hooks.c static int selinux_socket_unix_may_send(struct socket *sock, · line 3670
Quoted 13 lines
security/selinux/hooks.c +13
-0+ err =sel_netif_sid (skb->iif, &if_sid); +if (err) +return err; + err =avc_has_perm (if_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad); +if (err) +return err; + + err =sel_netnode_sid (addrp, family, &node_sid); +if (err) +return err; + err =avc_has_perm (node_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad);
We should probably have different permissions for the interface and node cases. Take the example of an admin who is only interested in enforcing interface controls and not node controls. They would most likely write the following policy rule to nullify the node check ...
allow unlabeled_t peer_t:peer egress;
... which would end up applying to both the interface and node checks because they use the same permission. I'm thinking we should split the permissions like this:
allow netif_t peer_t:peer if_egress;
allow netnode_t peer_t: peer node_egress;
... and do something similar for the ingress side. Thoughts?
Quoted 4 lines
security/selinux/hooks.c +4
-0+ } + +return err; +}
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 06/18] LSM: Add inet_sys_snd_skb() LSM hook
In reply to Paul MooreQuoted 5 lines · Paul Moore
Add an
inet_sys_snd_skb()LSM hook to allow the LSM to provide packet level access control for all outbound packets. Using the existingpostroute_lastnetfilter hook turns out to be problematic as it is can be invoked multiple times for a single packet, e.g. individual IPsec transforms, adding unwanted overhead and complicating the security policy.
None of the netfilter hooks works for this purpose?
Obviously this one needs to get seen on netdev.
Quoted 144 lines
---
include/linux/security.h | 11 +++++++++++ net/ipv4/ip_output.c | 7 +++++++ net/ipv6/ip6_output.c | 5 +++++ security/dummy.c | 8 +++++++- security/security.c | 6 ++++++ 5 files changed, 36 insertions(+), 1 deletions(-)include/linux/security.h +11
-0@@ -876,6 +876,10 @@ struct request_sock;* Sets the connection's peersid to the secmark on skb. * @req_classify_flow: * Sets the flow's sid to the openreq sid. +* @inet_sys_snd_skb: +* Check permissions on outgoing network packets. +* @skb is the packet to check +* @family is the packet's address family * * Security hooks for XFRM operations. * @@ -1416,6 +1420,7 @@ struct security_operations {void (*inet_csk_clone)(struct sock *newsk,const struct request_sock *req);void (*inet_conn_established)(struct sock *sk,struct sk_buff *skb);void (*req_classify_flow)(const struct request_sock *req,struct flowi *fl); +int (*inet_sys_snd_skb)(struct sk_buff *skb,int family);#endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM @@ -2328,6 +2333,7 @@ void security_sk_free(struct sock *sk);void security_sk_clone (const struct sock *sk,struct sock *newsk);void security_sk_classify_flow (struct sock *sk,struct flowi *fl);void security_req_classify_flow (const struct request_sock *req,struct flowi *fl); +int security_inet_sys_snd_skb (struct sk_buff *skb,int family);void security_sock_graft (struct sock *sk,struct socket *parent);int security_inet_conn_request (struct sock *sk,struct sk_buff *skb,struct request_sock *req);@@ -2471,6 +2477,11 @@ static inline void security_req_classify_flow(const struct request_sock *req, st { } +static inline int security_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +return 0 ; +} +static inline void security_sock_graft (struct sock * sk,struct socket *parent) { }net/ipv4/ip_output.c +7
-0@@ -204,6 +204,8 @@ static inline int ip_skb_dst_mtu(struct sk_buff *skb)static int ip_finish_output (struct sk_buff *skb) { +int err; +#if defined(CONFIG_NETFILTER ) && defined(CONFIG_XFRM )/* Policy lookup after SNAT yielded a new policy */ if (skb->dst->xfrm !=NULL ) {@@ -211,6 +213,11 @@ static int ip_finish_output(struct sk_buff *skb) return dst_output(skb); }#endif + + err =security_inet_sys_snd_skb (skb,AF_INET ); +if (err) +return err; +if (skb->len >ip_skb_dst_mtu (skb) && !skb_is_gso (skb))return ip_fragment (skb, ip_finish_output2);else net/ipv6/ip6_output.c +5
-0@@ -72,8 +72,13 @@ static __inline__ void ipv6_select_ident(struct sk_buff *skb, struct frag_hdr *fstatic int ip6_output_finish (struct sk_buff *skb) { +int err;struct dst_entry *dst = skb->dst; + err =security_inet_sys_snd_skb (skb,AF_INET6 ); +if (err) +return err; +if (dst->hh)return neigh_hh_output (dst->hh, skb);else if (dst->neighbour)security/dummy.c +7
-1@@ -848,6 +848,11 @@ static inline void dummy_req_classify_flow(const struct request_sock *req, struct flowi *fl) { } + +static inline int dummy_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +return 0 ; +}#endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM @@ -1122,7 +1127,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, inet_csk_clone);set_to_dummy_if_null (ops, inet_conn_established);set_to_dummy_if_null (ops, req_classify_flow); -#endif /* CONFIG_SECURITY_NETWORK */ +set_to_dummy_if_null (ops, inet_sys_snd_skb); +#endif /* CONFIG_SECURITY_NETWORK */ #ifdef CONFIG_SECURITY_NETWORK_XFRM set_to_dummy_if_null (ops, xfrm_policy_alloc_security);set_to_dummy_if_null (ops, xfrm_policy_clone_security);security/security.c +6
-1@@ -961,6 +961,12 @@ void security_req_classify_flow(const struct request_sock *req, struct flowi *fl }EXPORT_SYMBOL (security_req_classify_flow); +int security_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +return security_ops->inet_sys_snd_skb (skb, family); +} +EXPORT_SYMBOL (security_inet_sys_snd_skb); +void security_sock_graft (struct sock *sk,struct socket *parent) { security_ops->sock_graft (sk, parent); --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.
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.
Re: [RFC PATCH v8 05/18] LSM: Add secctx_to_secid() LSM hook
In reply to Paul MooreQuoted 3 lines · Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook. This patch also includes the SELinux implementation for this hook.
This one can go up anytime, as we have other people wanting such a hook too.
Or alternatively we need to rationalize the entire selinux/exports interface with these hooks as used by the networking and audit subsystems, as that issue will be coming up anyway for other LSMs.
One thing to note is that some of these interfaces treat the context as an opaque byte array of a given length, while other ones depend on the context to be a NUL-terminated string (e.g. audit).
Quoted 124 lines
---
include/linux/security.h | 13 +++++++++++++ security/dummy.c | 6 ++++++ security/security.c | 6 ++++++ security/selinux/hooks.c | 6 ++++++ 4 files changed, 31 insertions(+), 0 deletions(-)include/linux/security.h +13
-0@@ -1183,6 +1183,10 @@ struct request_sock;* Convert secid to security context. * @secid contains the security ID. * @secdata contains the pointer that stores the converted security context. +* @secctx_to_secid: +* Convert security context to secid. +* @secid contains the pointer to the generated security ID. +* @secdata contains the security context. * * @release_secctx: * Release the security context. @@ -1371,6 +1375,7 @@ struct security_operations {int (*getprocattr)(struct task_struct *p,char *name,char **value);int (*setprocattr)(struct task_struct *p,char *name,void *value,size_t size);int (*secid_to_secctx)(u32 secid,char **secdata,u32 *seclen); +int (*secctx_to_secid)(char *secdata,u32 seclen,u32 *secid);void (*release_secctx)(char *secdata,u32 seclen);#ifdef CONFIG_SECURITY_NETWORK @@ -1603,6 +1608,7 @@ int security_setprocattr(struct task_struct *p, char *name, void *value, size_tint security_netlink_send (struct sock *sk,struct sk_buff *skb);int security_netlink_recv (struct sk_buff *skb,int cap);int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen); +int security_secctx_to_secid (char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen);#else /* CONFIG_SECURITY */ @@ -2280,6 +2286,13 @@ static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclereturn -EOPNOTSUPP ; } +static inline int security_secctx_to_secid (char *secdata, +u32 seclen, +u32 *secid) +{ +return -EOPNOTSUPP ; +} +static inline void security_release_secctx (char *secdata,u32 seclen) { }security/dummy.c +6
-0@@ -928,6 +928,11 @@ static int dummy_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)return -EOPNOTSUPP ; } +static int dummy_secctx_to_secid (char *secdata,u32 seclen,u32 *secid) +{ +return -EOPNOTSUPP ; +} +static void dummy_release_secctx (char *secdata,u32 seclen) { }@@ -1086,6 +1091,7 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, getprocattr);set_to_dummy_if_null (ops, setprocattr);set_to_dummy_if_null (ops, secid_to_secctx); +set_to_dummy_if_null (ops, secctx_to_secid);set_to_dummy_if_null (ops, release_secctx);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);security/security.c +6
-0@@ -816,6 +816,12 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) }EXPORT_SYMBOL (security_secid_to_secctx); +int security_secctx_to_secid (char *secdata,u32 seclen,u32 *secid) +{ +return security_ops->secctx_to_secid (secdata, seclen, secid); +} +EXPORT_SYMBOL (security_secctx_to_secid); +void security_release_secctx (char *secdata,u32 seclen) {return security_ops->release_secctx (secdata, seclen);security/selinux/hooks.c +6
-1@@ -4710,6 +4710,11 @@ static int selinux_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)return security_sid_to_context (secid, secdata, seclen); } +static int selinux_secctx_to_secid (char *secdata,u32 seclen,u32 *secid) +{ +return security_context_to_sid (secdata, seclen, secid); +} +static void selinux_release_secctx (char *secdata,u32 seclen) {kfree (secdata);@@ -4898,6 +4903,7 @@ static struct security_operations selinux_ops = { .setprocattr = selinux_setprocattr, .secid_to_secctx = selinux_secid_to_secctx, + .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx, .unix_stream_connect = selinux_socket_unix_stream_connect, --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.
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.
Re: [RFC PATCH v8 09/18] SELinux: Only store the network interface's ifindex
In reply to Paul MooreQuoted 74 lines · Paul Moore
Instead of storing the packet's network interface name store the ifindex. This allows us to defer the need to lookup the
net_devicestructure until the audit record is generated meaning that in the majority of cases we never need to bother with this at all.---
security/selinux/avc.c | 15 ++++++++++++--- security/selinux/hooks.c | 4 ++-- security/selinux/include/avc.h | 7 +++++-- 3 files changed, 19 insertions(+), 7 deletions(-)security/selinux/avc.c +12
-3@@ -661,9 +661,18 @@ void avc_audit(u32 ssid, u32 tsid, "daddr", "dest");break ; } -if (a->u.net.netif) -audit_log_format (ab," netif=%s" , - a->u.net.netif); +if (a->u.net.netif >=0 ) { +struct net_device *dev; + +/* NOTE: we always use init's namespace */ + dev =dev_get_by_index (&init_net, + a->u.net.netif); +if (dev) { +audit_log_format (ab," netif=%s" , + dev->name); +dev_put (dev); + } + }break ; } }security/selinux/hooks.c +2
-2@@ -3691,7 +3691,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) family =PF_INET ;AVC_AUDIT_DATA_INIT (&ad,NET ); - ad.u.net.netif = skb->dev ? skb->dev->name :"[unknown]" ; + ad.u.net.netif = skb->iif; ad.u.net.family = family; err =selinux_parse_skb (skb, &ad, &addrp, &len,1 ,NULL );@@ -4023,7 +4023,7 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, sksec = sk->sk_security;AVC_AUDIT_DATA_INIT (&ad,NET ); - ad.u.net.netif = dev->name; + ad.u.net.netif = dev->ifindex; ad.u.net.family = family; err =selinux_parse_skb (skb, &ad, &addrp, &len,0 , &proto);security/selinux/include/avc.h +1
-1@@ -51,7 +51,7 @@ struct avc_audit_data {struct inode *inode; } fs;struct { -char *netif; +int netif;struct sock *sk;u16 family;__be16 dport;
security/selinux/include/avc.h struct avc_audit_data { · line 83
Quoted 8 lines
security/selinux/include/avc.h +4
-1@@ -77,7 +77,10 @@ struct avc_audit_data {/* Initialize an AVC audit data structure. */ #define AVC_AUDIT_DATA_INIT (_d,_t) \ - { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; } + { memset((_d), 0, sizeof(struct avc_audit_data)); \ + (_d)->type = AVC_AUDIT_DATA_##_t; \ + if ((_d)->type == AVC_AUDIT_DATA_NET) \ + (_d)->u.net.netif = -1; }
As a minor nit, at the same time you do this, turn this into a static inline function please.
Quoted 9 lines
security/selinux/include/avc.h +0
-1/* * AVC statistics -- 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.
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.
Re: [RFC PATCH v8 18/18] SELinux: Add network ingress and egress control permission checks
In reply to Paul MooreQuoted 33 lines · Paul Moore
Quoted 7 lines · Paul Moore
This patch implements packet ingress/egress controls for SELinux which allow SELinux security policy to control the flow of all IPv4 and IPv6 packets into and out of the system. Currently SELinux does not have proper control over forwarded packets and this patch corrects this problem.
Special thanks to Venkat Yekkirala <[email protected]> whose earlier work on this topic eventually led to this patch.
I've been thinking about this over the weekend and realized a few things ...
{snip}
Quoted 20 lines
security/selinux/hooks.c +20
-0+static int selinux_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +int err =0 ; + +if (!selinux_policycap_netpeer) +return 0 ; + +if (netlbl_enabled () ||selinux_xfrm_enabled ()) { +u32 if_sid; +u32 node_sid; +u32 peer_sid; +char *addrp; +struct avc_audit_data ad; + +AVC_AUDIT_DATA_INIT (&ad,NET ); + ad.u.net.netif = skb->iif; + ad.u.net.family = family; + err =selinux_parse_skb (skb, &ad, &addrp,0 ,NULL ); +if (err) +return err;
Quoted 8 lines
security/selinux/hooks.c static int selinux_socket_unix_may_send(struct socket *sock, · line 3656
Quoted 4 lines
security/selinux/hooks.c +4
-0+ + err =selinux_skb_peerlbl_sid (skb, family, &peer_sid); +if (err) +return err;I realized I made a mistake here: we should check to see if the skb has a socket associated with it and if it does get the
peer_sidfrom there instead. If there is no socket to be found then do what we are already going above.
In what case do you expect the two SIDs to diverge?
What if we later provide an API to allow a sender to send a datagram with a particular label rather than always requiring them to be the same as the sending socket?
Quoted 21 lines
security/selinux/hooks.c static int selinux_socket_unix_may_send(struct socket *sock, · line 3670
Quoted 13 lines
security/selinux/hooks.c +13
-0+ err =sel_netif_sid (skb->iif, &if_sid); +if (err) +return err; + err =avc_has_perm (if_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad); +if (err) +return err; + + err =sel_netnode_sid (addrp, family, &node_sid); +if (err) +return err; + err =avc_has_perm (node_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad);We should probably have different permissions for the interface and node cases. Take the example of an admin who is only interested in enforcing interface controls and not node controls. They would most likely write the following policy rule to nullify the node check ...
allow
unlabeled_tpeer_t:peer egress;
Quoted 8 lines
... which would end up applying to both the interface and node checks because they use the same permission. I'm thinking we should split the permissions like this:
allow
netif_tpeer_t:peerif_egress;
allownetnode_tpeer_t: peernode_egress;... and do something similar for the ingress side. Thoughts?
That starts to sound a lot like using netif and node classes instead of the peer class.
allow peer_t netif_t:netif egress; allow peer_t netnode_t:node egress;
Quoted 6 lines
Quoted 5 lines
security/selinux/hooks.c +4
-0+ } + +return err; +}
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.
Re: [RFC PATCH v8 10/18] SELinux: Add a network node caching mechanism similar to the sel_netif_*() functions
In reply to Paul MooreQuoted 5 lines · Paul Moore
This patch adds a SELinux IP address/node SID caching mechanism similar to the sel_netif_*() functions. The node SID queries in the SELinux hooks files are also modified to take advantage of this new functionality. In addition, remove the address length information from the
sk_buffparsing routines as it is redundant since we already have the address family.
This is very nice - we also need the same kind of cache for port SIDs.
Quoted 588 lines
---
security/selinux/Makefile | 9 + security/selinux/hooks.c | 33 ++- security/selinux/include/netnode.h | 32 +++ security/selinux/include/objsec.h | 9 + security/selinux/netnode.c | 351 ++++++++++++++++++++++++++++++++++++ 5 files changed, 417 insertions(+), 17 deletions(-)security/selinux/Makefile +8
-1@@ -4,7 +4,14 @@ obj-$(CONFIG_SECURITY_SELINUX) := selinux.o ss/ -selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o netif.o exports.o +selinux-y := avc.o \ + hooks.o \ + selinuxfs.o \ + netlink.o \ + nlmsgtab.o \ + netif.o \ + netnode.o \ + exports.o selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.osecurity/selinux/hooks.c +17
-16@@ -76,6 +76,7 @@#include "avc.h" #include "objsec.h" #include "netif.h" +#include "netnode.h" #include "xfrm.h" #include "netlabel.h" @@ -3158,7 +3159,7 @@ out:#endif /* IPV6 */ static int selinux_parse_skb (struct sk_buff *skb,struct avc_audit_data *ad, -char **addrp,int *len,int src,u8 *proto) +char **addrp,int src,u8 *proto) {int ret =0 ;@@ -3167,7 +3168,6 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad, ret =selinux_parse_skb_ipv4 (skb, ad, proto);if (ret || !addrp)break ; - *len =4 ; *addrp = (char *)(src ? &ad->u.net.v4info.saddr : &ad->u.net.v4info.daddr);break ;@@ -3177,7 +3177,6 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad, ret =selinux_parse_skb_ipv6 (skb, ad, proto);if (ret || !addrp)break ; - *len =16 ; *addrp = (char *)(src ? &ad->u.net.v6info.saddr : &ad->u.net.v6info.daddr);break ;@@ -3377,7 +3376,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, inbreak ; } - err =security_node_sid (family, addrp, addrlen, &sid); + err =sel_netnode_sid (addrp, family, &sid);if (err) goto out;@@ -3589,7 +3588,8 @@ static int selinux_socket_unix_may_send(struct socket *sock, }static int selinux_sock_rcv_skb_compat (struct sock *sk,struct sk_buff *skb, -struct avc_audit_data *ad,u16 family,char *addrp,int len) +struct avc_audit_data *ad, +u16 family,char *addrp) {int err =0 ;u32 netif_perm, node_perm, node_sid, if_sid, recv_perm =0 ;@@ -3649,7 +3649,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,if (err) goto out; - err =security_node_sid (family, addrp, len, &node_sid); + err =sel_netnode_sid (addrp, family, &node_sid);if (err) goto out;@@ -3678,7 +3678,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) {u16 family;char *addrp; -int len, err =0 ; +int err =0 ;struct avc_audit_data ad;struct sk_security_struct *sksec = sk->sk_security;@@ -3694,13 +3694,12 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ad.u.net.netif = skb->iif; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp, &len,1 ,NULL ); + err =selinux_parse_skb (skb, &ad, &addrp,1 ,NULL );if (err) goto out;if (selinux_compat_net) - err =selinux_sock_rcv_skb_compat (sk, skb, &ad, family, - addrp, len); + err =selinux_sock_rcv_skb_compat (sk, skb, &ad, family, addrp);else err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__RECV , &ad);@@ -3922,9 +3921,11 @@ out:#ifdef CONFIG_NETFILTER -static int selinux_ip_postroute_last_compat (struct sock *sk,struct net_device *dev, +static int selinux_ip_postroute_last_compat (struct sock *sk, +struct net_device *dev,struct avc_audit_data *ad, -u16 family,char *addrp,int len) +u16 family, +char *addrp) {int err =0 ;u32 netif_perm, node_perm, node_sid, if_sid, send_perm =0 ;@@ -3975,7 +3976,7 @@ static int selinux_ip_postroute_last_compat(struct sock *sk, struct net_device *if (err) goto out; - err =security_node_sid (family, addrp, len, &node_sid); + err =sel_netnode_sid (addrp, family, &node_sid);if (err) goto out;@@ -4009,7 +4010,7 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, u16 family) {char *addrp; -int len, err =0 ; +int err =0 ;struct sock *sk;struct avc_audit_data ad;struct net_device *dev = (struct net_device *)out;@@ -4026,13 +4027,13 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, ad.u.net.netif = dev->ifindex; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp, &len,0 , &proto); + err =selinux_parse_skb (skb, &ad, &addrp,0 , &proto);if (err) goto out;if (selinux_compat_net) err =selinux_ip_postroute_last_compat (sk, dev, &ad, - family, addrp, len); + family, addrp);else err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__SEND , &ad);security/selinux/include/netnode.h new file +32
-0@@ -0,0 +1,32 @@ +/* +* Network node table +* +* SELinux must keep a mapping of network nodes to labels/SIDs. This +* mapping is maintained as part of the normal policy but a fast cache is +* needed to reduce the lookup overhead since most of these queries happen on +* a per-packet basis. +* +* Author: Paul Moore <[email protected]> +* +*/ + +/* +* (c) Copyright Hewlett-Packard Development Company, L.P., 2007 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _SELINUX_NETNODE_H +#define _SELINUX_NETNODE_H + +int sel_netnode_sid (void *addr,u16 family,u32 *sid); + +#endif security/selinux/include/objsec.h +9
-0@@ -99,6 +99,15 @@ struct netif_security_struct {u32 sid;/* SID for this interface */ }; +struct netnode_security_struct { +union { +__be32 ipv4;/* IPv4 node address */ +struct in6_addr ipv6;/* IPv6 node address */ + } addr; +u32 sid;/* SID for this node */ +u16 family;/* address family */ +}; +struct sk_security_struct {struct sock *sk;/* back pointer to sk object */ u32 sid;/* SID of this object */ security/selinux/netnode.c new file +351
-1@@ -0,0 +1,351 @@ +/* +* Network node table +* +* SELinux must keep a mapping of network nodes to labels/SIDs. This +* mapping is maintained as part of the normal policy but a fast cache is +* needed to reduce the lookup overhead since most of these queries happen on +* a per-packet basis. +* +* Author: Paul Moore <[email protected]> +* +* This code is heavily based on the "netif" concept originally developed by +* James Morris <[email protected]> +* (see security/selinux/netif.c for more information) +* +*/ + +/* +* (c) Copyright Hewlett-Packard Development Company, L.P., 2007 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/types.h> +#include <linux/rcupdate.h> +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/in.h> +#include <linux/in6.h> +#include <linux/ip.h> +#include <linux/ipv6.h> +#include <net/ip.h> +#include <net/ipv6.h> +#include <asm/bug.h> + +#include "objsec.h" + +#define SEL_NETNODE_HASH_SIZE 256 +#define SEL_NETNODE_HASH_BKT_LIMIT 16 + +struct sel_netnode { +struct netnode_security_struct nsec; + +struct list_head list; +struct rcu_head rcu; +}; + +/* NOTE: we are using a combined hash table for both IPv4 and IPv6, the reason +* for this is that I suspect most users will not make heavy use of both +* address families at the same time so one table will usually end up wasted, +* if this becomes a problem we can always add a hash table for each address +* family later */ + +static LIST_HEAD (sel_netnode_list); +static DEFINE_SPINLOCK (sel_netnode_lock); +static struct list_head sel_netnode_hash[SEL_NETNODE_HASH_SIZE ]; + +/** +* sel_netnode_free - Frees a node entry +* @p: the entry's RCU field +* +* Description: +* This function is designed to be used as a callback to the call_rcu() +* function so that memory allocated to a hash table node entry can be +* released safely. +* +*/ +static void sel_netnode_free (struct rcu_head *p) +{ + struct sel_netnode *node = container_of(p, struct sel_netnode, rcu); +kfree (node); +} + +/** +* sel_netnode_hashfn_ipv4 - IPv4 hashing function for the node table +* @addr: IPv4 address +* +* Description: +* This is the IPv4 hashing function for the node interface table, it returns +* the bucket number for the given IP address. +* +*/ +static u32 sel_netnode_hashfn_ipv4 (__be32 addr) +{ +/* at some point we should determine if the mismatch in byte order +* affects the hash function dramatically */ +return (addr & (SEL_NETNODE_HASH_SIZE -1 )); +} + +/** +* sel_netnode_hashfn_ipv6 - IPv6 hashing function for the node table +* @addr: IPv6 address +* +* Description: +* This is the IPv6 hashing function for the node interface table, it returns +* the bucket number for the given IP address. +* +*/ +static u32 sel_netnode_hashfn_ipv6 (const struct in6_addr *addr) +{ +/* just hash the least significant 32 bits to keep things fast (they +* are the most likely to be different anyway), we can revisit this +* later if needed */ +return (addr->s6_addr32[3 ] & (SEL_NETNODE_HASH_SIZE -1 )); +} + +/** +* sel_netnode_find - Search for a node record +* @addr: IP address +* @family: address family +* +* Description: +* Search the network node table and return the record matching @addr. If an +* entry can not be found in the table return NULL. +* +*/ +static struct sel_netnode *sel_netnode_find (const void *addr,u16 family) +{ +u32 idx; +struct sel_netnode *node; + +switch (family) { +case PF_INET : + idx =sel_netnode_hashfn_ipv4 (*(__be32 *)addr); +break ; +case PF_INET6 : + idx =sel_netnode_hashfn_ipv6 (addr); +break ; +default : +BUG (); + } + +list_for_each_entry_rcu (node, &sel_netnode_hash[idx], list) +if (node->nsec.family == family) +switch (family) { +case PF_INET : +if (node->nsec.addr.ipv4 == *(__be32 *)addr) +return node; +break ; +case PF_INET6 : +if (ipv6_addr_cmp (&node->nsec.addr.ipv6, + addr) ==0 ) +return node; +break ; + } + +return NULL ; +} + +/** +* sel_netnode_insert - Insert a new node into the table +* @node: the new node record +* +* Description: +* Add a new node record to the network address hash table. Returns zero on +* success, negative values on failure. +* +*/ +static int sel_netnode_insert (struct sel_netnode *node) +{ +u32 idx; +u32 count =0 ; +struct sel_netnode *iter; + +switch (node->nsec.family) { +case PF_INET : + idx =sel_netnode_hashfn_ipv4 (node->nsec.addr.ipv4); +break ; +case PF_INET6 : + idx =sel_netnode_hashfn_ipv6 (&node->nsec.addr.ipv6); +break ; +default : +BUG (); + } +list_add_rcu (&node->list, &sel_netnode_hash[idx]); + +/* we need to impose a limit on the growth of the hash table so check +* this bucket to make sure it is within the specified bounds */ +list_for_each_entry (iter, &sel_netnode_hash[idx], list) +if (++count >SEL_NETNODE_HASH_BKT_LIMIT ) { +list_del_rcu (&iter->list); +call_rcu (&iter->rcu, sel_netnode_free); +break ; + } + +return 0 ; +} + +/** +* sel_netnode_destroy - Remove a node record from the table +* @node: the existing node record +* +* Description: +* Remove an existing node record from the network address table. +* +*/ +static void sel_netnode_destroy (struct sel_netnode *node) +{ +list_del_rcu (&node->list); +call_rcu (&node->rcu, sel_netnode_free); +} + +/** +* sel_netnode_sid_slow - Lookup the SID of a network address using the policy +* @addr: the IP address +* @family: the address family +* @sid: node SID +* +* Description: +* This function determines the SID of a network address by quering the +* security policy. The result is added to the network address table to +* speedup future queries. Returns zero on success, negative values on +* failure. +* +*/ +static int sel_netnode_sid_slow (void *addr,u16 family,u32 *sid) +{ +int ret; +struct sel_netnode *node; +struct sel_netnode *new =NULL ; + +spin_lock_bh (&sel_netnode_lock); + node =sel_netnode_find (addr, family); +if (node !=NULL ) { + *sid = node->nsec.sid; + ret =0 ; + goto out; + } + new =kzalloc (sizeof (*new),GFP_ATOMIC ); +if (new ==NULL ) { + ret = -ENOMEM ; + goto out; + } +switch (family) { +case PF_INET : + ret =security_node_sid (PF_INET , + addr,sizeof (struct in_addr ), + &new->nsec.sid); + new->nsec.addr.ipv4 = *(__be32 *)addr; +break ; +case PF_INET6 : + ret =security_node_sid (PF_INET6 , + addr,sizeof (struct in6_addr ), + &new->nsec.sid); +memcpy (&new->nsec.addr.ipv6, addr, +sizeof (new->nsec.addr.ipv6)); +break ; +default : +BUG (); + } +if (ret !=0 ) + goto out; + new->nsec.family = family; + ret =sel_netnode_insert (new); +if (ret !=0 ) + goto out; + *sid = new->nsec.sid; + +out: +spin_unlock_bh (&sel_netnode_lock); +if (ret !=0 ) +kfree (new); +return ret; +} + +/** +* sel_netnode_sid - Lookup the SID of a network address +* @addr: the IP address +* @family: the address family +* @sid: node SID +* +* Description: +* This function determines the SID of a network address using the fastest +* method possible. First the address table is queried, but if an entry +* can't be found then the policy is queried and the result is added to the +* table to speedup future queries. Returns zero on success, negative values +* on failure. +* +*/ +int sel_netnode_sid (void *addr,u16 family,u32 *sid) +{ +struct sel_netnode *node; + +rcu_read_lock (); + node =sel_netnode_find (addr, family); +if (node !=NULL ) { + *sid = node->nsec.sid; +rcu_read_unlock (); +return 0 ; + } +rcu_read_unlock (); + +return sel_netnode_sid_slow (addr, family, sid); +} + +/** +* sel_netnode_flush - Flush the entire network address table +* +* Description: +* Remove all entries from the network address table. +* +*/ +static void sel_netnode_flush (void ) +{ +u32 idx; +struct sel_netnode *node; + +spin_lock_bh (&sel_netnode_lock); +for (idx =0 ; idx <SEL_NETNODE_HASH_SIZE ; idx++) +list_for_each_entry (node, &sel_netnode_hash[idx], list) +sel_netnode_destroy (node); +spin_unlock_bh (&sel_netnode_lock); +} + +static int sel_netnode_avc_callback (u32 event,u32 ssid,u32 tsid, +u16 class,u32 perms,u32 *retained) +{ +if (event ==AVC_CALLBACK_RESET ) { +sel_netnode_flush (); +synchronize_net (); + } +return 0 ; +} + +static __init int sel_netnode_init (void ) +{ +int iter; +int ret; + +if (!selinux_enabled) +return 0 ; + +for (iter =0 ; iter <SEL_NETNODE_HASH_SIZE ; iter++) +INIT_LIST_HEAD (&sel_netnode_hash[iter]); + + ret =avc_add_callback (sel_netnode_avc_callback,AVC_CALLBACK_RESET , +SECSID_NULL ,SECSID_NULL ,SECCLASS_NULL ,0 ); +if (ret !=0 ) +panic ("avc_add_callback() failed, error %d\n" , ret); + +return ret; +} + +__initcall (sel_netnode_init); --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.
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.
Re: [RFC PATCH v8 05/18] LSM: Add secctx_to_secid() LSM hook
In reply to Stephen SmalleyQuoted 9 lines · --- Stephen Smalley
Quoted 3 lines · Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook. This patch also includes the SELinux implementation for this hook.Acked-by Stephen Smalley <[email protected]>This one can go up anytime, as we have other people wanting such a hook too.
I can't provide any justifications why it shouldn't go in, and there will no doubt be places where the continued use of secids will require it going forward.
Quoted 3 lines
Or alternatively we need to rationalize the entire selinux/exports interface with these hooks as used by the networking and audit subsystems, as that issue will be coming up anyway for other LSMs.
Yeah. Smack is taking the pragmatic path, assuming that secid and secctx will be around at least until pigs nest in trees. You left out the USB subsystems's use of secid's, which may be the least savory of all.
Quoted 3 lines
One thing to note is that some of these interfaces treat the context as an opaque byte array of a given length, while other ones depend on the context to be a NUL-terminated string (e.g. audit).
Smack and SELiunx always provide a NUL-terminated string. I would be in favor of defining a secctx as the textual representation of a security blob. If we don't, we'll need to define a third thing that is the text representation for audit before it's possible to convert audit from SELinux calls to LSM calls. Converting audit to use LSM calls will be mostly straitforward if the secctx can be assumed to be a string.
Casey Schaufler
[email protected]
--
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: [RFC PATCH v8 06/18] LSM: Add inet_sys_snd_skb() LSM hook
In reply to Stephen SmalleyQuoted 9 lines · Stephen Smalley
Quoted 6 lines · Paul Moore
Add an
inet_sys_snd_skb()LSM hook to allow the LSM to provide packet level access control for all outbound packets. Using the existingpostroute_lastnetfilter hook turns out to be problematic as it is can be invoked multiple times for a single packet, e.g. individual IPsec transforms, adding unwanted overhead and complicating the security policy.None of the netfilter hooks works for this purpose?
None that we have found, no. Although if you can prove me wrong I'd be very happy. The problem is that the existing netfilter hooks can get hit multiple times in the case of labeled IPsec which was decided to be a no-no.
Quoted 1 line
Obviously this one needs to get seen on netdev.
Yep. I just wanted to make sure we were all in agreement on what we wanted/needed before I tried to make our case to the netdev folks.
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 09/18] SELinux: Only store the network interface's ifindex
In reply to Stephen SmalleyQuoted 13 lines · Stephen Smalley
security/selinux/include/avc.h struct avc_audit_data { · line 83
Quoted 9 lines · Paul Moore
/* Initialize an AVC audit data structure. */
#defineAVC_AUDIT_DATA_INIT(_d,_t)\
- {memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type =
AVC_AUDIT_DATA_##_t; }
+ { memset((_d), 0, sizeof(structavc_audit_data)); \security/selinux/include/avc.h +3
-0+ (_d)->type = AVC_AUDIT_DATA_##_t; \ +if ((_d)->type ==AVC_AUDIT_DATA_NET ) \ + (_d)->u.net.netif =-1 ; }As a minor nit, at the same time you do this, turn this into a static inline function please.
Can do ... although when talking about this with some other people I'm not sure I need to use -1 as a sentinel value, zero should work. If that is the case I won't need to change this definition.
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 10/18] SELinux: Add a network node caching mechanism similar to the sel_netif_*() functions
In reply to Stephen SmalleyQuoted 9 lines · Stephen Smalley
Quoted 6 lines · Paul Moore
This patch adds a SELinux IP address/node SID caching mechanism similar to the sel_netif_*() functions. The node SID queries in the SELinux hooks files are also modified to take advantage of this new functionality. In addition, remove the address length information from the
sk_buffparsing routines as it is redundant since we already have the address family.This is very nice - we also need the same kind of cache for port SIDs.
Thanks. Any problem if we wait until 2.6.26 for a port SID cache? It shouldn't be any worse than it is now (the new code is not concerned with ports) and the current patchset is already large enough that it keeps me up at night thinking about all the places it could go wrong ...
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 18/18] SELinux: Add network ingress and egress control permission checks
In reply to Stephen SmalleyQuoted 46 lines · Stephen Smalley
Quoted 36 lines · Paul Moore
Quoted 8 lines · Paul Moore
This patch implements packet ingress/egress controls for SELinux which allow SELinux security policy to control the flow of all IPv4 and IPv6 packets into and out of the system. Currently SELinux does not have proper control over forwarded packets and this patch corrects this problem.
Special thanks to Venkat Yekkirala <[email protected]> whose earlier work on this topic eventually led to this patch.
I've been thinking about this over the weekend and realized a few things
...{snip}
Quoted 21 lines
security/selinux/hooks.c +21
-0+static int selinux_inet_sys_snd_skb (struct sk_buff *skb,int family) +{ +int err =0 ; + +if (!selinux_policycap_netpeer) +return 0 ; + +if (netlbl_enabled () ||selinux_xfrm_enabled ()) { +u32 if_sid; +u32 node_sid; +u32 peer_sid; +char *addrp; +struct avc_audit_data ad; + +AVC_AUDIT_DATA_INIT (&ad,NET ); + ad.u.net.netif = skb->iif; + ad.u.net.family = family; + err =selinux_parse_skb (skb, &ad, &addrp,0 ,NULL ); +if (err) +return err; +Quoted 8 lines
security/selinux/hooks.c static int selinux_socket_unix_may_send(struct socket *sock, · line 3656
Quoted 3 lines
security/selinux/hooks.c +3
-0+ err =selinux_skb_peerlbl_sid (skb, family, &peer_sid); +if (err) +return err;I realized I made a mistake here: we should check to see if the skb has a socket associated with it and if it does get the
peer_sidfrom there instead. If there is no socket to be found then do what we are already going above.
Quoted 1 line
In what case do you expect the two SIDs to diverge?
The case of CIPSO immediately springs to mind. If you query the packet directly you will get a SID similar to what you see on incoming packets:
the "netlabel_peer_t" type plus the CIPSO MLS sensitivity label. If you query the socket which originated the packet you'll get the original, native SELinux label/SID. In my mind using the socket's label is a shortcut to get the full/true/original/etc. label quickly.
There is most likely also a performance advantage in pulling the SID from the socket.
Quoted 3 lines
What if we later provide an API to allow a sender to send a datagram with a particular label rather than always requiring them to be the same as the sending socket?
Then we can transition from using a mix between socket and packet labels to just packet labels. I don't see any _significant_ barriers to that approach in the ingress/egress controls as proposed. If you do, let me know.
Quoted 28 lines
Quoted 28 lines
security/selinux/hooks.c static int selinux_socket_unix_may_send(struct socket *sock, · line 3670
Quoted 13 lines
security/selinux/hooks.c +13
-0+ err =sel_netif_sid (skb->iif, &if_sid); +if (err) +return err; + err =avc_has_perm (if_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad); +if (err) +return err; + + err =sel_netnode_sid (addrp, family, &node_sid); +if (err) +return err; + err =avc_has_perm (node_sid, peer_sid, +SECCLASS_PEER ,PEER__EGRESS , &ad);We should probably have different permissions for the interface and node cases. Take the example of an admin who is only interested in enforcing interface controls and not node controls. They would most likely write the following policy rule to nullify the node check ...
allow
unlabeled_tpeer_t:peer egress;... which would end up applying to both the interface and node checks because they use the same permission. I'm thinking we should split the permissions like this:
allow
netif_tpeer_t:peerif_egress;
allownetnode_tpeer_t: peernode_egress;
Quoted 6 lines
Quoted 1 line
... and do something similar for the ingress side. Thoughts?
That starts to sound a lot like using netif and node classes instead of the peer class.
allow peer_t netif_t:netif egress; allow peer_t netnode_t:node egress;
I see you noticed that too :)
I've been mulling this over and over in my head for some time and I'm not sure which is better. I'm leaning towards sticking with the peer object class just because it reinforces the decision to treat the packet as an object. Good or bad, that is how SELinux currently treats packets and I fear that using the packet's peer label as the subject here could get confusing.
Signature · 7 lines
paul moore linux security @ hp -- 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.
James Morris
maintainerRe: [RFC PATCH v8 10/18] SELinux: Add a network node caching mechanism similar to the sel_netif_*() functions
In reply to Paul MooreQuoted 9 lines · Paul Moore
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · Paul Moore
This patch adds a SELinux IP address/node SID caching mechanism similar to the sel_netif_*() functions. The node SID queries in the SELinux hooks files are also modified to take advantage of this new functionality. In addition, remove the address length information from the
sk_buffparsing routines as it is redundant since we already have the address family.
Quoted 3 lines
Quoted 1 line
This is very nice - we also need the same kind of cache for port SIDs.
Thanks. Any problem if we wait until 2.6.26 for a port SID cache?
Nope.
Signature · 7 lines
James Morris <[email protected]> -- 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.
James Morris
maintainerRe: [RFC PATCH v8 05/18] LSM: Add secctx_to_secid() LSM hook
In reply to Paul MooreQuoted 3 lines · Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook. This patch also includes the SELinux implementation for this hook.
Please sign off your patches (especially this one asap, so I can push it upstream).
Signature · 7 lines
James Morris <[email protected]> -- 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: [RFC PATCH v8 10/18] SELinux: Add a network node caching mechanism similar to the sel_netif_*() functions
In reply to Paul MooreQuoted 9 lines · Paul Moore
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · Paul Moore
This patch adds a SELinux IP address/node SID caching mechanism similar to the sel_netif_*() functions. The node SID queries in the SELinux hooks files are also modified to take advantage of this new functionality. In addition, remove the address length information from the
sk_buffparsing routines as it is redundant since we already have the address family.
Quoted 6 lines
Quoted 1 line
This is very nice - we also need the same kind of cache for port SIDs.
Thanks. Any problem if we wait until 2.6.26 for a port SID cache? It shouldn't be any worse than it is now (the new code is not concerned with ports) and the current patchset is already large enough that it keeps me up at night thinking about all the places it could go wrong ...
Yes, that's fine - just a note to file away for the future. We'll still want the cache eventually though since the name_bind and name_connect checks are based on the port SIDs and will remain even when the compat checks are obsoleted.
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.
Re: [RFC PATCH v8 10/18] SELinux: Add a network node caching mechanism similar to the sel_netif_*() functions
Quoted 17 lines · Stephen Smalley
Quoted 9 lines · Paul Moore
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · Paul Moore
This patch adds a SELinux IP address/node SID caching mechanism similar to the sel_netif_*() functions. The node SID queries in the SELinux hooks files are also modified to take advantage of this new functionality. In addition, remove the address length information from the
sk_buffparsing routines as it is redundant since we already have the address family.Quoted 6 lines
Quoted 1 line
This is very nice - we also need the same kind of cache for port SIDs.
Thanks. Any problem if we wait until 2.6.26 for a port SID cache? It shouldn't be any worse than it is now (the new code is not concerned with ports) and the current patchset is already large enough that it keeps me up at night thinking about all the places it could go wrong ...
Quoted 4 lines
Yes, that's fine - just a note to file away for the future. We'll still want the cache eventually though since the
name_bindandname_connectchecks are based on the port SIDs and will remain even when the compat checks are obsoleted.
All righty, since neither you or James are in a hurry for this I'll "file it away" for 2.6.26.
Thanks.
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 18/18] SELinux: Add network ingress and egress control permission checks
In reply to Stephen SmalleyQuoted 15 lines · Stephen Smalley
Quoted 14 lines · Paul Moore
We should probably have different permissions for the interface and node cases. Take the example of an admin who is only interested in enforcing interface controls and not node controls. They would most likely write the following policy rule to nullify the node check ...
allow
unlabeled_tpeer_t:peer egress;... which would end up applying to both the interface and node checks because they use the same permission. I'm thinking we should split the permissions like this:
allow
netif_tpeer_t:peerif_egress;
allownetnode_tpeer_t: peernode_egress;
Quoted 6 lines
Quoted 1 line
... and do something similar for the ingress side. Thoughts?
That starts to sound a lot like using netif and node classes instead of the peer class.
allow peer_t netif_t:netif egress; allow peer_t netnode_t:node egress;
Thinking about this some more ... egress/ingress make sense from an interface point of view but they sound out of place from a node point of view. After all, you are not "egressing" to a node, to are "sending to" a node. The same thing applies in the opposite direction, you don't "ingress" from a node, you "receive from" a node. With that in mind I'm thinking of going with the following:
allow netif_t peer_t:peer { ingress egress }; allow netnode_t peer_t:peer { recv_from send_to };
Thoughts? Should I just forget all this and use the peer label as a subject label?
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 05/18] LSM: Add secctx_to_secid() LSM hook
In reply to James MorrisQuoted 7 lines · James Morris
Quoted 3 lines · Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook. This patch also includes the SELinux implementation for this hook.Please sign off your patches (especially this one asap, so I can push it upstream).
The lack of a sign-off line is actually intentional at this point as I wanted to make sure they didn't go anywhere before they were ready. For instance, I've got the changes that were pointed out yesterday on-list as well as a handful of IPv6 changes from some IPv6 folks here at HP.
Most of the new peer object class code paths haven't even been tested yet. I realize we can still get fixes/corrections in after -rc1 but I'd like to try and minimize that if I can.
I've been operating under the assumption that I've most likely got until the end of next week before I need to post "final-ish" version of the patches, complete with a signed-off line. If that isn't the case and you need these bits sooner (or now) please let me know.
Signature · 7 lines
paul moore linux security @ hp -- 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: [RFC PATCH v8 18/18] SELinux: Add network ingress and egress control permission checks
In reply to Paul MooreQuoted 30 lines · Paul Moore
Quoted 15 lines · Stephen Smalley
Quoted 14 lines · Paul Moore
We should probably have different permissions for the interface and node cases. Take the example of an admin who is only interested in enforcing interface controls and not node controls. They would most likely write the following policy rule to nullify the node check ...
allow
unlabeled_tpeer_t:peer egress;... which would end up applying to both the interface and node checks because they use the same permission. I'm thinking we should split the permissions like this:
allow
netif_tpeer_t:peerif_egress;
allownetnode_tpeer_t: peernode_egress;Quoted 6 lines
Quoted 1 line
... and do something similar for the ingress side. Thoughts?
That starts to sound a lot like using netif and node classes instead of the peer class.
allow peer_t netif_t:netif egress; allow peer_t netnode_t:node egress;Thinking about this some more ... egress/ingress make sense from an interface point of view but they sound out of place from a node point of view. After all, you are not "egressing" to a node, to are "sending to" a node. The same thing applies in the opposite direction, you don't "ingress" from a node, you "receive from" a node. With that in mind I'm thinking of going with the following:
Quoted 2 lines
allow
netif_tpeer_t:peer { ingress egress }; allownetnode_tpeer_t:peer {recv_fromsend_to};
nit: recvfrom and sendto don't really require an underscore to be readable, and we've already set a precedent for them in the socket and association classes.
Quoted 2 lines
Thoughts? Should I just forget all this and use the peer label as a subject label?
I'm not certain what we gain by using the peer as the object and class in these checks, and it seems to make their meaning less clear. It should be noted that we already use process labels as both subjects (when the actor) and objects (when the target/recipient of an action, as in signal delivery or IPC), and that process labels "flow" to sockets they create and socket labels "flow" to packets they send, and socket labels likewise serve dual roles as subjects (Can this socket send/recv this packet?) and objects (Can this process send/recv on this socket?).
In the case of locally generated or destined traffic, we always have a local socket that we can use as the subject of the check, which I think is why we end up not using packet/peer as the subject generally - we essentially have two subjects to choose from, and we favor the local one. But in the forwarded case, the packet/peer is the only subject/actor in view really.
OTOH, I'm not sure your original concern about unlabeled_t is well-founded now that I think about it; the netif and node type space is disjoint and they default to discrete initial SIDs and types (netif_t, node_t), not to unlabeled_t, right? So the types themselves encode the class there.
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.
Re: [RFC PATCH v8 18/18] SELinux: Add network ingress and egress control permission checks
Quoted 13 lines · Stephen Smalley
Quoted 2 lines · Paul Moore
Thoughts? Should I just forget all this and use the peer label as a subject label?
I'm not certain what we gain by using the peer as the object and class in these checks, and it seems to make their meaning less clear. It should be noted that we already use process labels as both subjects (when the actor) and objects (when the target/recipient of an action, as in signal delivery or IPC), and that process labels "flow" to sockets they create and socket labels "flow" to packets they send, and socket labels likewise serve dual roles as subjects (Can this socket send/recv this packet?) and objects (Can this process send/recv on this socket?).
Quoted 6 lines
In the case of locally generated or destined traffic, we always have a local socket that we can use as the subject of the check, which I think is why we end up not using packet/peer as the subject generally - we essentially have two subjects to choose from, and we favor the local one. But in the forwarded case, the packet/peer is the only subject/actor in view really.
Yep, I think you are right and I'm just slow to realize it. As pointed out earlier in the discussion, the awkwardness of using the packet's peer label as an object should have clued me into the fact that this was a bad idea.
So, my last question is what permissions do we want to use for the netif/node object classes?
allow peer_t netif_t:netif { egress ingress }; allow peer_t netnode_t:node { sendto/send recvfrom/recv };
What I'd like to avoid if possible is the protocol specific permissions we currently have for the netif and node object classes; it requires extra work in the kernel, it doesn't work at all for the forwarding case, and I have my doubts about the usefulness of the distinction. I think the ingress/egress permissions still make sense when applied to the netif object class but it's a bit of a stretch when applied to the node object class. I personally like the sendto/recvfrom permissions but if that is too much of a violation from existing precedence I imagine send/recv would work.
Thoughts?
Signature · 7 lines
paul moore linux security @ hp -- 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.