Skip to contentSkip to conversation

libsepol: Tighten validation of scope index class_perm_map array

PATCH In review James Carter 2 participants 3 messages Aug 31 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Tighten validation of scope index class_perm_map array

Commit 94e9e7cf ("libsepol: Validate scope index class_perm_map array") verified that for each class in the array either the permission bitmap was empty or that it contained at least one valid permission. This was based on the belief that older compilers would set bits higher than than the highest valid permission bit when "*" or "~" was used. But this is only true for AV and constraint rules and does not apply to declarations or requires. This means that stricter validation can be done.

Fail validation if any invalid (junk) permissions are set.

---
 libsepol/src/policydb_validate.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
libsepol/src/policydb_validate.c +4 -9
index 99d27f88..1a32456f 100644
@@ -1755,21 +1755,16 @@ static int validate_scope_index(sepol_handle_t *handle,
 		for (i = 0; i < scope_index->class_perms_len; i++) {
 			const ebitmap_t *map;
 			class_datum_t *class;
-			ebitmap_node_t *node;
-			unsigned int bit = 0;
 			if (validate_value(i + 1, &flavors[SYM_CLASSES]))
 				goto bad;
 			map = &scope_index->class_perms_map[i];
 			class = p->class_val_to_struct[i];
-			/* Either there are no perms */
+			/* Having no perms is allowed */
 			if (ebitmap_is_empty(map))
 				continue;
-			/* Or at least one valid perm */
-			ebitmap_for_each_positive_bit(map, node, bit) {
-				if (bit < class->permissions.nprim)
-					break;
-			}
-			if (bit >= class->permissions.nprim)
+			/* Having junk perms is not */
+			if (ebitmap_highest_set_bit(map) >=
+			    class->permissions.nprim)
 				goto bad;
 		}
 	} else {
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · James Carter

Commit 94e9e7cf ("libsepol: Validate scope index class_perm_map array") verified that for each class in the array either the permission bitmap was empty or that it contained at least one valid permission. This was based on the belief that older compilers would set bits higher than than the highest valid permission bit when "*" or "~" was used. But this is only true for AV and constraint rules and does not apply to declarations or requires. This means that stricter validation can be done.

Quoted 3 lines

Fail validation if any invalid (junk) permissions are set.

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

Commit 94e9e7cf ("libsepol: Validate scope index class_perm_map array") verified that for each class in the array either the permission bitmap was empty or that it contained at least one valid permission. This was based on the belief that older compilers would set bits higher than than the highest valid permission bit when "*" or "~" was used. But this is only true for AV and constraint rules and does not apply to declarations or requires. This means that stricter validation can be done.

Quoted 5 lines
Quoted 3 lines

Fail validation if any invalid (junk) permissions are set.

Thanks, merged.