Skip to contentSkip to conversation

libsepol: Turn assert into error in type_set_expand()

PATCH Superseded James Carter 2 participants 3 messages Jul 29 – Jul 30 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Turn assert into error in type_set_expand()

The assertion in function type_set_expand() can only be violated by a malformed policy. Since it is called before the policy has been validated just return an error.

---
 libsepol/src/expand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/expand.c +2 -2
index 8d7fe519..19b5fdcc 100644
@@ -2827,8 +2827,8 @@ int type_set_expand(type_set_t *set, ebitmap_t *t, policydb_t *p,
 		for (i = 0; i < p->p_types.nprim; i++) {
 			if (p->type_val_to_struct[i] &&
 			    p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
-				assert(!ebitmap_get_bit(t, i));
-				continue;
+				if (ebitmap_get_bit(t, i))
+					goto err_neg;
 			}
 			if (ebitmap_get_bit(t, i)) {
 				if (ebitmap_set_bit(t, i, 0))
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 15 lines · James Carter

The assertion in function type_set_expand() can only be violated by a malformed policy. Since it is called before the policy has been validated just return an error.

---
 libsepol/src/expand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/expand.c +0 -0
index 8d7fe519..19b5fdcc 100644

libsepol/src/expand.c int type_set_expand(type_set_t *set, ebitmap_t *t, policydb_t *p, · line 2831

Quoted 7 lines
libsepol/src/expand.c +2 -2
@@ -2827,8 +2827,8 @@ int type_set_expand(type_set_t *set, ebitmap_t *t, policydb_t *p,
                for (i = 0; i < p->p_types.nprim; i++) {
                        if (p->type_val_to_struct[i] &&
                            p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
-                               assert(!ebitmap_get_bit(t, i));
-                               continue;
+                               if (ebitmap_get_bit(t, i))
+                                       goto err_neg;

Why did you drop the continue; in the non-error path?

Quoted 6 lines
libsepol/src/expand.c +0 -1
                        }
                        if (ebitmap_get_bit(t, i)) {
                                if (ebitmap_set_bit(t, i, 0))
--

2.55.0

#2 lore raw
Quoted 12 lines · Stephen Smalley
Quoted 10 lines · James Carter

The assertion in function type_set_expand() can only be violated by a malformed policy. Since it is called before the policy has been validated just return an error.

---
 libsepol/src/expand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

libsepol/src/expand.c int type_set_expand(type_set_t *set, ebitmap_t *t, policydb_t *p, · line 2831

Quoted 12 lines
libsepol/src/expand.c +2 -2
index 8d7fe519..19b5fdcc 100644
@@ -2827,8 +2827,8 @@ int type_set_expand(type_set_t *set, ebitmap_t *t, policydb_t *p,
                for (i = 0; i < p->p_types.nprim; i++) {
                        if (p->type_val_to_struct[i] &&
                            p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
-                               assert(!ebitmap_get_bit(t, i));
-                               continue;
+                               if (ebitmap_get_bit(t, i))
+                                       goto err_neg;

Why did you drop the continue; in the non-error path?

That was a mistake. I'll send out a correction.
Jim

Quoted 7 lines
Quoted 7 lines
libsepol/src/expand.c +0 -1
                        }
                        if (ebitmap_get_bit(t, i)) {
                                if (ebitmap_set_bit(t, i, 0))
--

2.55.0