Skip to content
Permalink
Browse files

tests: z_except_reason() policy from usermode

User mode should be able to successfully induce a kernel
oops, or stack check fail fatal error. The latter is
required by compiler stack canaries.

User mode should not be able to induce a kernel panic, or
fake some other kind of exception.

Currently supported on ARM and x86 platforms.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information...
andrewboie committed Jul 16, 2019
1 parent 34ffda3 commit 55fce980d72ea744b6c7a88a923a48d7622fb2ed
Showing with 38 additions and 0 deletions.
  1. +38 −0 tests/kernel/mem_protect/userspace/src/main.c
@@ -1119,6 +1119,37 @@ void test_object_recycle(void)
zassert_true(perms_count == 1, "invalid number of thread permissions");
}

#define test_oops(provided, expected) do { \
expect_fault = true; \
expected_reason = expected; \
z_except_reason(provided); \
} while (false)

void test_oops_panic(void)
{
test_oops(K_ERR_KERNEL_PANIC, K_ERR_KERNEL_OOPS);
}

void test_oops_oops(void)
{
test_oops(K_ERR_KERNEL_OOPS, K_ERR_KERNEL_OOPS);
}

void test_oops_exception(void)
{
test_oops(K_ERR_CPU_EXCEPTION, K_ERR_KERNEL_OOPS);
}

void test_oops_maxint(void)
{
test_oops(INT_MAX, K_ERR_KERNEL_OOPS);
}

void test_oops_stackcheck(void)
{
test_oops(K_ERR_STACK_CHK_FAIL, K_ERR_STACK_CHK_FAIL);
}

void test_main(void)
{
struct k_mem_partition *parts[] = {&part0, &part1,
@@ -1171,6 +1202,13 @@ void test_main(void)
ztest_unit_test(test_stack_buffer),
ztest_user_unit_test(test_unimplemented_syscall),
ztest_user_unit_test(test_bad_syscall),
#if !defined(CONFIG_ARC) /* FIXME: #17590 */
ztest_user_unit_test(test_oops_panic),
ztest_user_unit_test(test_oops_oops),
ztest_user_unit_test(test_oops_exception),
ztest_user_unit_test(test_oops_maxint),
ztest_user_unit_test(test_oops_stackcheck),
#endif /* !defined(CONFIG_ARC) */
ztest_unit_test(test_object_recycle)
);
ztest_run_test_suite(userspace);

0 comments on commit 55fce98

Please sign in to comment.
You can’t perform that action at this time.