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) ...@@ -386,8 +386,10 @@ int avtab_read(struct avtab *a, void *fp, u32 config)
goto bad; goto bad;
} }
for (i = 0; i < nel; i++) { for (i = 0; i < nel; i++) {
if (avtab_read_item(fp, &avdatum, &avkey)) if (avtab_read_item(fp, &avdatum, &avkey)) {
rc = -EINVAL;
goto bad; goto bad;
}
rc = avtab_insert(a, &avkey, &avdatum); rc = avtab_insert(a, &avkey, &avdatum);
if (rc) { if (rc) {
if (rc == -ENOMEM) if (rc == -ENOMEM)
......
...@@ -237,7 +237,7 @@ void ebitmap_destroy(struct ebitmap *e) ...@@ -237,7 +237,7 @@ void ebitmap_destroy(struct ebitmap *e)
int ebitmap_read(struct ebitmap *e, void *fp) int ebitmap_read(struct ebitmap *e, void *fp)
{ {
int rc = -EINVAL; int rc;
struct ebitmap_node *n, *l; struct ebitmap_node *n, *l;
u32 buf[3], mapsize, count, i; u32 buf[3], mapsize, count, i;
u64 map; u64 map;
...@@ -256,7 +256,7 @@ int ebitmap_read(struct ebitmap *e, void *fp) ...@@ -256,7 +256,7 @@ int ebitmap_read(struct ebitmap *e, void *fp)
printk(KERN_ERR "security: ebitmap: map size %u does not " printk(KERN_ERR "security: ebitmap: map size %u does not "
"match my size %Zd (high bit was %d)\n", mapsize, "match my size %Zd (high bit was %d)\n", mapsize,
MAPSIZE, e->highbit); MAPSIZE, e->highbit);
goto out; goto bad;
} }
if (!e->highbit) { if (!e->highbit) {
e->node = NULL; e->node = NULL;
...@@ -329,6 +329,8 @@ int ebitmap_read(struct ebitmap *e, void *fp) ...@@ -329,6 +329,8 @@ int ebitmap_read(struct ebitmap *e, void *fp)
bad_free: bad_free:
kfree(n); kfree(n);
bad: bad:
if (!rc)
rc = -EINVAL;
ebitmap_destroy(e); ebitmap_destroy(e);
goto out; goto out;
} }
...@@ -832,7 +832,6 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -832,7 +832,6 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
} }
lc = NULL; lc = NULL;
rc = -EINVAL;
for (i = 0; i < ncons; i++) { for (i = 0; i < ncons; i++) {
c = kmalloc(sizeof(*c), GFP_KERNEL); c = kmalloc(sizeof(*c), GFP_KERNEL);
if (!c) { if (!c) {
...@@ -875,6 +874,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -875,6 +874,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
e->attr = le32_to_cpu(buf[1]); e->attr = le32_to_cpu(buf[1]);
e->op = le32_to_cpu(buf[2]); e->op = le32_to_cpu(buf[2]);
rc = -EINVAL;
switch (e->expr_type) { switch (e->expr_type) {
case CEXPR_NOT: case CEXPR_NOT:
if (depth < 0) if (depth < 0)
...@@ -915,6 +915,8 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) ...@@ -915,6 +915,8 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
rc = hashtab_insert(h, key, cladatum); rc = hashtab_insert(h, key, cladatum);
if (rc) if (rc)
goto bad; goto bad;
rc = 0;
out: out:
return rc; return rc;
bad: bad:
...@@ -1110,7 +1112,6 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1110,7 +1112,6 @@ int policydb_read(struct policydb *p, void *fp)
if (rc) if (rc)
goto out; goto out;
rc = -EINVAL;
/* 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)
...@@ -1503,12 +1504,16 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1503,12 +1504,16 @@ int policydb_read(struct policydb *p, void *fp)
rc = mls_read_trusted(p, fp); rc = mls_read_trusted(p, fp);
if (rc) if (rc)
goto bad; goto bad;
rc = 0;
out: out:
policydb_loaded_version = r_policyvers; policydb_loaded_version = r_policyvers;
return rc; return rc;
bad_newc: bad_newc:
ocontext_destroy(newc,OCON_FSUSE); ocontext_destroy(newc,OCON_FSUSE);
bad: bad:
if (!rc)
rc = -EINVAL;
policydb_destroy(p); policydb_destroy(p);
goto out; 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