Skip to content

Commit

Permalink
libsepol: validate MLS levels
Browse files Browse the repository at this point in the history
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
    #2 0x55e371 in write_level_rules_to_conf ./libsepol/src/kernel_to_conf.c:1106:11
    #3 0x55e371 in write_mls_rules_to_conf ./libsepol/src/kernel_to_conf.c:1140:7
    #4 0x55adb1 in sepol_kernel_policydb_to_conf ./libsepol/src/kernel_to_conf.c:3103:7
    #5 0x55a34f in LLVMFuzzerTestOneInput ./libsepol/fuzz/binpolicy-fuzzer.c:38:9
    #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]>
  • Loading branch information
cgzones authored and jwcart2 committed Dec 15, 2021
1 parent e2e60d9 commit 8fdb3eb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libsepol/src/policydb_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,27 @@ static int validate_mls_semantic_range(mls_semantic_range_t *range, validate_t *
return -1;
}

static int validate_mls_level(mls_level_t *level, validate_t *sens, validate_t *cats)
{
if (validate_value(level->sens, sens))
goto bad;
if (validate_ebitmap(&level->cat, cats))
goto bad;

return 0;

bad:
return -1;
}

static int validate_level_datum(__attribute__ ((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
level_datum_t *level = d;
validate_t *flavors = args;

return validate_mls_level(level->level, &flavors[SYM_LEVELS], &flavors[SYM_CATS]);
}

static int validate_user_datum(sepol_handle_t *handle, user_datum_t *user, validate_t flavors[])
{
if (validate_value(user->s.value, &flavors[SYM_USERS]))
Expand Down Expand Up @@ -399,6 +420,9 @@ static int validate_datum_array_entries(sepol_handle_t *handle, policydb_t *p, v
if (hashtab_map(p->p_users.table, validate_user_datum_wrapper, &margs))
goto bad;

if (p->mls && hashtab_map(p->p_levels.table, validate_level_datum, flavors))
goto bad;

return 0;

bad:
Expand Down

0 comments on commit 8fdb3eb

Please sign in to comment.