Skip to content

Commit 7c733c2

Browse files
cgzonesjwcart2
authored andcommitted
libsepol: validate MLS levels
Validate the level map of the policy to ensure no level refers to a non existent category. READ of size 8 at 0x602000000c58 thread T0 #0 0x568d2c in cats_ebitmap_len ./libsepol/src/kernel_to_conf.c:1003:14 #1 0x568d2c in cats_ebitmap_to_str ./libsepol/src/kernel_to_conf.c:1038:19 SELinuxProject#2 0x55e371 in write_level_rules_to_conf ./libsepol/src/kernel_to_conf.c:1106:11 SELinuxProject#3 0x55e371 in write_mls_rules_to_conf ./libsepol/src/kernel_to_conf.c:1140:7 SELinuxProject#4 0x55adb1 in sepol_kernel_policydb_to_conf ./libsepol/src/kernel_to_conf.c:3103:7 SELinuxProject#5 0x55a34f in LLVMFuzzerTestOneInput ./libsepol/fuzz/binpolicy-fuzzer.c:38:9 SELinuxProject#6 0x45aed3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) fuzzer.o SELinuxProject#7 0x446a12 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) fuzzer.o SELinuxProject#8 0x44c93b in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) fuzzer.o SELinuxProject#9 0x475dd2 in main (./out/binpolicy-fuzzer+0x475dd2) SELinuxProject#10 0x7f741d0d67ec in __libc_start_main csu/../csu/libc-start.c:332:16 SELinuxProject#11 0x423689 in _start (./out/binpolicy-fuzzer+0x423689) Signed-off-by: Christian Göttsche <[email protected]>
1 parent e8b2f5b commit 7c733c2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

libsepol/src/policydb_validate.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,27 @@ static int validate_mls_semantic_range(mls_semantic_range_t *range, validate_t *
319319
return -1;
320320
}
321321

322+
static int validate_mls_level(mls_level_t *level, validate_t *sens, validate_t *cats)
323+
{
324+
if (validate_value(level->sens, sens))
325+
goto bad;
326+
if (validate_ebitmap(&level->cat, cats))
327+
goto bad;
328+
329+
return 0;
330+
331+
bad:
332+
return -1;
333+
}
334+
335+
static int validate_level_datum(__attribute__ ((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
336+
{
337+
level_datum_t *level = d;
338+
validate_t *flavors = args;
339+
340+
return validate_mls_level(level->level, &flavors[SYM_LEVELS], &flavors[SYM_CATS]);
341+
}
342+
322343
static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, validate_t flavors[])
323344
{
324345
if (validate_value(user->s.value, &flavors[SYM_USERS]))
@@ -399,6 +420,9 @@ static int validate_datum_array_entries(sepol_handle_t *handle, policydb_t *p, v
399420
if (hashtab_map(p->p_users.table, validate_user_datum_wrapper, &margs))
400421
goto bad;
401422

423+
if (p->mls && hashtab_map(p->p_levels.table, validate_level_datum, flavors))
424+
goto bad;
425+
402426
return 0;
403427

404428
bad:

0 commit comments

Comments
 (0)