Commit 19b5b517 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6:
  SELinux: one little, two little, three little whitespaces, the avc.c saga.
  SELinux: cleanup on isle selinuxfs.c
  changing whitespace for fun and profit: policydb.c
  SELinux: whitespace and formating fixes for hooks.c
  SELinux: clean up printks
  SELinux: sidtab.c whitespace, syntax, and static declaraction cleanups
  SELinux: services.c whitespace, syntax, and static declaraction cleanups
  SELinux: mls.c whitespace, syntax, and static declaraction cleanups
  SELinux: hashtab.c whitespace, syntax, and static declaraction cleanups
  SELinux: ebitmap.c whitespace, syntax, and static declaraction cleanups
  SELinux: conditional.c whitespace, syntax, and static declaraction cleanups
  SELinux: avtab.c whitespace, syntax, and static declaraction cleanups
  SELinux: xfrm.c whitespace, syntax, and static declaraction cleanups
  SELinux: nlmsgtab.c whitespace, syntax, and static declaraction cleanups
  SELinux: netnode.c whitespace, syntax, and static declaraction cleanups
  SELinux: netlink.c whitespace, syntax, and static declaraction cleanups
  SELinux: netlabel.c whitespace, syntax, and static declaraction cleanups
  SELinux: netif.c whitespace, syntax, and static declaraction cleanups
