mirror of
https://github.com/fail0verflow/switch-linux.git
synced 2025-05-04 02:34:21 -04:00
selinux: fix error codes in cond_read_bool()
The original code always returned -1 (-EPERM) on error. The new code returns either -ENOMEM, or -EINVAL or it propagates the error codes from lower level functions next_entry() or hashtab_insert(). next_entry() returns -EINVAL. hashtab_insert() returns -EINVAL, -EEXIST, or -ENOMEM. Signed-off-by: Dan Carpenter <error27@gmail.com> Acked-by: Stephen D. Smalley <sds@tycho.nsa.gov> Signed-off-by: James Morris <jmorris@namei.org>
This commit is contained in:
parent
38184c5222
commit
338437f6a0
1 changed files with 8 additions and 5 deletions
|
@ -223,34 +223,37 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
|
||||||
|
|
||||||
booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL);
|
booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL);
|
||||||
if (!booldatum)
|
if (!booldatum)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
rc = next_entry(buf, fp, sizeof buf);
|
rc = next_entry(buf, fp, sizeof buf);
|
||||||
if (rc < 0)
|
if (rc)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
booldatum->value = le32_to_cpu(buf[0]);
|
booldatum->value = le32_to_cpu(buf[0]);
|
||||||
booldatum->state = le32_to_cpu(buf[1]);
|
booldatum->state = le32_to_cpu(buf[1]);
|
||||||
|
|
||||||
|
rc = -EINVAL;
|
||||||
if (!bool_isvalid(booldatum))
|
if (!bool_isvalid(booldatum))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
len = le32_to_cpu(buf[2]);
|
len = le32_to_cpu(buf[2]);
|
||||||
|
|
||||||
|
rc = -ENOMEM;
|
||||||
key = kmalloc(len + 1, GFP_KERNEL);
|
key = kmalloc(len + 1, GFP_KERNEL);
|
||||||
if (!key)
|
if (!key)
|
||||||
goto err;
|
goto err;
|
||||||
rc = next_entry(key, fp, len);
|
rc = next_entry(key, fp, len);
|
||||||
if (rc < 0)
|
if (rc)
|
||||||
goto err;
|
goto err;
|
||||||
key[len] = '\0';
|
key[len] = '\0';
|
||||||
if (hashtab_insert(h, key, booldatum))
|
rc = hashtab_insert(h, key, booldatum);
|
||||||
|
if (rc)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
err:
|
||||||
cond_destroy_bool(key, booldatum, NULL);
|
cond_destroy_bool(key, booldatum, NULL);
|
||||||
return -1;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cond_insertf_data {
|
struct cond_insertf_data {
|
||||||
|
|
Loading…
Add table
Reference in a new issue