Skip to contentSkip to conversation

selinux: fix error codes in cond_read_bool()

PATCH Superseded Dan Carpenter 3 participants 3 messages Jun 7, 2010 – Jun 8, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 7447be0..dc5db55 100644
@@ -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 {
#1 lore raw
Quoted 15 lines · Dan Carpenter

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 +0 -0
index 7447be0..dc5db55 100644

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