xen/xsm/flask: Update to policy.24
PATCH 1/1 xen/xsm/flask: Update to policy.24
Update Xen Flask module to policy.24.
This is a back-port of the latest SELinux code to Xen, adjusted for Xen coding style and interfaces. Unneeded functionality such as most object context config data, handle_unknown, MLS field defaulting, etc has been omitted.
---
tools/flask/policy/Makefile | 2 xen/xsm/flask/avc.c | 234 ++++++++------- xen/xsm/flask/flask_op.c | 2 xen/xsm/flask/include/avc_ss.h | 23 + xen/xsm/flask/include/security.h | 14 xen/xsm/flask/ss/avtab.c | 142 +++++++-- xen/xsm/flask/ss/avtab.h | 20 - xen/xsm/flask/ss/conditional.c | 23 - xen/xsm/flask/ss/conditional.h | 2 xen/xsm/flask/ss/context.h | 33 +- xen/xsm/flask/ss/ebitmap.c | 209 +++++++------- xen/xsm/flask/ss/ebitmap.h | 94 ++++-- xen/xsm/flask/ss/hashtab.c | 10 xen/xsm/flask/ss/hashtab.h | 12 xen/xsm/flask/ss/mls.c | 321 ++++++++------------- xen/xsm/flask/ss/mls.h | 6 xen/xsm/flask/ss/policydb.c | 411 +++++++++++++++++++++++---- xen/xsm/flask/ss/policydb.h | 29 + xen/xsm/flask/ss/services.c | 574 +++++++++++++++++++++++++++------------ xen/xsm/flask/ss/sidtab.c | 2 xen/xsm/flask/ss/symtab.c | 8 21 files changed, 1438 insertions(+), 733 deletions(-)
tools/flask/policy/Makefile +1 -1
@@ -20,7 +20,7 @@ # By default, checkpolicy will create the highest # version policy it supports. Setting this will # override the version. -OUTPUT_POLICY = 20 +#OUTPUT_POLICY = 20 # Policy Type # strict, targeted,
xen/xsm/flask/avc.c +132 -102
460 lines not on this page · raw message
xen/xsm/flask/flask_op.c +1 -1
@@ -346,7 +346,7 @@memset (buf,0 , size); length =snprintf (buf, size,"%x %x %x %x %u" , - avd.allowed, avd.decided, + avd.allowed,0xffffffff , avd.auditallow, avd.auditdeny, avd.seqno);
xen/xsm/flask/include/avc_ss.h +23 -0
@@ -10,5 +10,28 @@int avc_ss_reset (u32 seqno); +struct av_perm_to_string { +u16 tclass; +u32 value; +const char *name; +}; + +struct av_inherit { +const char **common_pts; +u32 common_base; +u16 tclass; +}; + +struct selinux_class_perm { +const struct av_perm_to_string *av_perm_to_string; +u32 av_pts_len; +u32 cts_len; +const char **class_to_string; +const struct av_inherit *av_inherit; +u32 av_inherit_len; +}; + +extern const struct selinux_class_perm selinux_class_perm; +#endif /* _FLASK_AVC_SS_H_ */
xen/xsm/flask/include/security.h +9 -5
@@ -26,10 +26,14 @@#define POLICYDB_VERSION_VALIDATETRANS 19#define POLICYDB_VERSION_MLS 19#define POLICYDB_VERSION_AVTAB 20 +#define POLICYDB_VERSION_RANGETRANS 21 +#define POLICYDB_VERSION_POLCAP 22 +#define POLICYDB_VERSION_PERMISSIVE 23 +#define POLICYDB_VERSION_BOUNDARY 24/* Range of policy versions we understand*/ #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE -#define POLICYDB_VERSION_MAX POLICYDB_VERSION_AVTAB +#define POLICYDB_VERSION_MAX POLICYDB_VERSION_BOUNDARY#ifdef FLASK_BOOTPARAM extern int flask_enabled;
@@ -43,12 +47,15 @@struct av_decision {u32 allowed; -u32 decided;u32 auditallow;u32 auditdeny;u32 seqno; +u32 flags; }; +/* definitions of av_decision.flags */ +#define AVD_FLAGS_PERMISSIVE 0x0001 +int security_compute_av (u32 ssid,u32 tsid,u16 tclass,u32 requested,struct av_decision *avd);
@@ -62,9 +69,6 @@int security_context_to_sid (char *scontext,u32 scontext_len,u32 *out_sid); -int security_context_to_sid_default (char *scontext,u32 scontext_len, -u32 *out_sid,u32 def_sid); -int security_get_user_sids (u32 callsid,char *username,u32 **sids,u32 *nel);int security_pirq_sid (int pirq,u32 *out_sid);
xen/xsm/flask/ss/avtab.c +104 -38
329 lines not on this page · raw message
xen/xsm/flask/ss/avtab.h +13 -7
@@ -16,6 +16,9 @@* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. +* +* Updated: Yuichi Nakamura <[email protected]> +* Tuned number of hash slots for avtab to reduce memory usage */ /* Ported to Xen 3.0, George Coker, <[email protected]> */
@@ -53,19 +56,23 @@struct avtab {struct avtab_node **htable;u32 nel;/* number of elements */ +u32 nslot;/* number of hash slots */ +u16 mask;/* mask to compute hash func */ };int avtab_init (struct avtab *); +int avtab_alloc (struct avtab *,u32 );struct avtab_datum *avtab_search (struct avtab *h,struct avtab_key *k);void avtab_destroy (struct avtab *h);void avtab_hash_eval (struct avtab *h,char *tag); -int avtab_read_item (void *fp,uint32_t vers,struct avtab *a, +struct policydb ; +int avtab_read_item (struct avtab *a,void *fp,struct policydb *pol,int (*insert)(struct avtab *a,struct avtab_key *k,struct avtab_datum *d,void *p),void *p); -int avtab_read (struct avtab *a,void *fp,u32 vers); +int avtab_read (struct avtab *a,void *fp,struct policydb *pol);struct avtab_node *avtab_insert_nonunique (struct avtab *h,struct avtab_key *key,struct avtab_datum *datum);
@@ -75,11 +82,10 @@struct avtab_node *avtab_search_node_next (struct avtab_node *node,int specified); -#define AVTAB_HASH_BITS 15 -#define AVTAB_HASH_BUCKETS (1 << AVTAB_HASH_BITS) -#define AVTAB_HASH_MASK (AVTAB_HASH_BUCKETS-1) - -#define AVTAB_SIZE AVTAB_HASH_BUCKETS +#define MAX_AVTAB_HASH_BITS 13 +#define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) +#define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1) +#define MAX_AVTAB_SIZE MAX_AVTAB_HASH_BUCKETS#endif /* _SS_AVTAB_H_ */
xen/xsm/flask/ss/conditional.c +13 -10
@@ -101,7 +101,7 @@ { node->cur_state = new_state;if ( new_state ==-1 ) -printk (KERN_ERR "security: expression result was undefined - disabling all rules.\n" ); +printk (KERN_ERR "Flask: expression result was undefined - disabling all rules.\n" );/* turn the rules on or off */ for ( cur = node->true_list; cur !=NULL ; cur = cur->next ) {
@@ -287,7 +287,7 @@ {if (avtab_search (&p->te_avtab, k) ) { -printk ("security: type rule already exists outside of a " +printk ("Flask: type rule already exists outside of a " "conditional." ); goto err; }
@@ -306,7 +306,7 @@ {if (avtab_search_node_next (node_ptr, k->specified) ) { -printk ("security: too many conflicting type rules." ); +printk ("Flask: too many conflicting type rules." ); goto err; } found =0 ;
@@ -320,7 +320,7 @@ }if ( !found ) { -printk ("security: conflicting type rules.\n" ); +printk ("Flask: conflicting type rules.\n" ); goto err; } }
@@ -329,7 +329,7 @@ {if (avtab_search (&p->te_cond_avtab, k) ) { -printk ("security: conflicting type rules when adding type rule " +printk ("Flask: conflicting type rules when adding type rule " "for true.\n" ); goto err; }
@@ -339,7 +339,7 @@ node_ptr =avtab_insert_nonunique (&p->te_cond_avtab, k, d);if ( !node_ptr ) { -printk ("security: could not insert rule." ); +printk ("Flask: could not insert rule." ); goto err; }
@@ -389,8 +389,7 @@ data.tail =NULL ;for ( i =0 ; i < len; i++ ) { - rc =avtab_read_item (fp, p->policyvers, &p->te_cond_avtab, cond_insertf, - &data); + rc =avtab_read_item (&p->te_cond_avtab, fp, p, cond_insertf, &data);if ( rc )return rc; }
@@ -403,13 +402,13 @@ {if ( expr->expr_type <=0 || expr->expr_type >COND_LAST ) { -printk ("security: conditional expressions uses unknown operator.\n" ); +printk ("Flask: conditional expressions uses unknown operator.\n" );return 0 ; }if ( expr->bool > p->p_bools.nprim ) { -printk ("security: conditional expressions uses unknown bool.\n" ); +printk ("Flask: conditional expressions uses unknown bool.\n" );return 0 ; }return 1 ;
@@ -489,6 +488,10 @@ len =le32_to_cpu (buf[0 ]); + rc =avtab_alloc (&(p->te_cond_avtab), p->te_avtab.nel); +if ( rc ) + goto err; +for ( i =0 ; i < len; i++ ) { node = xmalloc(struct cond_node);
xen/xsm/flask/ss/conditional.h +1 -1
@@ -28,7 +28,7 @@#define COND_XOR 5/* bool ^ bool */ #define COND_EQ 6/* bool == bool */ #define COND_NEQ 7/* bool != bool */ -#define COND_LAST 8 +#define COND_LAST COND_NEQ__u32 expr_type;__u32 bool;struct cond_expr *next;
xen/xsm/flask/ss/context.h +28 -5
@@ -42,17 +42,40 @@ {int rc; -if (!flask_mls_enabled) +if ( !flask_mls_enabled )return 0 ; dst->range.level[0 ].sens = src->range.level[0 ].sens; rc =ebitmap_cpy (&dst->range.level[0 ].cat, &src->range.level[0 ].cat); -if (rc) +if ( rc ) goto out; dst->range.level[1 ].sens = src->range.level[1 ].sens; rc =ebitmap_cpy (&dst->range.level[1 ].cat, &src->range.level[1 ].cat); -if (rc) +if ( rc ) +ebitmap_destroy (&dst->range.level[0 ].cat); +out: +return rc; +} + +/* +* Sets both levels in the MLS range of 'dst' to the low level of 'src'. +*/ +static inline int mls_context_cpy_low (struct context *dst,struct context *src) +{ +int rc; + +if ( !flask_mls_enabled ) +return 0 ; + + dst->range.level[0 ].sens = src->range.level[0 ].sens; + rc =ebitmap_cpy (&dst->range.level[0 ].cat, &src->range.level[0 ].cat); +if ( rc ) + goto out; + + dst->range.level[1 ].sens = src->range.level[0 ].sens; + rc =ebitmap_cpy (&dst->range.level[1 ].cat, &src->range.level[0 ].cat); +if ( rc )ebitmap_destroy (&dst->range.level[0 ].cat); out:return rc;
@@ -60,7 +83,7 @@static inline int mls_context_cmp (struct context *c1,struct context *c2) { -if (!flask_mls_enabled) +if ( !flask_mls_enabled )return 1 ; return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
@@ -71,7 +94,7 @@static inline void mls_context_destroy (struct context *c) { -if (!flask_mls_enabled) +if ( !flask_mls_enabled )return ;ebitmap_destroy (&c->range.level[0 ].cat);
xen/xsm/flask/ss/ebitmap.c +109 -100
321 lines not on this page · raw message
xen/xsm/flask/ss/ebitmap.h +72 -22
126 lines not on this page · raw message
xen/xsm/flask/ss/hashtab.c +6 -4
@@ -11,8 +11,10 @@#include <xen/errno.h> #include "hashtab.h" -struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h,void *key), -int (*keycmp)(struct hashtab *h,void *key1,void *key2),u32 size) +struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h, +const void *key), +int (*keycmp)(struct hashtab *h,const void *key1, +const void *key2),u32 size) {struct hashtab *p;u32 i;
@@ -26,7 +28,7 @@ p->nel =0 ; p->hash_value = hash_value; p->keycmp = keycmp; - p->htable = (void *)xmalloc_array(struct hashtab_node, size); + p->htable = xmalloc_array(struct hashtab_node *, size);if ( p->htable ==NULL ) {xfree (p);
@@ -80,7 +82,7 @@return 0 ; } -void *hashtab_search (struct hashtab *h,void *key) +void *hashtab_search (struct hashtab *h,const void *key) {u32 hvalue;struct hashtab_node *cur;
xen/xsm/flask/ss/hashtab.h +7 -5
@@ -22,9 +22,9 @@struct hashtab_node **htable;/* hash table */ u32 size;/* number of slots in hash table */ u32 nel;/* number of elements in hash table */ -u32 (*hash_value)(struct hashtab *h,void *key); +u32 (*hash_value)(struct hashtab *h,const void *key);/* hash function */ -int (*keycmp)(struct hashtab *h,void *key1,void *key2); +int (*keycmp)(struct hashtab *h,const void *key1,const void *key2);/* key comparison function */ };
@@ -39,8 +39,10 @@* Returns NULL if insufficent space is available or * the new hash table otherwise. */ -struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h,void *key), -int (*keycmp)(struct hashtab *h,void *key1,void *key2),u32 size); +struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h, +const void *key), +int (*keycmp)(struct hashtab *h,const void *key1, +const void *key2),u32 size);/* * Inserts the specified (key, datum) pair into the specified hash table.
@@ -58,7 +60,7 @@* Returns NULL if no entry has the specified key or * the datum of the entry otherwise. */ -void *hashtab_search (struct hashtab *h,void *k); +void *hashtab_search (struct hashtab *h,const void *k);/* * Destroys the specified hash table.
xen/xsm/flask/ss/mls.c +121 -200
453 lines not on this page · raw message
xen/xsm/flask/ss/mls.h +4 -2
@@ -8,7 +8,7 @@* * Support for enhanced MLS infrastructure. * -* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. +* Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. */ #ifndef _SS_MLS_H_
@@ -20,9 +20,11 @@int mls_compute_context_len (struct context *context);void mls_sid_to_context (struct context *context,char **scontext);int mls_context_isvalid (struct policydb *p,struct context *c); +int mls_range_isvalid (struct policydb *p,struct mls_range *r); +int mls_level_isvalid (struct policydb *p,struct mls_level *l);int mls_context_to_sid (char oldc,char **scontext,struct context *context, -struct sidtab *s,u32 def_sid); +struct sidtab *s);int mls_convert_context (struct policydb *oldp,struct policydb *newp,struct context *context);
xen/xsm/flask/ss/policydb.c +353 -58
749 lines not on this page · raw message
xen/xsm/flask/ss/policydb.h +26 -3
@@ -63,6 +63,7 @@/* Role attributes */ struct role_datum {u32 value;/* internal role value */ +u32 bounds;/* boundary of role */ struct ebitmap dominates;/* set of roles dominated by this role */ struct ebitmap types;/* set of authorized types for role */ };
@@ -83,12 +84,25 @@/* Type attributes */ struct type_datum {u32 value;/* internal type value */ +u32 bounds;/* boundary of type */ unsigned char primary;/* primary name? */ +unsigned char attribute;/* attribute ?*/ }; +/* +* type_datum properties +* available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY +*/ +#define TYPEDATUM_PROPERTY_PRIMARY 0x0001 +#define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002 + +/* limitation of boundary depth */ +#define POLICYDB_BOUNDS_MAXDEPTH 4 +/* User attributes */ struct user_datum {u32 value;/* internal user value */ +u32 bounds;/* bounds of user */ struct ebitmap roles;/* set of authorized roles for user */ struct mls_range range;/* MLS range (min - max) for user */ struct mls_level dfltlevel;/* default login MLS level for user */
@@ -108,9 +122,10 @@ };struct range_trans { -u32 dom;/* current process domain */ -u32 type;/* program executable type */ -struct mls_range range;/* new range */ +u32 source_type; +u32 target_type; +u32 target_class; +struct mls_range target_range;struct range_trans *next; };
@@ -191,6 +206,7 @@struct class_datum **class_val_to_struct;struct role_datum **role_val_to_struct;struct user_datum **user_val_to_struct; +struct type_datum **type_val_to_struct;/* type enforcement access vectors and transitions */ struct avtab te_avtab;
@@ -218,12 +234,19 @@/* type -> attribute reverse mapping */ struct ebitmap *type_attr_map; +struct ebitmap policycaps; + +struct ebitmap permissive_map; +unsigned int policyvers; };extern void policydb_destroy (struct policydb *p);extern int policydb_load_isids (struct policydb *p,struct sidtab *s);extern int policydb_context_isvalid (struct policydb *p,struct context *c); +extern int policydb_class_isvalid (struct policydb *p,unsigned int class); +extern int policydb_type_isvalid (struct policydb *p,unsigned int type); +extern int policydb_role_isvalid (struct policydb *p,unsigned int role);extern int policydb_read (struct policydb *p,void *fp);#define PERM_SYMTAB_SIZE 32
xen/xsm/flask/ss/services.c +410 -164
130 lines not on this page · raw message
xen/xsm/flask/ss/sidtab.c +1 -1
Lines of this file are not shown. View the raw message.
xen/xsm/flask/ss/symtab.c +4 -4
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 2 lines
Stephen Smalley National Security Agency
Part of the diff is not shown here. View the raw message.
Quoted 8 lines · Stephen Smalley
Update Xen Flask module to policy.24.
This is a back-port of the latest SELinux code to Xen, adjusted for Xen coding style and interfaces. Unneeded functionality such as most object context config data,handle_unknown, MLS field defaulting, etc has been omitted.Signed-off-by Stephen D. Smalley <[email protected]>Signed-off-by George S. Coker, II <[email protected]>
The patch didn't apply. Given that the affected source files have a thick layer of dust on them, it is probably because the patch got mangled somehow. Try re-sending as an attachment.
-- Keir
PATCH 1/1 xen/xsm/flask: Update to policy.24
# HG changeset patch
# User Stephen Smalley <[email protected]>
# Date 1250684892 14400
# Node ID 6c3ba8157bedfd3f1a15a21ebcfcecbd38584059
# Parent 8b0f1f37e145ad9680e1363290da8e4349a51a00
Update Xen Flask module to policy.24.
This is a back-port of the latest SELinux code to Xen, adjusted for Xen coding style and interfaces. Unneeded functionality such as most object context config data, handle_unknown, MLS field defaulting, etc has been omitted.
tools/flask/policy/Makefile +1 -1
@@ -20,7 +20,7 @@ # By default, checkpolicy will create the highest # version policy it supports. Setting this will # override the version. -OUTPUT_POLICY = 20 +#OUTPUT_POLICY = 20 # Policy Type # strict, targeted,
xen/xsm/flask/avc.c +132 -102
460 lines not on this page · raw message
xen/xsm/flask/flask_op.c +1 -1
@@ -346,7 +346,7 @@memset (buf,0 , size); length =snprintf (buf, size,"%x %x %x %x %u" , - avd.allowed, avd.decided, + avd.allowed,0xffffffff , avd.auditallow, avd.auditdeny, avd.seqno);
xen/xsm/flask/include/avc_ss.h +23 -0
@@ -10,5 +10,28 @@int avc_ss_reset (u32 seqno); +struct av_perm_to_string { +u16 tclass; +u32 value; +const char *name; +}; + +struct av_inherit { +const char **common_pts; +u32 common_base; +u16 tclass; +}; + +struct selinux_class_perm { +const struct av_perm_to_string *av_perm_to_string; +u32 av_pts_len; +u32 cts_len; +const char **class_to_string; +const struct av_inherit *av_inherit; +u32 av_inherit_len; +}; + +extern const struct selinux_class_perm selinux_class_perm; +#endif /* _FLASK_AVC_SS_H_ */
xen/xsm/flask/include/security.h +9 -5
@@ -26,10 +26,14 @@#define POLICYDB_VERSION_VALIDATETRANS 19#define POLICYDB_VERSION_MLS 19#define POLICYDB_VERSION_AVTAB 20 +#define POLICYDB_VERSION_RANGETRANS 21 +#define POLICYDB_VERSION_POLCAP 22 +#define POLICYDB_VERSION_PERMISSIVE 23 +#define POLICYDB_VERSION_BOUNDARY 24/* Range of policy versions we understand*/ #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE -#define POLICYDB_VERSION_MAX POLICYDB_VERSION_AVTAB +#define POLICYDB_VERSION_MAX POLICYDB_VERSION_BOUNDARY#ifdef FLASK_BOOTPARAM extern int flask_enabled;
@@ -43,12 +47,15 @@struct av_decision {u32 allowed; -u32 decided;u32 auditallow;u32 auditdeny;u32 seqno; +u32 flags; }; +/* definitions of av_decision.flags */ +#define AVD_FLAGS_PERMISSIVE 0x0001 +int security_compute_av (u32 ssid,u32 tsid,u16 tclass,u32 requested,struct av_decision *avd);
@@ -62,9 +69,6 @@int security_context_to_sid (char *scontext,u32 scontext_len,u32 *out_sid); -int security_context_to_sid_default (char *scontext,u32 scontext_len, -u32 *out_sid,u32 def_sid); -int security_get_user_sids (u32 callsid,char *username,u32 **sids,u32 *nel);int security_pirq_sid (int pirq,u32 *out_sid);
xen/xsm/flask/ss/avtab.c +104 -38
329 lines not on this page · raw message
xen/xsm/flask/ss/avtab.h +13 -7
@@ -16,6 +16,9 @@* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. +* +* Updated: Yuichi Nakamura <[email protected]> +* Tuned number of hash slots for avtab to reduce memory usage */ /* Ported to Xen 3.0, George Coker, <[email protected]> */
@@ -53,19 +56,23 @@struct avtab {struct avtab_node **htable;u32 nel;/* number of elements */ +u32 nslot;/* number of hash slots */ +u16 mask;/* mask to compute hash func */ };int avtab_init (struct avtab *); +int avtab_alloc (struct avtab *,u32 );struct avtab_datum *avtab_search (struct avtab *h,struct avtab_key *k);void avtab_destroy (struct avtab *h);void avtab_hash_eval (struct avtab *h,char *tag); -int avtab_read_item (void *fp,uint32_t vers,struct avtab *a, +struct policydb ; +int avtab_read_item (struct avtab *a,void *fp,struct policydb *pol,int (*insert)(struct avtab *a,struct avtab_key *k,struct avtab_datum *d,void *p),void *p); -int avtab_read (struct avtab *a,void *fp,u32 vers); +int avtab_read (struct avtab *a,void *fp,struct policydb *pol);struct avtab_node *avtab_insert_nonunique (struct avtab *h,struct avtab_key *key,struct avtab_datum *datum);
@@ -75,11 +82,10 @@struct avtab_node *avtab_search_node_next (struct avtab_node *node,int specified); -#define AVTAB_HASH_BITS 15 -#define AVTAB_HASH_BUCKETS (1 << AVTAB_HASH_BITS) -#define AVTAB_HASH_MASK (AVTAB_HASH_BUCKETS-1) - -#define AVTAB_SIZE AVTAB_HASH_BUCKETS +#define MAX_AVTAB_HASH_BITS 13 +#define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) +#define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1) +#define MAX_AVTAB_SIZE MAX_AVTAB_HASH_BUCKETS#endif /* _SS_AVTAB_H_ */
xen/xsm/flask/ss/conditional.c +13 -10
@@ -101,7 +101,7 @@ { node->cur_state = new_state;if ( new_state ==-1 ) -printk (KERN_ERR "security: expression result was undefined - disabling all rules.\n" ); +printk (KERN_ERR "Flask: expression result was undefined - disabling all rules.\n" );/* turn the rules on or off */ for ( cur = node->true_list; cur !=NULL ; cur = cur->next ) {
@@ -287,7 +287,7 @@ {if (avtab_search (&p->te_avtab, k) ) { -printk ("security: type rule already exists outside of a " +printk ("Flask: type rule already exists outside of a " "conditional." ); goto err; }
@@ -306,7 +306,7 @@ {if (avtab_search_node_next (node_ptr, k->specified) ) { -printk ("security: too many conflicting type rules." ); +printk ("Flask: too many conflicting type rules." ); goto err; } found =0 ;
@@ -320,7 +320,7 @@ }if ( !found ) { -printk ("security: conflicting type rules.\n" ); +printk ("Flask: conflicting type rules.\n" ); goto err; } }
@@ -329,7 +329,7 @@ {if (avtab_search (&p->te_cond_avtab, k) ) { -printk ("security: conflicting type rules when adding type rule " +printk ("Flask: conflicting type rules when adding type rule " "for true.\n" ); goto err; }
@@ -339,7 +339,7 @@ node_ptr =avtab_insert_nonunique (&p->te_cond_avtab, k, d);if ( !node_ptr ) { -printk ("security: could not insert rule." ); +printk ("Flask: could not insert rule." ); goto err; }
@@ -389,8 +389,7 @@ data.tail =NULL ;for ( i =0 ; i < len; i++ ) { - rc =avtab_read_item (fp, p->policyvers, &p->te_cond_avtab, cond_insertf, - &data); + rc =avtab_read_item (&p->te_cond_avtab, fp, p, cond_insertf, &data);if ( rc )return rc; }
@@ -403,13 +402,13 @@ {if ( expr->expr_type <=0 || expr->expr_type >COND_LAST ) { -printk ("security: conditional expressions uses unknown operator.\n" ); +printk ("Flask: conditional expressions uses unknown operator.\n" );return 0 ; }if ( expr->bool > p->p_bools.nprim ) { -printk ("security: conditional expressions uses unknown bool.\n" ); +printk ("Flask: conditional expressions uses unknown bool.\n" );return 0 ; }return 1 ;
@@ -489,6 +488,10 @@ len =le32_to_cpu (buf[0 ]); + rc =avtab_alloc (&(p->te_cond_avtab), p->te_avtab.nel); +if ( rc ) + goto err; +for ( i =0 ; i < len; i++ ) { node = xmalloc(struct cond_node);
xen/xsm/flask/ss/conditional.h +1 -1
@@ -28,7 +28,7 @@#define COND_XOR 5/* bool ^ bool */ #define COND_EQ 6/* bool == bool */ #define COND_NEQ 7/* bool != bool */ -#define COND_LAST 8 +#define COND_LAST COND_NEQ__u32 expr_type;__u32 bool;struct cond_expr *next;
xen/xsm/flask/ss/context.h +28 -5
@@ -42,17 +42,40 @@ {int rc; -if (!flask_mls_enabled) +if ( !flask_mls_enabled )return 0 ; dst->range.level[0 ].sens = src->range.level[0 ].sens; rc =ebitmap_cpy (&dst->range.level[0 ].cat, &src->range.level[0 ].cat); -if (rc) +if ( rc ) goto out; dst->range.level[1 ].sens = src->range.level[1 ].sens; rc =ebitmap_cpy (&dst->range.level[1 ].cat, &src->range.level[1 ].cat); -if (rc) +if ( rc ) +ebitmap_destroy (&dst->range.level[0 ].cat); +out: +return rc; +} + +/* +* Sets both levels in the MLS range of 'dst' to the low level of 'src'. +*/ +static inline int mls_context_cpy_low (struct context *dst,struct context *src) +{ +int rc; + +if ( !flask_mls_enabled ) +return 0 ; + + dst->range.level[0 ].sens = src->range.level[0 ].sens; + rc =ebitmap_cpy (&dst->range.level[0 ].cat, &src->range.level[0 ].cat); +if ( rc ) + goto out; + + dst->range.level[1 ].sens = src->range.level[0 ].sens; + rc =ebitmap_cpy (&dst->range.level[1 ].cat, &src->range.level[0 ].cat); +if ( rc )ebitmap_destroy (&dst->range.level[0 ].cat); out:return rc;
@@ -60,7 +83,7 @@static inline int mls_context_cmp (struct context *c1,struct context *c2) { -if (!flask_mls_enabled) +if ( !flask_mls_enabled )return 1 ; return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
@@ -71,7 +94,7 @@static inline void mls_context_destroy (struct context *c) { -if (!flask_mls_enabled) +if ( !flask_mls_enabled )return ;ebitmap_destroy (&c->range.level[0 ].cat);
xen/xsm/flask/ss/ebitmap.c +109 -100
321 lines not on this page · raw message
xen/xsm/flask/ss/ebitmap.h +72 -22
126 lines not on this page · raw message
xen/xsm/flask/ss/hashtab.c +6 -4
@@ -11,8 +11,10 @@#include <xen/errno.h> #include "hashtab.h" -struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h,void *key), -int (*keycmp)(struct hashtab *h,void *key1,void *key2),u32 size) +struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h, +const void *key), +int (*keycmp)(struct hashtab *h,const void *key1, +const void *key2),u32 size) {struct hashtab *p;u32 i;
@@ -26,7 +28,7 @@ p->nel =0 ; p->hash_value = hash_value; p->keycmp = keycmp; - p->htable = (void *)xmalloc_array(struct hashtab_node, size); + p->htable = xmalloc_array(struct hashtab_node *, size);if ( p->htable ==NULL ) {xfree (p);
@@ -80,7 +82,7 @@return 0 ; } -void *hashtab_search (struct hashtab *h,void *key) +void *hashtab_search (struct hashtab *h,const void *key) {u32 hvalue;struct hashtab_node *cur;
xen/xsm/flask/ss/hashtab.h +7 -5
@@ -22,9 +22,9 @@struct hashtab_node **htable;/* hash table */ u32 size;/* number of slots in hash table */ u32 nel;/* number of elements in hash table */ -u32 (*hash_value)(struct hashtab *h,void *key); +u32 (*hash_value)(struct hashtab *h,const void *key);/* hash function */ -int (*keycmp)(struct hashtab *h,void *key1,void *key2); +int (*keycmp)(struct hashtab *h,const void *key1,const void *key2);/* key comparison function */ };
@@ -39,8 +39,10 @@* Returns NULL if insufficent space is available or * the new hash table otherwise. */ -struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h,void *key), -int (*keycmp)(struct hashtab *h,void *key1,void *key2),u32 size); +struct hashtab *hashtab_create (u32 (*hash_value)(struct hashtab *h, +const void *key), +int (*keycmp)(struct hashtab *h,const void *key1, +const void *key2),u32 size);/* * Inserts the specified (key, datum) pair into the specified hash table.
@@ -58,7 +60,7 @@* Returns NULL if no entry has the specified key or * the datum of the entry otherwise. */ -void *hashtab_search (struct hashtab *h,void *k); +void *hashtab_search (struct hashtab *h,const void *k);/* * Destroys the specified hash table.
xen/xsm/flask/ss/mls.c +121 -200
453 lines not on this page · raw message
xen/xsm/flask/ss/mls.h +4 -2
@@ -8,7 +8,7 @@* * Support for enhanced MLS infrastructure. * -* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. +* Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. */ #ifndef _SS_MLS_H_
@@ -20,9 +20,11 @@int mls_compute_context_len (struct context *context);void mls_sid_to_context (struct context *context,char **scontext);int mls_context_isvalid (struct policydb *p,struct context *c); +int mls_range_isvalid (struct policydb *p,struct mls_range *r); +int mls_level_isvalid (struct policydb *p,struct mls_level *l);int mls_context_to_sid (char oldc,char **scontext,struct context *context, -struct sidtab *s,u32 def_sid); +struct sidtab *s);int mls_convert_context (struct policydb *oldp,struct policydb *newp,struct context *context);
xen/xsm/flask/ss/policydb.c +353 -58
749 lines not on this page · raw message
xen/xsm/flask/ss/policydb.h +26 -3
@@ -63,6 +63,7 @@/* Role attributes */ struct role_datum {u32 value;/* internal role value */ +u32 bounds;/* boundary of role */ struct ebitmap dominates;/* set of roles dominated by this role */ struct ebitmap types;/* set of authorized types for role */ };
@@ -83,12 +84,25 @@/* Type attributes */ struct type_datum {u32 value;/* internal type value */ +u32 bounds;/* boundary of type */ unsigned char primary;/* primary name? */ +unsigned char attribute;/* attribute ?*/ }; +/* +* type_datum properties +* available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY +*/ +#define TYPEDATUM_PROPERTY_PRIMARY 0x0001 +#define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002 + +/* limitation of boundary depth */ +#define POLICYDB_BOUNDS_MAXDEPTH 4 +/* User attributes */ struct user_datum {u32 value;/* internal user value */ +u32 bounds;/* bounds of user */ struct ebitmap roles;/* set of authorized roles for user */ struct mls_range range;/* MLS range (min - max) for user */ struct mls_level dfltlevel;/* default login MLS level for user */
@@ -108,9 +122,10 @@ };struct range_trans { -u32 dom;/* current process domain */ -u32 type;/* program executable type */ -struct mls_range range;/* new range */ +u32 source_type; +u32 target_type; +u32 target_class; +struct mls_range target_range;struct range_trans *next; };
@@ -191,6 +206,7 @@struct class_datum **class_val_to_struct;struct role_datum **role_val_to_struct;struct user_datum **user_val_to_struct; +struct type_datum **type_val_to_struct;/* type enforcement access vectors and transitions */ struct avtab te_avtab;
@@ -218,12 +234,19 @@/* type -> attribute reverse mapping */ struct ebitmap *type_attr_map; +struct ebitmap policycaps; + +struct ebitmap permissive_map; +unsigned int policyvers; };extern void policydb_destroy (struct policydb *p);extern int policydb_load_isids (struct policydb *p,struct sidtab *s);extern int policydb_context_isvalid (struct policydb *p,struct context *c); +extern int policydb_class_isvalid (struct policydb *p,unsigned int class); +extern int policydb_type_isvalid (struct policydb *p,unsigned int type); +extern int policydb_role_isvalid (struct policydb *p,unsigned int role);extern int policydb_read (struct policydb *p,void *fp);#define PERM_SYMTAB_SIZE 32
xen/xsm/flask/ss/services.c +410 -164
130 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.