Labeled networking patches
Subsystems (6)
v6 cover Labeled networking patches
This is an update to the patcheset sent earlier this week and the first time these patches have been sent to the LSM list. The most notable change between this patchset and the "v5" patches is the addition of the fallback/static label patches that were discussed on the SELinux list a few months ago. In addition to just porting the old fallback/static patches I've added the concept of a "default" interface as well as some intelligence in the SELinux layer to allow the NetLabel provided fallback label to play nicely with XFRM labels when both are present on a connection. This should help address issues found in the earlier versions of the fallback/static label patches. This patchset does not include Venkat's flow control patches, but Venkat has promised that they will be ready very soon; when they are I will merge them into this patchset. On a similar note, the new "peer" SELinux object class in this patchset isn't usable with currently released SELinux policies so you'll still be using the separate, labeling protocol specific, access checks.
I have to caution against using these patches for anything critical as they are still a "work in progress" and have only received minimal testing. However, I know there are a few of you who are very interested in this functionality and have offered to help with the testing so I'm posting the patches in this early state so we can get a jump shaking the bugs out. For those of you who are playing with these patches, there are a few things worth noting:
* You can do a pull down a complete git tree with these changes here:
-> git://git.infradead.org/users/pcmoore/lblnet-2.6_testing
* You should probably also apply this patch to fix an unrelated panic:
-> http://git.kernel.org/?p=linux/kernel/git/jmorris/selinux-2.6.git;a=commitdiff;h=6d2b685564ba417f4c6d80c3661f0dfee13fff85
* You'll need the latest SVN (rev 49 or higher) of the static_label branch of netlabel_tools to make use of the new fallback/static label features:
-> http://netlabel.svn.sourceforge.net/viewvc/netlabel/netlabel_tools
To configure the new fallback/static labels you use the following netlabelctl commands:
* Add a label
"netlabelctl unlbl add default|interface:<DEV> address:<ADDR>[/<MASK>] \
label:<LABEL>"
DEV = interface
ADDR = IP address
MASK = size of address mask
LABEL = full SELinux context
Examples:
# netlabelctl unlbl add default address:10.0.0.0/8 \
label:system_u:object_r:unlabeled_t:s0
# netlabelctl unlbl add interface:eth0 address:192.168.0.1 \
label:system_u:object_r:unlabeled_t:s0
# netlabelctl unlbl add interface:lo address:::1 \
label:system_u:object_r:unlabeled_t:s0 * Remove a label
"netlabelctl unlbl del default|interface:<DEV> address:<ADDR>[/<MASK>]"
DEV = interface
ADDR = IP address
MASK = size of address mask
Examples:
# netlabelctl unlbl del default address:10.0.0.0/8 # netlabelctl unlbl del interface:eth0 address:192.168.0.1 # netlabelctl unlbl del interface:lo address:::1
* Show labels
"netlabelctl -p unlbl list"
Examples:
# netlabelctl unlbl list
# netlabelctl -p unlbl list
If you have any questions/problems/comments feel free to either drop me mail privately or post something to the list.
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.
RFC PATCH v6 1/13 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 v6 2/13 NetLabel: cleanup the LSM domain hash functions
In reply to Paul MooreThe NetLabel/LSM domain hash table search function used a 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 v6 3/13 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 v6 4/13 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
@@ -563,7 +563,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 ; }
@@ -583,7 +583,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; }
@@ -606,8 +606,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;
@@ -634,7 +634,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 v6 5/13 SELinux: 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 a 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.
Re: [RFC PATCH v6 05/13] SELinux: add secctx_to_secid() LSM hook
Quoted 2 lines · --- Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook.
I'll bite. Where does this get used?
There are already places in the networking and audit code where a secid is gotten and saved for the sole purpose of getting a secctx at some later time. My favorite example:
Quoted 5 lines
static void
ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb){ char *secdata; u32 seclen, secid; int err;
In the Smack case what's in skb is the secctx.
Quoted 3 lines
err = security_socket_getpeersec_dgram(NULL, skb, &secid);
if (err)
return;Smack pulls the secctx off the packet and finds a secid for it.
Quoted 3 lines
err = security_secid_to_secctx(secid, &secdata, &seclen);
if (err)
return;Just so that it can turn around and look up the secctx it had in the first place.
Quoted 2 lines
put_cmsg(msg, SOL_IP, SCM_SECURITY, seclen, secdata);
security_release_secctx(secdata, seclen);Fortunatly, this is no-op.
Quoted 1 line
}
I expect that the purpose of the proposed secctx_to_secid() is to make it easier to implement more of these cases, where the only reason to do the conversion is to have something to convert back later. With SELinux as the only consumer of the LSM, and with the SELinux secid mindset I suppose this could make sense. It would also be perfectly reasonable if there was anything to do with a secid except convert it to a secctx, but there isn't.
There. I got the righteous indignation off my chest. I say to go ahead with adding this to the LSM because I need it to for dealing with the aformentioned audit code, which I have looked into fixing to use secctx instead of secid, and determined that there are a couple cases where you end up with the secid in any case.
In Linux 2.7 I propose that we fix these problems. Not today.
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 v6 05/13] SELinux: add secctx_to_secid() LSM hook
Quoted 5 lines · Casey Schaufler
Quoted 2 lines · --- Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook.I'll bite. Where does this get used?
Patch 12/13, functions netlbl_unlabel_staticadd() and netlbl_unlabel_staticadddef(). It is used to convert a user supplied label into a token which is later passed to the LSM; in the SELinux case it is used directly in an avc_has_perm() call.
Go ahead and check, I'll wait ... just please don't bring up the whole getpeercon() issue (essentially the example you chose, although you picked the connectionless version) again. Worrying about something that typically happens only once (if at all) per-connection is not something I want to worry about optimizing if it causes the per-packet case to become more tedious.
Quoted 2 lines
There. I got the righteous indignation off my chest. I say to go ahead with adding this to the LSM ... {snip}
Sigh. I agree, the whole tokenized label concept is conceptually very annoying and I'll also agree that it can be frustrating for certain implementations. However, the world we live in (the Linux kernel) makes use of these tokenized labels (secid, SID, etc) because it's all the original LSM folks could get in some places. The fact that this works fine with SELinux (actually works better than fine in some cases) is a happy coincidence and probably the reason things haven't changed much.
I _really_ don't want to get into the "one true security model" debate, but the fact remains that as long as SELinux is the only LSM implementation in the mainline kernel there is no reason to change this. If/when SMACK (this is really the immediate source of the "righteous indignation" after all, right?) is merged then it will probably make sense to go revisit some of those earlier decisions regarding these tokenized labels. For me personally, right now I'm just concerned about making sure the labeled networking bits work as well as we can make them work; with SELinux that means using a secid/SID to speed up the per-packet access checks. For SMACK, this will probably mean passing the actual string label. You and I have already talked about this so _you_know_ there is a SMACK friendly solution to the fallback/static label functionality; I just can't justify adding code that serves no purpose in the context (haha!) of the current kernel sources.
You know all this Casey, so I have no idea where all of these comments are coming from - bad day at work? Somebody run over your dog? Well, go home, have a beer and forget about it for right now. Get SMACK merged, or any other LSM which highlights the same problem, and we can put that "righteous indignation" to good use; right now, it's just plan tiresome.
Quoted 1 line
In Linux 2.7 I propose that we fix these problems. Not today.
Un huh ... in the meantime I'm gonna work with what I have :)
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 v6 05/13] SELinux: add secctx_to_secid() LSM hook
Quoted 54 lines · --- Paul Moore
Quoted 5 lines · Casey Schaufler
Quoted 2 lines · --- Paul Moore
Add a
secctx_to_secid()LSM hook to go along with the existingsecid_to_secctx()LSM hook.I'll bite. Where does this get used?
Patch 12/13, functions
netlbl_unlabel_staticadd()andnetlbl_unlabel_staticadddef(). It is used to convert a user supplied label into a token which is later passed to the LSM; in the SELinux case it is useddirectly in an
avc_has_perm()call.Go ahead and check, I'll wait ... just please don't bring up the whole
getpeercon()issue (essentially the example you chose, although you picked the connectionless version) again. Worrying about something that typically happens only once (if at all) per-connection is not something I want to worryabout optimizing if it causes the per-packet case to become more tedious.
Quoted 2 lines
There. I got the righteous indignation off my chest. I say to go ahead with adding this to the LSM ... {snip}
Sigh. I agree, the whole tokenized label concept is conceptually very annoying and I'll also agree that it can be frustrating for certain implementations. However, the world we live in (the Linux kernel) makes use of these tokenized labels (secid, SID, etc) because it's all the original LSM
folks could get in some places. The fact that this works fine with SELinux (actually works better than fine in some cases) is a happy coincidence and probably the reason things haven't changed much.
I _really_ don't want to get into the "one true security model" debate, but the fact remains that as long as SELinux is the only LSM implementation in the mainline kernel there is no reason to change this. If/when SMACK (this is really the immediate source of the "righteous indignation" after all, right?) is merged then it will probably make sense to go revisit some of those earlier decisions regarding these tokenized labels. For me personally,
right now I'm just concerned about making sure the labeled networking bits work as well as we can make them work; with SELinux that means using a secid/SID to speed up the per-packet access checks. For SMACK, this will probably mean passing the actual string label. You and I have already talked
about this so _you_know_ there is a SMACK friendly solution to the fallback/static label functionality; I just can't justify adding code that serves no purpose in the context (haha!) of the current kernel sources.
You know all this Casey, so I have no idea where all of these comments are coming from - bad day at work? Somebody run over your dog? Well, go home, have a beer and forget about it for right now. Get SMACK merged, or any other LSM which highlights the same problem, and we can put that "righteous indignation" to good use; right now, it's just plan tiresome.
Quoted 3 lines
Quoted 1 line
In Linux 2.7 I propose that we fix these problems. Not today.
Un huh ... in the meantime I'm gonna work with what I have :)
Sounds like a plan with merit. I would not expect a change to existing code without a good^H^H^H^Hbetter alternative proposed. As I don't have such in hand at the moment, I agree that the current scheme is pragmatic. And yes, I'm still working on getting Smack in.
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.
RFC PATCH v6 6/13 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 v6 7/13 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;
@@ -92,6 +104,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 ; }
@@ -1532,6 +1544,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 v6 8/13 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__FLOW_IN, "flow_in") + S_(SECCLASS_PEER, PEER__FLOW_OUT, "flow_out") +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__FLOW_IN 0x00000001UL +#define PEER__FLOW_OUT 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.
James Morris
maintainerRe: [RFC PATCH v6 08/13] SELinux: Add new peer permissions to the Flask definitions
Quoted 1 line · Paul Moore
Add additional Flask definitions to support the new "peer" object class.
Should this be dependent on dynamic class/permission support?
Or, will these checks only be invoked if labled networking is configured?
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 v6 08/13] SELinux: Add new peer permissions to the Flask definitions
Quoted 4 lines · James Morris
Quoted 1 line · Paul Moore
Add additional Flask definitions to support the new "peer" object class.
Should this be dependent on dynamic class/permission support?
I think it's okay to _define_ the Flask definitions regardless of what the policy supports as older policies should simply ignore these definitions.
Quoted 1 line
Or, will these checks only be invoked if labled networking is configured?
Bingo! Look at patch 7/13, specifically the 'selinux_policycap_netpeer' variable and then at patch 9/13 where the new access checks are made conditional on this variable. The whole mess needs more testing and verification, but "in theory" it shouldn't cause any breakage with older policies ... if someone does notice something broken please scream loudly.
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.
RFC PATCH v6 9/13 SELinux: Better integration between peer labeling subsystems
In reply to Paul MooreRename the existing selinux_skb_extlbl_sid() function to selinux_skb_peerlbl_sid() and modify it's behavior such that it now reconciles multiple peer/external labels and if reconciliation is not possible it returns an error to the caller.
---
security/selinux/hooks.c | 94 ++++++++++++++++++++++------------- security/selinux/include/netlabel.h | 3 + security/selinux/include/security.h | 4 + security/selinux/netlabel.c | 3 + security/selinux/ss/services.c | 85 ++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 35 deletions(-)
security/selinux/hooks.c +59 -35
@@ -3190,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 */
@@ -3674,17 +3677,32 @@ out:return err; } +static int selinux_sock_recv_peer_compat (struct sk_security_struct *sksec, +struct sk_buff *skb, +u16 family, +struct avc_audit_data ad) +{ +int err; + + err =selinux_netlbl_sock_rcv_skb (sksec, skb, family, &ad); +if (err) +return err; + +return selinux_xfrm_sock_rcv_skb (sksec->sid, skb, &ad); +} +static int selinux_socket_sock_rcv_skb (struct sock *sk,struct sk_buff *skb) { -u16 family; +u16 family = sk->sk_family;char *addrp; -int len, err =0 ; +int len; +int err;struct avc_audit_data ad;struct sk_security_struct *sksec = sk->sk_security; +int peer_sid; - 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,10 +3711,14 @@ 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->dev ? skb->dev->name :"[unknown]" ; ad.u.net.family = family; - err =selinux_parse_skb (skb, &ad, &addrp, &len,1 ,NULL );if (err) - goto out; +return err; + +/* Between selinux_compat_net and selinux_policycap_netpeer this is +* starting to get a bit messy - we need to setup a timetable for +* deprecating some of this old/obsolete functionality so we can +* reclaim some level of sanity in this function. */ if (selinux_compat_net) err = selinux_sock_rcv_skb_compat(sk, skb, &ad, family,
@@ -3705,15 +3727,15 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__RECV , &ad);if (err) - goto out; +return err; - err =selinux_netlbl_sock_rcv_skb (sksec, skb, family, &ad); +if (!selinux_policycap_netpeer) +return selinux_sock_recv_peer_compat (sksec, skb, family, ad); + err =selinux_skb_peerlbl_sid (skb, family, &peer_sid);if (err) - goto out; - - err =selinux_xfrm_sock_rcv_skb (sksec->sid, skb, &ad); -out: -return err; +return err; +return avc_has_perm (sksec->sid, peer_sid, +SECCLASS_PEER ,PEER__RECV , &ad); } static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *optval,
@@ -3776,7 +3798,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 ;
@@ -3837,7 +3859,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 ;
@@ -3875,7 +3899,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/security.h +4 -0
@@ -100,6 +100,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 -0
@@ -143,6 +143,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 +155,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 +176,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;
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.
James Morris
maintainerRe: [RFC PATCH v6 09/13] SELinux: Better integration between peer labeling subsystems
security/selinux/hooks.c static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) · line 3721
Quoted 4 lines · Paul Moore
security/selinux/hooks.c +4
-0+/* Between selinux_compat_net and selinux_policycap_netpeer this is +* starting to get a bit messy - we need to setup a timetable for +* deprecating some of this old/obsolete functionality so we can +* reclaim some level of sanity in this function. */
I don't think we can do anything which could potentially break userspace now.
So, this one really needs to be right :-)
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 v6 09/13] SELinux: Better integration between peer labeling subsystems
Quoted 8 lines · James Morris
security/selinux/hooks.c static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) · line 3721
Quoted 4 lines · Paul Moore
security/selinux/hooks.c +4
-0+/* Between selinux_compat_net and selinux_policycap_netpeer this is +* starting to get a bit messy - we need to setup a timetable for +* deprecating some of this old/obsolete functionality so we can +* reclaim some level of sanity in this function. */ I don't think we can do anything which could potentially break userspace now.
Yeah, I've already had one very long day as a result of that, I'm not in any hurry to do that again :)
On a serious note, I thought we could remove specific features after a certain period of time, i.e. Documentation/feature-removal-schedule.txt? My thought is that eventually we can at least remove compat_net, or is that too drastic?
Quoted 1 line
So, this one really needs to be right :-)
Yeah, this is the one thing that still worries me and one of the main reasons I keep pushing RFC patches so often.
Personally, I'm still a little frustrated at how ugly that function looks. I'm debating putting a check near the top to see if any of
the "compatibility" flags are set, meaning an older policy, and if it is just handing off control to a compat function which handles all the ugliness. There might be some duplication of code but the sock_rcv_skb() function would be _much_ cleaner and faster in the "current policy" case.
Actually, I think I just talked myself into it ...
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.
RFC PATCH v6 10/13 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 | 24 ++++++++++++++++++++- security/selinux/include/xfrm.h | 17 +++++++++++++++ security/selinux/xfrm.c | 18 ++++++++++++++-- 6 files changed, 123 insertions(+), 14 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 +23 -1
@@ -50,8 +50,10 @@#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/netlabel.h> #include <asm/uaccess.h> #include <asm/ioctls.h> +#include <asm/atomic.h> #include <linux/bitops.h> #include <linux/interrupt.h> #include <linux/netdevice.h> /* for network interface checks */
@@ -87,6 +89,9 @@ extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);extern int selinux_compat_net;extern struct security_operations *security_ops; +/* SECMARK reference count */ +atomic_t selinux_secmark_refcount =ATOMIC_INIT (0 ); +#ifdef CONFIG_SECURITY_SELINUX_DEVELOP int selinux_enforcing =0 ;
@@ -153,6 +158,21 @@ getsecurity_exit:return len; } +/** +* selinux_secmark_enabled - Check to see if SECMARK is currently enabled +* +* Description: +* This function checks the SECMARK reference counter to see if any SECMARK +* targets are currently configured, if the reference counter is greater than +* zero SECMARK is considered to be enabled. Returns true (1) if SECMARK is +* enabled, false (0) if SECMARK is disabled. +* +*/ +static int selinux_secmark_enabled (void ) +{ +return (atomic_read (&selinux_secmark_refcount) >0 ); +} +/* Allocate and free functions for each kind of security blob. */ static int task_alloc_security (struct task_struct *task)
@@ -3723,7 +3743,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)if (selinux_compat_net) err =selinux_sock_rcv_skb_compat (sk, skb, &ad, family, addrp, len); -else +else if (!selinux_policycap_netpeer ||selinux_secmark_enabled ()) err =avc_has_perm (sksec->sid, skb->secmark,SECCLASS_PACKET ,PACKET__RECV , &ad);if (err)
@@ -3731,6 +3751,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)if (!selinux_policycap_netpeer)return selinux_sock_recv_peer_compat (sksec, skb, family, ad); +if (!netlbl_enabled () && !selinux_xfrm_enabled ()) +return 0 ; err =selinux_skb_peerlbl_sid (skb, family, &peer_sid);if (err)return err;
security/selinux/include/xfrm.h +17 -0
@@ -7,6 +7,23 @@#ifndef _SELINUX_XFRM_H_#define _SELINUX_XFRM_H_ +extern atomic_t selinux_xfrm_refcount; + +/** +* selinux_xfrm_enabled - Determine if labeled XFRM is enabled +* +* Description: +* This function checks to see if there are any labeled SAs or entries in the +* SPD. If there are then labeled XFRM is currently enabled, if not it is +* currently disabled. Returns true (1) if labeled XFRM is enabled, false (0) +* if labeled XFRM is disabled. +* +*/ +static inline int selinux_xfrm_enabled (void ) +{ +return (atomic_read (&selinux_xfrm_refcount) >0 ); +} +int selinux_xfrm_policy_alloc (struct xfrm_policy *xp,struct xfrm_user_sec_ctx *sec_ctx);int selinux_xfrm_policy_clone (struct xfrm_policy *old,struct xfrm_policy *new);
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
@@ -292,6 +295,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; }
@@ -339,10 +345,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; }
@@ -359,6 +368,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; }
@@ -381,10 +392,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 v6 11/13 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
@@ -125,7 +125,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,
@@ -133,7 +132,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 v6 12/13 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 | 1373 +++++++++++++++++++++++++++++++++++++ net/netlabel/netlabel_unlabeled.h | 145 ++++ 4 files changed, 1522 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 +1366 -7
1,457 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 v6 13/13 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 | 127 +++++++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 22 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 +105 -22
293 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.