selinux: fix error codes in cond_read_bool()
Subsystems (2)
PATCH 6/7 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.
security/selinux/ss/conditional.c +6 -3
@@ -223,7 +223,7 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) booldatum =kzalloc (sizeof (struct cond_bool_datum ),GFP_KERNEL );if (!booldatum) -return -1 ; +return -ENOMEM ; rc =next_entry (buf, fp,sizeof buf);if (rc <0 )
@@ -232,11 +232,13 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) booldatum->value =le32_to_cpu (buf[0 ]); booldatum->state =le32_to_cpu (buf[1 ]); + rc = -EINVAL ;if (!bool_isvalid (booldatum)) goto err; len =le32_to_cpu (buf[2 ]); + rc = -ENOMEM ; key =kmalloc (len +1 ,GFP_KERNEL );if (!key) goto err;
@@ -244,13 +246,14 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)if (rc <0 ) goto err; key[len] ='\0' ; -if (hashtab_insert (h, key, booldatum)) + rc =hashtab_insert (h, key, booldatum); +if (rc <0 ) goto err;return 0 ; err:cond_destroy_bool (key, booldatum,NULL ); -return -1 ; +return rc; }struct cond_insertf_data {
Quoted 15 lines · Dan Carpenter
The original code always returned -1 (
-EPERM) on error. The new code returns either-ENOMEM, or-EINVALor it propagates the error codes from lower level functionsnext_entry()orhashtab_insert().
next_entry()returns-EINVAL.hashtab_insert()returns-EINVAL,-EEXIST, or-ENOMEM.Signed-off-by Dan Carpenter <[email protected]>security/selinux/ss/conditional.c +0
-0
security/selinux/ss/conditional.c int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) · line 250
Quoted 6 lines
security/selinux/ss/conditional.c +2
-1@@ -244,13 +246,14 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) if (rc < 0) goto err; key[len] = '\0'; - if (hashtab_insert(h, key, booldatum)) + rc = hashtab_insert(h, key, booldatum); + if (rc < 0)
If James wants to pull this one I'm ok with it, but I much prefer if (rc)
-Eric
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line · Eric Paris
If James wants to pull this one I'm ok with it, but I much prefer if (rc)
I'd prefer to see them resent with your feedback incorporated.
Signature · 2 lines
James Morris <[email protected]>