Skip to content

Commit

Permalink
libsepol: validate categories
Browse files Browse the repository at this point in the history
Check all categories have valid values, especially important for
aliases.

        ==7888==ERROR: AddressSanitizer: SEGV on unknown address 0x602000400710 (pc 0x00000055debc bp 0x7ffe0ff2a9d0 sp 0x7ffe0ff2a8e0 T0)
        ==7888==The signal is caused by a READ memory access.
        #0 0x55debc in write_category_rules_to_conf ./libsepol/src/kernel_to_conf.c:946:9
        #1 0x55debc in write_mls_rules_to_conf ./libsepol/src/kernel_to_conf.c:1137:7
        #2 0x55adb1 in sepol_kernel_policydb_to_conf ./libsepol/src/kernel_to_conf.c:3106:7
        #3 0x55a34f in LLVMFuzzerTestOneInput ./libsepol/fuzz/binpolicy-fuzzer.c:37:9
        #4 0x45aed3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) fuzzer.o
        #5 0x446a12 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) fuzzer.o
        #6 0x44c93b in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) fuzzer.o
        SELinuxProject#7 0x475dd2 in main (./out/binpolicy-fuzzer+0x475dd2)
        SELinuxProject#8 0x7fe80ccaf7ec in __libc_start_main csu/../csu/libc-start.c:332:16
        SELinuxProject#9 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 80b9441 commit 8a7215c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions libsepol/src/policydb_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ static int validate_datum_array_gaps(sepol_handle_t *handle, policydb_t *p, vali
return -1;
}

static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datum_t d, void *args)
{
symtab_datum_t *s = d;
uint32_t *nprim = (uint32_t *)args;

return !value_isvalid(s->value, *nprim);
}

static int validate_datum_array_entries(sepol_handle_t *handle, policydb_t *p, validate_t flavors[])
{
map_arg_t margs = { flavors, handle, p->mls };
Expand All @@ -507,6 +515,9 @@ static int validate_datum_array_entries(sepol_handle_t *handle, policydb_t *p, v
if (p->mls && hashtab_map(p->p_levels.table, validate_level_datum, flavors))
goto bad;

if (hashtab_map(p->p_cats.table, validate_datum, &flavors[SYM_CATS]))
goto bad;

return 0;

bad:
Expand Down Expand Up @@ -905,14 +916,6 @@ static int validate_filename_trans_rules(sepol_handle_t *handle, filename_trans_
return -1;
}

static int validate_datum(__attribute__ ((unused))hashtab_key_t k, hashtab_datum_t d, void *args)
{
symtab_datum_t *s = d;
uint32_t *nprim = (uint32_t *)args;

return !value_isvalid(s->value, *nprim);
}

static int validate_symtabs(sepol_handle_t *handle, symtab_t symtabs[], validate_t flavors[])
{
unsigned int i;
Expand Down

0 comments on commit 8a7215c

Please sign in to comment.