Commit f6444489 authored by Stephen D. Smalley's avatar Stephen D. Smalley Committed by Linus Torvalds

[PATCH] SELinux: fix error handling code for policy load

This patch fixes several bugs in the error handling code for SELinux policy
loading that were introduced by my earlier patch to eliminate unaligned
accesses by that code.
Signed-off-by: default avatarStephen Smalley <sds@epoch.ncsc.mil>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d61a371b
......@@ -386,8 +386,10 @@ int avtab_read(struct avtab *a, void *fp, u32 config)
goto bad;
}
for (i = 0; i < nel; i++) {
if (avtab_read_item(fp, &avdatum, &avkey))
if (avtab_read_item(fp, &avdatum, &avkey)) {
rc = -EINVAL;
goto bad;
}
rc = avtab_insert(a, &avkey, &avdatum);
if (rc) {
if (rc == -ENOMEM)
......
......@@ -237,7 +237,7 @@ void ebitmap_destroy(struct ebitmap *e)
int ebitmap_read(struct ebitmap *e, void *fp)
{
int rc = -EINVAL;
int rc;
struct ebitmap_node *n, *l;
u32 buf[3], mapsize, count, i;
u64 map;
......@@ -256,7 +256,7 @@ int ebitmap_read(struct ebitmap *e, void *fp)
printk(KERN_ERR "security: ebitmap: map size %u does not "
"match my size %Zd (high bit was %d)\n", mapsize,
MAPSIZE, e->highbit);
goto out;
goto bad;
}
if (!e->highbit) {
e->node = NULL;
......@@ -329,6 +329,8 @@ int ebitmap_read(struct ebitmap *e, void *fp)
bad_free:
kfree(n);
bad:
if (!rc)
rc = -EINVAL;
ebitmap_destroy(e);
goto out;
}
......@@ -832,7 +832,6 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
}
lc = NULL;
rc = -EINVAL;
for (i = 0; i < ncons; i++) {
c = kmalloc(sizeof(*c), GFP_KERNEL);
if (!c) {
......@@ -875,6 +874,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
e->attr = le32_to_cpu(buf[1]);
e->op = le32_to_cpu(buf[2]);
rc = -EINVAL;
switch (e->expr_type) {
case CEXPR_NOT:
if (depth < 0)
......@@ -915,6 +915,8 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
rc = hashtab_insert(h, key, cladatum);
if (rc)
goto bad;
rc = 0;
out:
return rc;
bad:
......@@ -1110,7 +1112,6 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto out;
rc = -EINVAL;
/* Read the magic number and string length. */
rc = next_entry(buf, fp, sizeof(u32)* 2);
if (rc < 0)
......@@ -1503,12 +1504,16 @@ int policydb_read(struct policydb *p, void *fp)
rc = mls_read_trusted(p, fp);
if (rc)
goto bad;
rc = 0;
out:
policydb_loaded_version = r_policyvers;
return rc;
bad_newc:
ocontext_destroy(newc,OCON_FSUSE);
bad:
if (!rc)
rc = -EINVAL;
policydb_destroy(p);
goto out;
}
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