Skip to contentSkip to conversation

libsepol/fuzz: Validate output of expand_module() before proceeding

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/fuzz: Validate output of expand_module() before proceeding

When creating actual policies the output of expand_module() is written to disk. Converting that policy to CIL or performing other operations on it will require it to be read by policydb_read() which calls policydb_validate(). The fuzzer is not validating the policy, so it is reporting bugs that would be caught by validation.

Have the fuzzer call policydb_validate() after expanding modules so it will not report bugs that are caught by validation.

---
 libsepol/fuzz/binpolicy-fuzzer.c | 3 +++
 1 file changed, 3 insertions(+)
libsepol/fuzz/binpolicy-fuzzer.c +3 -0
index 017f996e..f2379175 100644
@@ -88,6 +88,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
 					  /*check_assertions=*/0))
 				goto exit;
 
+			if (policydb_validate(NULL, &out))
+				goto exit;
+
 			(void)check_assertions(
 				NULL, &out, out.global->branch_list->avrules);
 			(void)hierarchy_check_constraints(NULL, &out);
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · James Carter

When creating actual policies the output of expand_module() is written to disk. Converting that policy to CIL or performing other operations on it will require it to be read by policydb_read() which calls policydb_validate(). The fuzzer is not validating the policy, so it is reporting bugs that would be caught by validation.

Have the fuzzer call policydb_validate() after expanding modules so it will not report bugs that are caught by validation.

Quoted 21 lines
---
 libsepol/fuzz/binpolicy-fuzzer.c | 3 +++
 1 file changed, 3 insertions(+)
libsepol/fuzz/binpolicy-fuzzer.c +3 -1
index 017f996e..f2379175 100644
@@ -88,6 +88,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
                                          /*check_assertions=*/0))
                                goto exit;
 
+                       if (policydb_validate(NULL, &out))
+                               goto exit;
+
                        (void)check_assertions(
                                NULL, &out, out.global->branch_list->avrules);
                        (void)hierarchy_check_constraints(NULL, &out);
--

2.55.0

maintainer
#2 lore raw
Quoted 9 lines · Stephen Smalley
Quoted 7 lines · James Carter

When creating actual policies the output of expand_module() is written to disk. Converting that policy to CIL or performing other operations on it will require it to be read by policydb_read() which calls policydb_validate(). The fuzzer is not validating the policy, so it is reporting bugs that would be caught by validation.

Quoted 6 lines
Quoted 4 lines

Have the fuzzer call policydb_validate() after expanding modules so it will not report bugs that are caught by validation.

Merged.