Skip to content

Commit

Permalink
libsepol: validate permission count of classes
Browse files Browse the repository at this point in the history
Check a common class or a class together with its common class parent
does not have more than the supported 32 permissions.

    ==28413==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f74ec3341a3 bp 0x7ffd0b7e5030 sp 0x7ffd0b7e47e8 T0)
    ==28413==The signal is caused by a READ memory access.
    ==28413==Hint: address points to the zero page.
        #0 0x7f74ec3341a3  string/../sysdeps/x86_64/multiarch/../strchr.S:32
        #1 0x4bfc78 in strchr (./out/binpolicy-fuzzer+0x4bfc78)
        #2 0x55b7f2 in class_constraint_rules_to_strs ./libsepol/src/kernel_to_conf.c:288:7
        #3 0x55b7f2 in constraint_rules_to_strs ./libsepol/src/kernel_to_conf.c:364:9
        #4 0x55ac80 in sepol_kernel_policydb_to_conf ./libsepol/src/kernel_to_conf.c:3071: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
        #7 0x446a12 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) fuzzer.o
        #8 0x44c93b in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) fuzzer.o
        #9 0x475dd2 in main (./out/binpolicy-fuzzer+0x475dd2)
        #10 0x7f74ec2be7ec in __libc_start_main csu/../csu/libc-start.c:332:16
        #11 0x423689 in _start (./out/binpolicy-fuzzer+0x423689)

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Dec 15, 2021
1 parent fffb160 commit e39cf0a
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 @@ -211,6 +211,8 @@ static int validate_class_datum(sepol_handle_t *handle, class_datum_t *class, va
goto bad;
if (validate_constraint_nodes(handle, class->validatetrans, flavors))
goto bad;
if (class->permissions.nprim > PERM_SYMTAB_SIZE)
goto bad;

return 0;

Expand All @@ -226,6 +228,25 @@ static int validate_class_datum_wrapper(__attribute__((unused)) hashtab_key_t k,
return validate_class_datum(margs->handle, d, margs->flavors);
}

static int validate_common_datum(sepol_handle_t *handle, common_datum_t *common)
{
if (common->permissions.nprim > PERM_SYMTAB_SIZE)
goto bad;

return 0;

bad:
ERR(handle, "Invalid common class datum");
return -1;
}

static int validate_common_datum_wrapper(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
map_arg_t *margs = args;

return validate_common_datum(margs->handle, d);
}

static int validate_role_datum(sepol_handle_t *handle, role_datum_t *role, validate_t flavors[])
{
if (validate_value(role->s.value, &flavors[SYM_ROLES]))
Expand Down Expand Up @@ -425,6 +446,9 @@ static int validate_datum_array_entries(sepol_handle_t *handle, policydb_t *p, v
{
map_arg_t margs = { flavors, handle, p->mls };

if (hashtab_map(p->p_commons.table, validate_common_datum_wrapper, &margs))
goto bad;

if (hashtab_map(p->p_classes.table, validate_class_datum_wrapper, &margs))
goto bad;

Expand Down

0 comments on commit e39cf0a

Please sign in to comment.