parents bda0c0af 95fff33b
...@@ -44,7 +44,7 @@ static const char *class_to_string[] = { ...@@ -44,7 +44,7 @@ static const char *class_to_string[] = {
#undef S_ #undef S_
}; };
#define TB_(s) static const char * s [] = { #define TB_(s) static const char *s[] = {
#define TE_(s) }; #define TE_(s) };
#define S_(s) s, #define S_(s) s,
#include "common_perm_to_string.h" #include "common_perm_to_string.h"
...@@ -306,7 +306,7 @@ static inline int avc_reclaim_node(void) ...@@ -306,7 +306,7 @@ static inline int avc_reclaim_node(void)
int hvalue, try, ecx; int hvalue, try, ecx;
unsigned long flags; unsigned long flags;
for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++ ) { for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1); hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
if (!spin_trylock_irqsave(&avc_cache.slots_lock[hvalue], flags)) if (!spin_trylock_irqsave(&avc_cache.slots_lock[hvalue], flags))
...@@ -426,7 +426,7 @@ static int avc_latest_notif_update(int seqno, int is_insert) ...@@ -426,7 +426,7 @@ static int avc_latest_notif_update(int seqno, int is_insert)
spin_lock_irqsave(&notif_lock, flag); spin_lock_irqsave(&notif_lock, flag);
if (is_insert) { if (is_insert) {
if (seqno < avc_cache.latest_notif) { if (seqno < avc_cache.latest_notif) {
printk(KERN_WARNING "avc: seqno %d < latest_notif %d\n", printk(KERN_WARNING "SELinux: avc: seqno %d < latest_notif %d\n",
seqno, avc_cache.latest_notif); seqno, avc_cache.latest_notif);
ret = -EAGAIN; ret = -EAGAIN;
} }
...@@ -551,7 +551,7 @@ void avc_audit(u32 ssid, u32 tsid, ...@@ -551,7 +551,7 @@ void avc_audit(u32 ssid, u32 tsid,
if (!ab) if (!ab)
return; /* audit_panic has been called */ return; /* audit_panic has been called */
audit_log_format(ab, "avc: %s ", denied ? "denied" : "granted"); audit_log_format(ab, "avc: %s ", denied ? "denied" : "granted");
avc_dump_av(ab, tclass,audited); avc_dump_av(ab, tclass, audited);
audit_log_format(ab, " for "); audit_log_format(ab, " for ");
if (a && a->tsk) if (a && a->tsk)
tsk = a->tsk; tsk = a->tsk;
...@@ -759,10 +759,10 @@ static int avc_update_node(u32 event, u32 perms, u32 ssid, u32 tsid, u16 tclass) ...@@ -759,10 +759,10 @@ static int avc_update_node(u32 event, u32 perms, u32 ssid, u32 tsid, u16 tclass)
hvalue = avc_hash(ssid, tsid, tclass); hvalue = avc_hash(ssid, tsid, tclass);
spin_lock_irqsave(&avc_cache.slots_lock[hvalue], flag); spin_lock_irqsave(&avc_cache.slots_lock[hvalue], flag);
list_for_each_entry(pos, &avc_cache.slots[hvalue], list){ list_for_each_entry(pos, &avc_cache.slots[hvalue], list) {
if ( ssid==pos->ae.ssid && if (ssid == pos->ae.ssid &&
tsid==pos->ae.tsid && tsid == pos->ae.tsid &&
tclass==pos->ae.tclass ){ tclass == pos->ae.tclass){
orig = pos; orig = pos;
break; break;
} }
...@@ -878,11 +878,11 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, ...@@ -878,11 +878,11 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
node = avc_lookup(ssid, tsid, tclass, requested); node = avc_lookup(ssid, tsid, tclass, requested);
if (!node) { if (!node) {
rcu_read_unlock(); rcu_read_unlock();
rc = security_compute_av(ssid,tsid,tclass,requested,&entry.avd); rc = security_compute_av(ssid, tsid, tclass, requested, &entry.avd);
if (rc) if (rc)
goto out; goto out;
rcu_read_lock(); rcu_read_lock();
node = avc_insert(ssid,tsid,tclass,&entry); node = avc_insert(ssid, tsid, tclass, &entry);
} }
p_ae = node ? &node->ae : &entry; p_ae = node ? &node->ae : &entry;
......
This diff is collapsed.
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
#define SEL_NETIF_HASH_SIZE 64 #define SEL_NETIF_HASH_SIZE 64
#define SEL_NETIF_HASH_MAX 1024 #define SEL_NETIF_HASH_MAX 1024
struct sel_netif struct sel_netif {
{
struct list_head list; struct list_head list;
struct netif_security_struct nsec; struct netif_security_struct nsec;
struct rcu_head rcu_head; struct rcu_head rcu_head;
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#include "flask.h" #include "flask.h"
#include "av_permissions.h" #include "av_permissions.h"
struct nlmsg_perm struct nlmsg_perm {
{
u16 nlmsg_type; u16 nlmsg_type;
u32 perm; u32 perm;
}; };
......
This diff is collapsed.
...@@ -33,10 +33,10 @@ static inline int avtab_hash(struct avtab_key *keyp, u16 mask) ...@@ -33,10 +33,10 @@ static inline int avtab_hash(struct avtab_key *keyp, u16 mask)
static struct avtab_node* static struct avtab_node*
avtab_insert_node(struct avtab *h, int hvalue, avtab_insert_node(struct avtab *h, int hvalue,
struct avtab_node * prev, struct avtab_node * cur, struct avtab_node *prev, struct avtab_node *cur,
struct avtab_key *key, struct avtab_datum *datum) struct avtab_key *key, struct avtab_datum *datum)
{ {
struct avtab_node * newnode; struct avtab_node *newnode;
newnode = kmem_cache_zalloc(avtab_node_cachep, GFP_KERNEL); newnode = kmem_cache_zalloc(avtab_node_cachep, GFP_KERNEL);
if (newnode == NULL) if (newnode == NULL)
return NULL; return NULL;
...@@ -84,7 +84,7 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat ...@@ -84,7 +84,7 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat
} }
newnode = avtab_insert_node(h, hvalue, prev, cur, key, datum); newnode = avtab_insert_node(h, hvalue, prev, cur, key, datum);
if(!newnode) if (!newnode)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
...@@ -95,7 +95,7 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat ...@@ -95,7 +95,7 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat
* It also returns a pointer to the node inserted. * It also returns a pointer to the node inserted.
*/ */
struct avtab_node * struct avtab_node *
avtab_insert_nonunique(struct avtab * h, struct avtab_key * key, struct avtab_datum * datum) avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, struct avtab_datum *datum)
{ {
int hvalue; int hvalue;
struct avtab_node *prev, *cur, *newnode; struct avtab_node *prev, *cur, *newnode;
...@@ -310,8 +310,8 @@ void avtab_hash_eval(struct avtab *h, char *tag) ...@@ -310,8 +310,8 @@ void avtab_hash_eval(struct avtab *h, char *tag)
} }
} }
printk(KERN_DEBUG "%s: %d entries and %d/%d buckets used, longest " printk(KERN_DEBUG "SELinux: %s: %d entries and %d/%d buckets used, "
"chain length %d sum of chain length^2 %Lu\n", "longest chain length %d sum of chain length^2 %Lu\n",
tag, h->nel, slots_used, h->nslot, max_chain_len, tag, h->nel, slots_used, h->nslot, max_chain_len,
chain2_len_sum); chain2_len_sum);
} }
...@@ -364,19 +364,19 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, ...@@ -364,19 +364,19 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
val = le32_to_cpu(buf32[items++]); val = le32_to_cpu(buf32[items++]);
key.source_type = (u16)val; key.source_type = (u16)val;
if (key.source_type != val) { if (key.source_type != val) {
printk("SELinux: avtab: truncated source type\n"); printk(KERN_ERR "SELinux: avtab: truncated source type\n");
return -1; return -1;
} }
val = le32_to_cpu(buf32[items++]); val = le32_to_cpu(buf32[items++]);
key.target_type = (u16)val; key.target_type = (u16)val;
if (key.target_type != val) { if (key.target_type != val) {
printk("SELinux: avtab: truncated target type\n"); printk(KERN_ERR "SELinux: avtab: truncated target type\n");
return -1; return -1;
} }
val = le32_to_cpu(buf32[items++]); val = le32_to_cpu(buf32[items++]);
key.target_class = (u16)val; key.target_class = (u16)val;
if (key.target_class != val) { if (key.target_class != val) {
printk("SELinux: avtab: truncated target class\n"); printk(KERN_ERR "SELinux: avtab: truncated target class\n");
return -1; return -1;
} }
...@@ -384,12 +384,12 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, ...@@ -384,12 +384,12 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
enabled = (val & AVTAB_ENABLED_OLD) ? AVTAB_ENABLED : 0; enabled = (val & AVTAB_ENABLED_OLD) ? AVTAB_ENABLED : 0;
if (!(val & (AVTAB_AV | AVTAB_TYPE))) { if (!(val & (AVTAB_AV | AVTAB_TYPE))) {
printk("SELinux: avtab: null entry\n"); printk(KERN_ERR "SELinux: avtab: null entry\n");
return -1; return -1;
} }
if ((val & AVTAB_AV) && if ((val & AVTAB_AV) &&
(val & AVTAB_TYPE)) { (val & AVTAB_TYPE)) {
printk("SELinux: avtab: entry has both access vectors and types\n"); printk(KERN_ERR "SELinux: avtab: entry has both access vectors and types\n");
return -1; return -1;
} }
...@@ -398,12 +398,13 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, ...@@ -398,12 +398,13 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
key.specified = spec_order[i] | enabled; key.specified = spec_order[i] | enabled;
datum.data = le32_to_cpu(buf32[items++]); datum.data = le32_to_cpu(buf32[items++]);
rc = insertf(a, &key, &datum, p); rc = insertf(a, &key, &datum, p);
if (rc) return rc; if (rc)
return rc;
} }
} }
if (items != items2) { if (items != items2) {
printk("SELinux: avtab: entry only had %d items, expected %d\n", items2, items); printk(KERN_ERR "SELinux: avtab: entry only had %d items, expected %d\n", items2, items);
return -1; return -1;
} }
return 0; return 0;
...@@ -411,7 +412,7 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, ...@@ -411,7 +412,7 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
rc = next_entry(buf16, fp, sizeof(u16)*4); rc = next_entry(buf16, fp, sizeof(u16)*4);
if (rc < 0) { if (rc < 0) {
printk("SELinux: avtab: truncated entry\n"); printk(KERN_ERR "SELinux: avtab: truncated entry\n");
return -1; return -1;
} }
...@@ -424,7 +425,7 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, ...@@ -424,7 +425,7 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
if (!policydb_type_isvalid(pol, key.source_type) || if (!policydb_type_isvalid(pol, key.source_type) ||
!policydb_type_isvalid(pol, key.target_type) || !policydb_type_isvalid(pol, key.target_type) ||
!policydb_class_isvalid(pol, key.target_class)) { !policydb_class_isvalid(pol, key.target_class)) {
printk(KERN_WARNING "SELinux: avtab: invalid type or class\n"); printk(KERN_ERR "SELinux: avtab: invalid type or class\n");
return -1; return -1;
} }
...@@ -434,20 +435,19 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, ...@@ -434,20 +435,19 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
set++; set++;
} }
if (!set || set > 1) { if (!set || set > 1) {
printk(KERN_WARNING printk(KERN_ERR "SELinux: avtab: more than one specifier\n");
"SELinux: avtab: more than one specifier\n");
return -1; return -1;
} }
rc = next_entry(buf32, fp, sizeof(u32)); rc = next_entry(buf32, fp, sizeof(u32));
if (rc < 0) { if (rc < 0) {
printk("SELinux: avtab: truncated entry\n"); printk(KERN_ERR "SELinux: avtab: truncated entry\n");
return -1; return -1;
} }
datum.data = le32_to_cpu(*buf32); datum.data = le32_to_cpu(*buf32);
if ((key.specified & AVTAB_TYPE) && if ((key.specified & AVTAB_TYPE) &&
!policydb_type_isvalid(pol, datum.data)) { !policydb_type_isvalid(pol, datum.data)) {
printk(KERN_WARNING "SELinux: avtab: invalid type\n"); printk(KERN_ERR "SELinux: avtab: invalid type\n");
return -1; return -1;
} }
return insertf(a, &key, &datum, p); return insertf(a, &key, &datum, p);
...@@ -513,5 +513,5 @@ void avtab_cache_init(void) ...@@ -513,5 +513,5 @@ void avtab_cache_init(void)
void avtab_cache_destroy(void) void avtab_cache_destroy(void)
{ {
kmem_cache_destroy (avtab_node_cachep); kmem_cache_destroy(avtab_node_cachep);
} }
...@@ -89,7 +89,7 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr) ...@@ -89,7 +89,7 @@ static int cond_evaluate_expr(struct policydb *p, struct cond_expr *expr)
int evaluate_cond_node(struct policydb *p, struct cond_node *node) int evaluate_cond_node(struct policydb *p, struct cond_node *node)
{ {
int new_state; int new_state;
struct cond_av_list* cur; struct cond_av_list *cur;
new_state = cond_evaluate_expr(p, node->expr); new_state = cond_evaluate_expr(p, node->expr);
if (new_state != node->cur_state) { if (new_state != node->cur_state) {
...@@ -98,22 +98,20 @@ int evaluate_cond_node(struct policydb *p, struct cond_node *node) ...@@ -98,22 +98,20 @@ int evaluate_cond_node(struct policydb *p, struct cond_node *node)
printk(KERN_ERR "SELinux: expression result was undefined - disabling all rules.\n"); printk(KERN_ERR "SELinux: expression result was undefined - disabling all rules.\n");
/* turn the rules on or off */ /* turn the rules on or off */
for (cur = node->true_list; cur != NULL; cur = cur->next) { for (cur = node->true_list; cur != NULL; cur = cur->next) {
if (new_state <= 0) { if (new_state <= 0)
cur->node->key.specified &= ~AVTAB_ENABLED; cur->node->key.specified &= ~AVTAB_ENABLED;
} else { else
cur->node->key.specified |= AVTAB_ENABLED; cur->node->key.specified |= AVTAB_ENABLED;
} }
}
for (cur = node->false_list; cur != NULL; cur = cur->next) { for (cur = node->false_list; cur != NULL; cur = cur->next) {
/* -1 or 1 */ /* -1 or 1 */
if (new_state) { if (new_state)
cur->node->key.specified &= ~AVTAB_ENABLED; cur->node->key.specified &= ~AVTAB_ENABLED;
} else { else
cur->node->key.specified |= AVTAB_ENABLED; cur->node->key.specified |= AVTAB_ENABLED;
} }
} }
}
return 0; return 0;
} }
...@@ -173,8 +171,8 @@ void cond_policydb_destroy(struct policydb *p) ...@@ -173,8 +171,8 @@ void cond_policydb_destroy(struct policydb *p)
int cond_init_bool_indexes(struct policydb *p) int cond_init_bool_indexes(struct policydb *p)
{ {
kfree(p->bool_val_to_struct); kfree(p->bool_val_to_struct);
p->bool_val_to_struct = (struct cond_bool_datum**) p->bool_val_to_struct = (struct cond_bool_datum **)
kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum*), GFP_KERNEL); kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL);
if (!p->bool_val_to_struct) if (!p->bool_val_to_struct)
return -1; return -1;
return 0; return 0;
...@@ -199,7 +197,7 @@ int cond_index_bool(void *key, void *datum, void *datap) ...@@ -199,7 +197,7 @@ int cond_index_bool(void *key, void *datum, void *datap)
return -EINVAL; return -EINVAL;
p->p_bool_val_to_name[booldatum->value - 1] = key; p->p_bool_val_to_name[booldatum->value - 1] = key;
p->bool_val_to_struct[booldatum->value -1] = booldatum; p->bool_val_to_struct[booldatum->value - 1] = booldatum;
return 0; return 0;
} }
...@@ -251,8 +249,7 @@ err: ...@@ -251,8 +249,7 @@ err:
return -1; return -1;
} }
struct cond_insertf_data struct cond_insertf_data {
{
struct policydb *p; struct policydb *p;
struct cond_av_list *other; struct cond_av_list *other;
struct cond_av_list *head; struct cond_av_list *head;
...@@ -275,7 +272,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum ...@@ -275,7 +272,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
*/ */
if (k->specified & AVTAB_TYPE) { if (k->specified & AVTAB_TYPE) {
if (avtab_search(&p->te_avtab, k)) { if (avtab_search(&p->te_avtab, k)) {
printk("SELinux: type rule already exists outside of a conditional."); printk(KERN_ERR "SELinux: type rule already exists outside of a conditional.\n");
goto err; goto err;
} }
/* /*
...@@ -290,7 +287,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum ...@@ -290,7 +287,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
node_ptr = avtab_search_node(&p->te_cond_avtab, k); node_ptr = avtab_search_node(&p->te_cond_avtab, k);
if (node_ptr) { if (node_ptr) {
if (avtab_search_node_next(node_ptr, k->specified)) { if (avtab_search_node_next(node_ptr, k->specified)) {
printk("SELinux: too many conflicting type rules."); printk(KERN_ERR "SELinux: too many conflicting type rules.\n");
goto err; goto err;
} }
found = 0; found = 0;
...@@ -301,13 +298,13 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum ...@@ -301,13 +298,13 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
} }
} }
if (!found) { if (!found) {
printk("SELinux: conflicting type rules.\n"); printk(KERN_ERR "SELinux: conflicting type rules.\n");
goto err; goto err;
} }
} }
} else { } else {
if (avtab_search(&p->te_cond_avtab, k)) { if (avtab_search(&p->te_cond_avtab, k)) {
printk("SELinux: conflicting type rules when adding type rule for true.\n"); printk(KERN_ERR "SELinux: conflicting type rules when adding type rule for true.\n");
goto err; goto err;
} }
} }
...@@ -315,7 +312,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum ...@@ -315,7 +312,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d); node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d);
if (!node_ptr) { if (!node_ptr) {
printk("SELinux: could not insert rule."); printk(KERN_ERR "SELinux: could not insert rule.\n");
goto err; goto err;
} }
...@@ -352,9 +349,8 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list * ...@@ -352,9 +349,8 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list *
return -1; return -1;
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
if (len == 0) { if (len == 0)
return 0; return 0;
}
data.p = p; data.p = p;
data.other = other; data.other = other;
...@@ -375,12 +371,12 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list * ...@@ -375,12 +371,12 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list *
static int expr_isvalid(struct policydb *p, struct cond_expr *expr) static int expr_isvalid(struct policydb *p, struct cond_expr *expr)
{ {
if (expr->expr_type <= 0 || expr->expr_type > COND_LAST) { if (expr->expr_type <= 0 || expr->expr_type > COND_LAST) {
printk("SELinux: conditional expressions uses unknown operator.\n"); printk(KERN_ERR "SELinux: conditional expressions uses unknown operator.\n");
return 0; return 0;
} }
if (expr->bool > p->p_bools.nprim) { if (expr->bool > p->p_bools.nprim) {
printk("SELinux: conditional expressions uses unknown bool.\n"); printk(KERN_ERR "SELinux: conditional expressions uses unknown bool.\n");
return 0; return 0;
} }
return 1; return 1;
...@@ -407,15 +403,14 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) ...@@ -407,15 +403,14 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
/* expr */ /* expr */
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
for (i = 0; i < len; i++ ) { for (i = 0; i < len; i++) {
rc = next_entry(buf, fp, sizeof(u32) * 2); rc = next_entry(buf, fp, sizeof(u32) * 2);
if (rc < 0) if (rc < 0)
goto err; goto err;
expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL); expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL);
if (!expr) { if (!expr)
goto err; goto err;
}
expr->expr_type = le32_to_cpu(buf[0]); expr->expr_type = le32_to_cpu(buf[0]);
expr->bool = le32_to_cpu(buf[1]); expr->bool = le32_to_cpu(buf[1]);
...@@ -425,11 +420,10 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) ...@@ -425,11 +420,10 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
goto err; goto err;
} }
if (i == 0) { if (i == 0)
node->expr = expr; node->expr = expr;
} else { else
last->next = expr; last->next = expr;
}
last = expr; last = expr;
} }
...@@ -468,11 +462,10 @@ int cond_read_list(struct policydb *p, void *fp) ...@@ -468,11 +462,10 @@ int cond_read_list(struct policydb *p, void *fp)
if (cond_read_node(p, node, fp) != 0) if (cond_read_node(p, node, fp) != 0)
goto err; goto err;
if (i == 0) { if (i == 0)
p->cond_list = node; p->cond_list = node;
} else { else
last->next = node; last->next = node;
}
last = node; last = node;
} }
return 0; return 0;
...@@ -489,15 +482,15 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decisi ...@@ -489,15 +482,15 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decisi
{ {
struct avtab_node *node; struct avtab_node *node;
if(!ctab || !key || !avd) if (!ctab || !key || !avd)
return; return;
for(node = avtab_search_node(ctab, key); node != NULL; for (node = avtab_search_node(ctab, key); node != NULL;
node = avtab_search_node_next(node, key->specified)) { node = avtab_search_node_next(node, key->specified)) {
if ( (u16) (AVTAB_ALLOWED|AVTAB_ENABLED) == if ((u16)(AVTAB_ALLOWED|AVTAB_ENABLED) ==
(node->key.specified & (AVTAB_ALLOWED|AVTAB_ENABLED))) (node->key.specified & (AVTAB_ALLOWED|AVTAB_ENABLED)))
avd->allowed |= node->datum.data; avd->allowed |= node->datum.data;
if ( (u16) (AVTAB_AUDITDENY|AVTAB_ENABLED) == if ((u16)(AVTAB_AUDITDENY|AVTAB_ENABLED) ==
(node->key.specified & (AVTAB_AUDITDENY|AVTAB_ENABLED))) (node->key.specified & (AVTAB_AUDITDENY|AVTAB_ENABLED)))
/* Since a '0' in an auditdeny mask represents a /* Since a '0' in an auditdeny mask represents a
* permission we do NOT want to audit (dontaudit), we use * permission we do NOT want to audit (dontaudit), we use
...@@ -505,7 +498,7 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decisi ...@@ -505,7 +498,7 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decisi
* are retained (much unlike the allow and auditallow cases). * are retained (much unlike the allow and auditallow cases).
*/ */
avd->auditdeny &= node->datum.data; avd->auditdeny &= node->datum.data;
if ( (u16) (AVTAB_AUDITALLOW|AVTAB_ENABLED) == if ((u16)(AVTAB_AUDITALLOW|AVTAB_ENABLED) ==
(node->key.specified & (AVTAB_AUDITALLOW|AVTAB_ENABLED))) (node->key.specified & (AVTAB_AUDITALLOW|AVTAB_ENABLED)))
avd->auditallow |= node->datum.data; avd->auditallow |= node->datum.data;
} }
......
...@@ -411,11 +411,10 @@ int ebitmap_read(struct ebitmap *e, void *fp) ...@@ -411,11 +411,10 @@ int ebitmap_read(struct ebitmap *e, void *fp)
} }
/* round down */ /* round down */
tmp->startbit = startbit - (startbit % EBITMAP_SIZE); tmp->startbit = startbit - (startbit % EBITMAP_SIZE);
if (n) { if (n)
n->next = tmp; n->next = tmp;
} else { else
e->node = tmp; e->node = tmp;
}
n = tmp; n = tmp;
} else if (startbit <= n->startbit) { } else if (startbit <= n->startbit) {
printk(KERN_ERR "SELinux: ebitmap: start bit %d" printk(KERN_ERR "SELinux: ebitmap: start bit %d"
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
* Return the length in bytes for the MLS fields of the * Return the length in bytes for the MLS fields of the
* security context string representation of `context'. * security context string representation of `context'.
*/ */
int mls_compute_context_len(struct context * context) int mls_compute_context_len(struct context *context)
{ {
int i, l, len, head, prev; int i, l, len, head, prev;
char *nm; char *nm;
...@@ -305,7 +305,8 @@ int mls_context_to_sid(char oldc, ...@@ -305,7 +305,8 @@ int mls_context_to_sid(char oldc,
*p++ = 0; *p++ = 0;
/* Separate into range if exists */ /* Separate into range if exists */
if ((rngptr = strchr(scontextp, '.')) != NULL) { rngptr = strchr(scontextp, '.');
if (rngptr != NULL) {
/* Remove '.' */ /* Remove '.' */
*rngptr++ = 0; *rngptr++ = 0;
} }
...@@ -449,11 +450,11 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user, ...@@ -449,11 +450,11 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
that of the user's default clearance (but that of the user's default clearance (but
only if the "fromcon" clearance dominates only if the "fromcon" clearance dominates
the user's computed sensitivity level) */ the user's computed sensitivity level) */
if (mls_level_dom(user_clr, fromcon_clr)) { if (mls_level_dom(user_clr, fromcon_clr))
*usercon_clr = *fromcon_clr; *usercon_clr = *fromcon_clr;
} else if (mls_level_dom(fromcon_clr, user_clr)) { else if (mls_level_dom(fromcon_clr, user_clr))
*usercon_clr = *user_clr; *usercon_clr = *user_clr;
} else else
return -EINVAL; return -EINVAL;
} }
......
...@@ -51,7 +51,7 @@ static char *symtab_name[SYM_NUM] = { ...@@ -51,7 +51,7 @@ static char *symtab_name[SYM_NUM] = {
}; };
#endif #endif
int selinux_mls_enabled = 0; int selinux_mls_enabled;
static unsigned int symtab_sizes[SYM_NUM] = { static unsigned int symtab_sizes[SYM_NUM] = {
2, 2,
...@@ -152,7 +152,7 @@ static int roles_init(struct policydb *p) ...@@ -152,7 +152,7 @@ static int roles_init(struct policydb *p)
rc = -EINVAL; rc = -EINVAL;
goto out_free_role; goto out_free_role;
} }
key = kmalloc(strlen(OBJECT_R)+1,GFP_KERNEL); key = kmalloc(strlen(OBJECT_R)+1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto out_free_role; goto out_free_role;
...@@ -390,7 +390,7 @@ static void symtab_hash_eval(struct symtab *s) ...@@ -390,7 +390,7 @@ static void symtab_hash_eval(struct symtab *s)
struct hashtab_info info; struct hashtab_info info;
hashtab_stat(h, &info); hashtab_stat(h, &info);
printk(KERN_DEBUG "%s: %d entries and %d/%d buckets used, " printk(KERN_DEBUG "SELinux: %s: %d entries and %d/%d buckets used, "
"longest chain length %d\n", symtab_name[i], h->nel, "longest chain length %d\n", symtab_name[i], h->nel,
info.slots_used, h->size, info.max_chain_len); info.slots_used, h->size, info.max_chain_len);
} }
...@@ -634,7 +634,7 @@ void policydb_destroy(struct policydb *p) ...@@ -634,7 +634,7 @@ void policydb_destroy(struct policydb *p)
while (c) { while (c) {
ctmp = c; ctmp = c;
c = c->next; c = c->next;
ocontext_destroy(ctmp,i); ocontext_destroy(ctmp, i);
} }
p->ocontexts[i] = NULL; p->ocontexts[i] = NULL;
} }
...@@ -647,7 +647,7 @@ void policydb_destroy(struct policydb *p) ...@@ -647,7 +647,7 @@ void policydb_destroy(struct policydb *p)
while (c) { while (c) {
ctmp = c; ctmp = c;
c = c->next; c = c->next;
ocontext_destroy(ctmp,OCON_FSUSE); ocontext_destroy(ctmp, OCON_FSUSE);
} }
gtmp = g; gtmp = g;
g = g->next; g = g->next;
...@@ -664,14 +664,14 @@ void policydb_destroy(struct policydb *p) ...@@ -664,14 +664,14 @@ void policydb_destroy(struct policydb *p)
} }
kfree(ltr); kfree(ltr);
for (ra = p->role_allow; ra; ra = ra -> next) { for (ra = p->role_allow; ra; ra = ra->next) {
cond_resched(); cond_resched();
kfree(lra); kfree(lra);
lra = ra; lra = ra;
} }
kfree(lra); kfree(lra);
for (rt = p->range_tr; rt; rt = rt -> next) { for (rt = p->range_tr; rt; rt = rt->next) {
cond_resched(); cond_resched();
if (lrt) { if (lrt) {
ebitmap_destroy(&lrt->target_range.level[0].cat); ebitmap_destroy(&lrt->target_range.level[0].cat);
...@@ -924,7 +924,7 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -924,7 +924,7 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
perdatum->value = le32_to_cpu(buf[1]); perdatum->value = le32_to_cpu(buf[1]);
key = kmalloc(len + 1,GFP_KERNEL); key = kmalloc(len + 1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -971,7 +971,7 @@ static int common_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -971,7 +971,7 @@ static int common_read(struct policydb *p, struct hashtab *h, void *fp)
comdatum->permissions.nprim = le32_to_cpu(buf[2]); comdatum->permissions.nprim = le32_to_cpu(buf[2]);
nel = le32_to_cpu(buf[3]); nel = le32_to_cpu(buf[3]);
key = kmalloc(len + 1,GFP_KERNEL); key = kmalloc(len + 1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1012,11 +1012,10 @@ static int read_cons_helper(struct constraint_node **nodep, int ncons, ...@@ -1012,11 +1012,10 @@ static int read_cons_helper(struct constraint_node **nodep, int ncons,
if (!c) if (!c)
return -ENOMEM; return -ENOMEM;
if (lc) { if (lc)
lc->next = c; lc->next = c;
} else { else
*nodep = c; *nodep = c;
}
rc = next_entry(buf, fp, (sizeof(u32) * 2)); rc = next_entry(buf, fp, (sizeof(u32) * 2));
if (rc < 0) if (rc < 0)
...@@ -1030,11 +1029,10 @@ static int read_cons_helper(struct constraint_node **nodep, int ncons, ...@@ -1030,11 +1029,10 @@ static int read_cons_helper(struct constraint_node **nodep, int ncons,
if (!e) if (!e)
return -ENOMEM; return -ENOMEM;
if (le) { if (le)
le->next = e; le->next = e;
} else { else
c->expr = e; c->expr = e;
}
rc = next_entry(buf, fp, (sizeof(u32) * 3)); rc = next_entry(buf, fp, (sizeof(u32) * 3));
if (rc < 0) if (rc < 0)
...@@ -1111,7 +1109,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1111,7 +1109,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
ncons = le32_to_cpu(buf[5]); ncons = le32_to_cpu(buf[5]);
key = kmalloc(len + 1,GFP_KERNEL); key = kmalloc(len + 1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1122,7 +1120,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1122,7 +1120,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
key[len] = 0; key[len] = 0;
if (len2) { if (len2) {
cladatum->comkey = kmalloc(len2 + 1,GFP_KERNEL); cladatum->comkey = kmalloc(len2 + 1, GFP_KERNEL);
if (!cladatum->comkey) { if (!cladatum->comkey) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1195,7 +1193,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1195,7 +1193,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
role->value = le32_to_cpu(buf[1]); role->value = le32_to_cpu(buf[1]);
key = kmalloc(len + 1,GFP_KERNEL); key = kmalloc(len + 1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1215,7 +1213,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1215,7 +1213,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
if (strcmp(key, OBJECT_R) == 0) { if (strcmp(key, OBJECT_R) == 0) {
if (role->value != OBJECT_R_VAL) { if (role->value != OBJECT_R_VAL) {
printk(KERN_ERR "Role %s has wrong value %d\n", printk(KERN_ERR "SELinux: Role %s has wrong value %d\n",
OBJECT_R, role->value); OBJECT_R, role->value);
rc = -EINVAL; rc = -EINVAL;
goto bad; goto bad;
...@@ -1242,7 +1240,7 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1242,7 +1240,7 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp)
__le32 buf[3]; __le32 buf[3];
u32 len; u32 len;
typdatum = kzalloc(sizeof(*typdatum),GFP_KERNEL); typdatum = kzalloc(sizeof(*typdatum), GFP_KERNEL);
if (!typdatum) { if (!typdatum) {
rc = -ENOMEM; rc = -ENOMEM;
return rc; return rc;
...@@ -1256,7 +1254,7 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1256,7 +1254,7 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp)
typdatum->value = le32_to_cpu(buf[1]); typdatum->value = le32_to_cpu(buf[1]);
typdatum->primary = le32_to_cpu(buf[2]); typdatum->primary = le32_to_cpu(buf[2]);
key = kmalloc(len + 1,GFP_KERNEL); key = kmalloc(len + 1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1328,7 +1326,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1328,7 +1326,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
usrdatum->value = le32_to_cpu(buf[1]); usrdatum->value = le32_to_cpu(buf[1]);
key = kmalloc(len + 1,GFP_KERNEL); key = kmalloc(len + 1, GFP_KERNEL);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1382,7 +1380,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1382,7 +1380,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
levdatum->isalias = le32_to_cpu(buf[1]); levdatum->isalias = le32_to_cpu(buf[1]);
key = kmalloc(len + 1,GFP_ATOMIC); key = kmalloc(len + 1, GFP_ATOMIC);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1434,7 +1432,7 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -1434,7 +1432,7 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
catdatum->value = le32_to_cpu(buf[1]); catdatum->value = le32_to_cpu(buf[1]);
catdatum->isalias = le32_to_cpu(buf[2]); catdatum->isalias = le32_to_cpu(buf[2]);
key = kmalloc(len + 1,GFP_ATOMIC); key = kmalloc(len + 1, GFP_ATOMIC);
if (!key) { if (!key) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1493,7 +1491,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1493,7 +1491,7 @@ int policydb_read(struct policydb *p, void *fp)
goto out; goto out;
/* Read the magic number and string length. */ /* Read the magic number and string length. */
rc = next_entry(buf, fp, sizeof(u32)* 2); rc = next_entry(buf, fp, sizeof(u32) * 2);
if (rc < 0) if (rc < 0)
goto bad; goto bad;
...@@ -1511,7 +1509,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1511,7 +1509,7 @@ int policydb_read(struct policydb *p, void *fp)
len, strlen(POLICYDB_STRING)); len, strlen(POLICYDB_STRING));
goto bad; goto bad;
} }
policydb_str = kmalloc(len + 1,GFP_KERNEL); policydb_str = kmalloc(len + 1, GFP_KERNEL);
if (!policydb_str) { if (!policydb_str) {
printk(KERN_ERR "SELinux: unable to allocate memory for policydb " printk(KERN_ERR "SELinux: unable to allocate memory for policydb "
"string of length %d\n", len); "string of length %d\n", len);
...@@ -1551,22 +1549,23 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1551,22 +1549,23 @@ int policydb_read(struct policydb *p, void *fp)
if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) { if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) {
if (ss_initialized && !selinux_mls_enabled) { if (ss_initialized && !selinux_mls_enabled) {
printk(KERN_ERR "Cannot switch between non-MLS and MLS " printk(KERN_ERR "SELinux: Cannot switch between non-MLS"
"policies\n"); " and MLS policies\n");
goto bad; goto bad;
} }
selinux_mls_enabled = 1; selinux_mls_enabled = 1;
config |= POLICYDB_CONFIG_MLS; config |= POLICYDB_CONFIG_MLS;
if (p->policyvers < POLICYDB_VERSION_MLS) { if (p->policyvers < POLICYDB_VERSION_MLS) {
printk(KERN_ERR "security policydb version %d (MLS) " printk(KERN_ERR "SELinux: security policydb version %d "
"not backwards compatible\n", p->policyvers); "(MLS) not backwards compatible\n",
p->policyvers);
goto bad; goto bad;
} }
} else { } else {
if (ss_initialized && selinux_mls_enabled) { if (ss_initialized && selinux_mls_enabled) {
printk(KERN_ERR "Cannot switch between MLS and non-MLS " printk(KERN_ERR "SELinux: Cannot switch between MLS and"
"policies\n"); " non-MLS policies\n");
goto bad; goto bad;
} }
} }
...@@ -1633,11 +1632,10 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1633,11 +1632,10 @@ int policydb_read(struct policydb *p, void *fp)
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
} }
if (ltr) { if (ltr)
ltr->next = tr; ltr->next = tr;
} else { else
p->role_tr = tr; p->role_tr = tr;
}
rc = next_entry(buf, fp, sizeof(u32)*3); rc = next_entry(buf, fp, sizeof(u32)*3);
if (rc < 0) if (rc < 0)
goto bad; goto bad;
...@@ -1664,11 +1662,10 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1664,11 +1662,10 @@ int policydb_read(struct policydb *p, void *fp)
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
} }
if (lra) { if (lra)
lra->next = ra; lra->next = ra;
} else { else
p->role_allow = ra; p->role_allow = ra;
}
rc = next_entry(buf, fp, sizeof(u32)*2); rc = next_entry(buf, fp, sizeof(u32)*2);
if (rc < 0) if (rc < 0)
goto bad; goto bad;
...@@ -1702,11 +1699,10 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1702,11 +1699,10 @@ int policydb_read(struct policydb *p, void *fp)
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
} }
if (l) { if (l)
l->next = c; l->next = c;
} else { else
p->ocontexts[i] = c; p->ocontexts[i] = c;
}
l = c; l = c;
rc = -EINVAL; rc = -EINVAL;
switch (i) { switch (i) {
...@@ -1725,7 +1721,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1725,7 +1721,7 @@ int policydb_read(struct policydb *p, void *fp)
if (rc < 0) if (rc < 0)
goto bad; goto bad;
len = le32_to_cpu(buf[0]); len = le32_to_cpu(buf[0]);
c->u.name = kmalloc(len + 1,GFP_KERNEL); c->u.name = kmalloc(len + 1, GFP_KERNEL);
if (!c->u.name) { if (!c->u.name) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1753,7 +1749,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1753,7 +1749,7 @@ int policydb_read(struct policydb *p, void *fp)
goto bad; goto bad;
break; break;
case OCON_NODE: case OCON_NODE:
rc = next_entry(buf, fp, sizeof(u32)* 2); rc = next_entry(buf, fp, sizeof(u32) * 2);
if (rc < 0) if (rc < 0)
goto bad; goto bad;
c->u.node.addr = le32_to_cpu(buf[0]); c->u.node.addr = le32_to_cpu(buf[0]);
...@@ -1770,7 +1766,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1770,7 +1766,7 @@ int policydb_read(struct policydb *p, void *fp)
if (c->v.behavior > SECURITY_FS_USE_NONE) if (c->v.behavior > SECURITY_FS_USE_NONE)
goto bad; goto bad;
len = le32_to_cpu(buf[1]); len = le32_to_cpu(buf[1]);
c->u.name = kmalloc(len + 1,GFP_KERNEL); c->u.name = kmalloc(len + 1, GFP_KERNEL);
if (!c->u.name) { if (!c->u.name) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad; goto bad;
...@@ -1818,7 +1814,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1818,7 +1814,7 @@ int policydb_read(struct policydb *p, void *fp)
goto bad; goto bad;
} }
newgenfs->fstype = kmalloc(len + 1,GFP_KERNEL); newgenfs->fstype = kmalloc(len + 1, GFP_KERNEL);
if (!newgenfs->fstype) { if (!newgenfs->fstype) {
rc = -ENOMEM; rc = -ENOMEM;
kfree(newgenfs); kfree(newgenfs);
...@@ -1864,7 +1860,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1864,7 +1860,7 @@ int policydb_read(struct policydb *p, void *fp)
goto bad; goto bad;
} }
newc->u.name = kmalloc(len + 1,GFP_KERNEL); newc->u.name = kmalloc(len + 1, GFP_KERNEL);
if (!newc->u.name) { if (!newc->u.name) {
rc = -ENOMEM; rc = -ENOMEM;
goto bad_newc; goto bad_newc;
...@@ -1968,7 +1964,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1968,7 +1964,7 @@ int policydb_read(struct policydb *p, void *fp)
out: out:
return rc; return rc;
bad_newc: bad_newc:
ocontext_destroy(newc,OCON_FSUSE); ocontext_destroy(newc, OCON_FSUSE);
bad: bad:
if (!rc) if (!rc)
rc = -EINVAL; rc = -EINVAL;
......
...@@ -82,7 +82,7 @@ static DEFINE_MUTEX(load_mutex); ...@@ -82,7 +82,7 @@ static DEFINE_MUTEX(load_mutex);
static struct sidtab sidtab; static struct sidtab sidtab;
struct policydb policydb; struct policydb policydb;
int ss_initialized = 0; int ss_initialized;
/* /*
* The largest sequence number that has been used when * The largest sequence number that has been used when
...@@ -90,7 +90,7 @@ int ss_initialized = 0; ...@@ -90,7 +90,7 @@ int ss_initialized = 0;
* The sequence number only changes when a policy change * The sequence number only changes when a policy change
* occurs. * occurs.
*/ */
static u32 latest_granting = 0; static u32 latest_granting;
/* Forward declaration. */ /* Forward declaration. */
static int context_struct_to_string(struct context *context, char **scontext, static int context_struct_to_string(struct context *context, char **scontext,
...@@ -163,10 +163,10 @@ static int constraint_expr_eval(struct context *scontext, ...@@ -163,10 +163,10 @@ static int constraint_expr_eval(struct context *scontext,
val1 - 1); val1 - 1);
continue; continue;
case CEXPR_INCOMP: case CEXPR_INCOMP:
s[++sp] = ( !ebitmap_get_bit(&r1->dominates, s[++sp] = (!ebitmap_get_bit(&r1->dominates,
val2 - 1) && val2 - 1) &&
!ebitmap_get_bit(&r2->dominates, !ebitmap_get_bit(&r2->dominates,
val1 - 1) ); val1 - 1));
continue; continue;
default: default:
break; break;
...@@ -415,7 +415,8 @@ static int context_struct_compute_av(struct context *scontext, ...@@ -415,7 +415,8 @@ static int context_struct_compute_av(struct context *scontext,
return 0; return 0;
inval_class: inval_class:
printk(KERN_ERR "%s: unrecognized class %d\n", __func__, tclass); printk(KERN_ERR "SELinux: %s: unrecognized class %d\n", __func__,
tclass);
return -EINVAL; return -EINVAL;
} }
...@@ -499,8 +500,8 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid, ...@@ -499,8 +500,8 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
tclass = SECCLASS_NETLINK_SOCKET; tclass = SECCLASS_NETLINK_SOCKET;
if (!tclass || tclass > policydb.p_classes.nprim) { if (!tclass || tclass > policydb.p_classes.nprim) {
printk(KERN_ERR "security_validate_transition: " printk(KERN_ERR "SELinux: %s: unrecognized class %d\n",
"unrecognized class %d\n", tclass); __func__, tclass);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
...@@ -508,24 +509,24 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid, ...@@ -508,24 +509,24 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
ocontext = sidtab_search(&sidtab, oldsid); ocontext = sidtab_search(&sidtab, oldsid);
if (!ocontext) { if (!ocontext) {
printk(KERN_ERR "security_validate_transition: " printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
" unrecognized SID %d\n", oldsid); __func__, oldsid);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
ncontext = sidtab_search(&sidtab, newsid); ncontext = sidtab_search(&sidtab, newsid);
if (!ncontext) { if (!ncontext) {
printk(KERN_ERR "security_validate_transition: " printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
" unrecognized SID %d\n", newsid); __func__, newsid);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
tcontext = sidtab_search(&sidtab, tasksid); tcontext = sidtab_search(&sidtab, tasksid);
if (!tcontext) { if (!tcontext) {
printk(KERN_ERR "security_validate_transition: " printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
" unrecognized SID %d\n", tasksid); __func__, tasksid);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
...@@ -581,15 +582,15 @@ int security_compute_av(u32 ssid, ...@@ -581,15 +582,15 @@ int security_compute_av(u32 ssid,
scontext = sidtab_search(&sidtab, ssid); scontext = sidtab_search(&sidtab, ssid);
if (!scontext) { if (!scontext) {
printk(KERN_ERR "security_compute_av: unrecognized SID %d\n", printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
ssid); __func__, ssid);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
tcontext = sidtab_search(&sidtab, tsid); tcontext = sidtab_search(&sidtab, tsid);
if (!tcontext) { if (!tcontext) {
printk(KERN_ERR "security_compute_av: unrecognized SID %d\n", printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
tsid); __func__, tsid);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
...@@ -623,9 +624,8 @@ static int context_struct_to_string(struct context *context, char **scontext, u3 ...@@ -623,9 +624,8 @@ static int context_struct_to_string(struct context *context, char **scontext, u3
/* Allocate space for the context; caller must free this space. */ /* Allocate space for the context; caller must free this space. */
scontextp = kmalloc(*scontext_len, GFP_ATOMIC); scontextp = kmalloc(*scontext_len, GFP_ATOMIC);
if (!scontextp) { if (!scontextp)
return -ENOMEM; return -ENOMEM;
}
*scontext = scontextp; *scontext = scontextp;
/* /*
...@@ -678,7 +678,7 @@ int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len) ...@@ -678,7 +678,7 @@ int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len)
char *scontextp; char *scontextp;
*scontext_len = strlen(initial_sid_to_string[sid]) + 1; *scontext_len = strlen(initial_sid_to_string[sid]) + 1;
scontextp = kmalloc(*scontext_len,GFP_ATOMIC); scontextp = kmalloc(*scontext_len, GFP_ATOMIC);
if (!scontextp) { if (!scontextp) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
...@@ -687,16 +687,16 @@ int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len) ...@@ -687,16 +687,16 @@ int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len)
*scontext = scontextp; *scontext = scontextp;
goto out; goto out;
} }
printk(KERN_ERR "security_sid_to_context: called before initial " printk(KERN_ERR "SELinux: %s: called before initial "
"load_policy on unknown SID %d\n", sid); "load_policy on unknown SID %d\n", __func__, sid);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
} }
POLICY_RDLOCK; POLICY_RDLOCK;
context = sidtab_search(&sidtab, sid); context = sidtab_search(&sidtab, sid);
if (!context) { if (!context) {
printk(KERN_ERR "security_sid_to_context: unrecognized SID " printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
"%d\n", sid); __func__, sid);
rc = -EINVAL; rc = -EINVAL;
goto out_unlock; goto out_unlock;
} }
...@@ -926,15 +926,15 @@ static int security_compute_sid(u32 ssid, ...@@ -926,15 +926,15 @@ static int security_compute_sid(u32 ssid,
scontext = sidtab_search(&sidtab, ssid); scontext = sidtab_search(&sidtab, ssid);
if (!scontext) { if (!scontext) {
printk(KERN_ERR "security_compute_sid: unrecognized SID %d\n", printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
ssid); __func__, ssid);
rc = -EINVAL; rc = -EINVAL;
goto out_unlock; goto out_unlock;
} }
tcontext = sidtab_search(&sidtab, tsid); tcontext = sidtab_search(&sidtab, tsid);
if (!tcontext) { if (!tcontext) {
printk(KERN_ERR "security_compute_sid: unrecognized SID %d\n", printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
tsid); __func__, tsid);
rc = -EINVAL; rc = -EINVAL;
goto out_unlock; goto out_unlock;
} }
...@@ -974,7 +974,7 @@ static int security_compute_sid(u32 ssid, ...@@ -974,7 +974,7 @@ static int security_compute_sid(u32 ssid,
avdatum = avtab_search(&policydb.te_avtab, &avkey); avdatum = avtab_search(&policydb.te_avtab, &avkey);
/* If no permanent rule, also check for enabled conditional rules */ /* If no permanent rule, also check for enabled conditional rules */
if(!avdatum) { if (!avdatum) {
node = avtab_search_node(&policydb.te_cond_avtab, &avkey); node = avtab_search_node(&policydb.te_cond_avtab, &avkey);
for (; node != NULL; node = avtab_search_node_next(node, specified)) { for (; node != NULL; node = avtab_search_node_next(node, specified)) {
if (node->key.specified & AVTAB_ENABLED) { if (node->key.specified & AVTAB_ENABLED) {
...@@ -1289,25 +1289,22 @@ static int convert_context(u32 key, ...@@ -1289,25 +1289,22 @@ static int convert_context(u32 key,
/* Convert the user. */ /* Convert the user. */
usrdatum = hashtab_search(args->newp->p_users.table, usrdatum = hashtab_search(args->newp->p_users.table,
args->oldp->p_user_val_to_name[c->user - 1]); args->oldp->p_user_val_to_name[c->user - 1]);
if (!usrdatum) { if (!usrdatum)
goto bad; goto bad;
}
c->user = usrdatum->value; c->user = usrdatum->value;
/* Convert the role. */ /* Convert the role. */
role = hashtab_search(args->newp->p_roles.table, role = hashtab_search(args->newp->p_roles.table,
args->oldp->p_role_val_to_name[c->role - 1]); args->oldp->p_role_val_to_name[c->role - 1]);
if (!role) { if (!role)
goto bad; goto bad;
}
c->role = role->value; c->role = role->value;
/* Convert the type. */ /* Convert the type. */
typdatum = hashtab_search(args->newp->p_types.table, typdatum = hashtab_search(args->newp->p_types.table,
args->oldp->p_type_val_to_name[c->type - 1]); args->oldp->p_type_val_to_name[c->type - 1]);
if (!typdatum) { if (!typdatum)
goto bad; goto bad;
}
c->type = typdatum->value; c->type = typdatum->value;
rc = mls_convert_context(args->oldp, args->newp, c); rc = mls_convert_context(args->oldp, args->newp, c);
...@@ -1556,8 +1553,8 @@ static int match_ipv6_addrmask(u32 *input, u32 *addr, u32 *mask) ...@@ -1556,8 +1553,8 @@ static int match_ipv6_addrmask(u32 *input, u32 *addr, u32 *mask)
{ {
int i, fail = 0; int i, fail = 0;
for(i = 0; i < 4; i++) for (i = 0; i < 4; i++)
if(addr[i] != (input[i] & mask[i])) { if (addr[i] != (input[i] & mask[i])) {
fail = 1; fail = 1;
break; break;
} }
...@@ -1881,7 +1878,7 @@ int security_get_bools(int *len, char ***names, int **values) ...@@ -1881,7 +1878,7 @@ int security_get_bools(int *len, char ***names, int **values)
goto out; goto out;
} }
*names = kcalloc(*len, sizeof(char*), GFP_ATOMIC); *names = kcalloc(*len, sizeof(char *), GFP_ATOMIC);
if (!*names) if (!*names)
goto err; goto err;
...@@ -1938,12 +1935,11 @@ int security_set_bools(int len, int *values) ...@@ -1938,12 +1935,11 @@ int security_set_bools(int len, int *values)
audit_get_loginuid(current), audit_get_loginuid(current),
audit_get_sessionid(current)); audit_get_sessionid(current));
} }
if (values[i]) { if (values[i])
policydb.bool_val_to_struct[i]->state = 1; policydb.bool_val_to_struct[i]->state = 1;
} else { else
policydb.bool_val_to_struct[i]->state = 0; policydb.bool_val_to_struct[i]->state = 0;
} }
}
for (cur = policydb.cond_list; cur != NULL; cur = cur->next) { for (cur = policydb.cond_list; cur != NULL; cur = cur->next) {
rc = evaluate_cond_node(&policydb, cur); rc = evaluate_cond_node(&policydb, cur);
...@@ -2036,16 +2032,16 @@ int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid) ...@@ -2036,16 +2032,16 @@ int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid)
POLICY_RDLOCK; POLICY_RDLOCK;
context1 = sidtab_search(&sidtab, sid); context1 = sidtab_search(&sidtab, sid);
if (!context1) { if (!context1) {
printk(KERN_ERR "security_sid_mls_copy: unrecognized SID " printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
"%d\n", sid); __func__, sid);
rc = -EINVAL; rc = -EINVAL;
goto out_unlock; goto out_unlock;
} }
context2 = sidtab_search(&sidtab, mls_sid); context2 = sidtab_search(&sidtab, mls_sid);
if (!context2) { if (!context2) {
printk(KERN_ERR "security_sid_mls_copy: unrecognized SID " printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
"%d\n", mls_sid); __func__, mls_sid);
rc = -EINVAL; rc = -EINVAL;
goto out_unlock; goto out_unlock;
} }
...@@ -2136,17 +2132,15 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type, ...@@ -2136,17 +2132,15 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
nlbl_ctx = sidtab_search(&sidtab, nlbl_sid); nlbl_ctx = sidtab_search(&sidtab, nlbl_sid);
if (!nlbl_ctx) { if (!nlbl_ctx) {
printk(KERN_ERR printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
"security_sid_mls_cmp: unrecognized SID %d\n", __func__, nlbl_sid);
nlbl_sid);
rc = -EINVAL; rc = -EINVAL;
goto out_slowpath; goto out_slowpath;
} }
xfrm_ctx = sidtab_search(&sidtab, xfrm_sid); xfrm_ctx = sidtab_search(&sidtab, xfrm_sid);
if (!xfrm_ctx) { if (!xfrm_ctx) {
printk(KERN_ERR printk(KERN_ERR "SELinux: %s: unrecognized SID %d\n",
"security_sid_mls_cmp: unrecognized SID %d\n", __func__, xfrm_sid);
xfrm_sid);
rc = -EINVAL; rc = -EINVAL;
goto out_slowpath; goto out_slowpath;
} }
...@@ -2226,7 +2220,7 @@ int security_get_permissions(char *class, char ***perms, int *nperms) ...@@ -2226,7 +2220,7 @@ int security_get_permissions(char *class, char ***perms, int *nperms)
match = hashtab_search(policydb.p_classes.table, class); match = hashtab_search(policydb.p_classes.table, class);
if (!match) { if (!match) {
printk(KERN_ERR "%s: unrecognized class %s\n", printk(KERN_ERR "SELinux: %s: unrecognized class %s\n",
__func__, class); __func__, class);
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
......
...@@ -156,12 +156,10 @@ void sidtab_map_remove_on_error(struct sidtab *s, ...@@ -156,12 +156,10 @@ void sidtab_map_remove_on_error(struct sidtab *s,
while (cur != NULL) { while (cur != NULL) {
ret = apply(cur->sid, &cur->context, args); ret = apply(cur->sid, &cur->context, args);
if (ret) { if (ret) {
if (last) { if (last)
last->next = cur->next; last->next = cur->next;
} else { else
s->htable[i] = cur->next; s->htable[i] = cur->next;
}
temp = cur; temp = cur;
cur = cur->next; cur = cur->next;
context_destroy(&temp->context); context_destroy(&temp->context);
......
...@@ -180,8 +180,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall) ...@@ -180,8 +180,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
if (!ckall) if (!ckall)
break; break;
} } else if (*sid != ctx->ctx_sid)
else if (*sid != ctx->ctx_sid)
return -EINVAL; return -EINVAL;
} }
} }
...@@ -326,7 +325,6 @@ int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, ...@@ -326,7 +325,6 @@ int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
*/ */
void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx) void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
{ {
if (ctx)
kfree(ctx); kfree(ctx);
} }
...@@ -372,7 +370,6 @@ int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *uct ...@@ -372,7 +370,6 @@ int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *uct
void selinux_xfrm_state_free(struct xfrm_state *x) void selinux_xfrm_state_free(struct xfrm_state *x)
{ {
struct xfrm_sec_ctx *ctx = x->security; struct xfrm_sec_ctx *ctx = x->security;
if (ctx)
kfree(ctx); kfree(ctx);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment