tests: fatal: enable x86 MMU stack protection
Show that this mechanism can detect stack overflows with the guard page. We only do it once since are are in an alternate IA HW task after it happens. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
19fdf4d6f8
commit
416eca5b13
4 changed files with 29 additions and 8 deletions
3
tests/kernel/fatal/prj-x86-mmu.conf
Normal file
3
tests/kernel/fatal/prj-x86-mmu.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
CONFIG_X86_MMU=y
|
||||
CONFIG_X86_STACK_PROTECTION=y
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_X86_STACK_PROTECTION=n
|
||||
|
||||
|
|
|
@ -123,6 +123,8 @@ void stack_thread2(void)
|
|||
|
||||
void main(void)
|
||||
{
|
||||
int expected_reason;
|
||||
|
||||
rv = TC_PASS;
|
||||
|
||||
TC_START("test_fatal");
|
||||
|
@ -195,9 +197,19 @@ void main(void)
|
|||
(k_thread_entry_t)stack_thread1,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(PRIORITY), 0,
|
||||
K_NO_WAIT);
|
||||
if (crash_reason != _NANO_ERR_STACK_CHK_FAIL) {
|
||||
|
||||
#ifdef CONFIG_X86_STACK_PROTECTION
|
||||
/* x86 double-faults when stack overflow in kernel mode, we're
|
||||
* in an alternate IA HW task when we finish the test
|
||||
*/
|
||||
expected_reason = _NANO_ERR_KERNEL_PANIC;
|
||||
#else
|
||||
expected_reason = _NANO_ERR_STACK_CHK_FAIL;
|
||||
#endif
|
||||
|
||||
if (crash_reason != expected_reason) {
|
||||
TC_ERROR("bad reason code got %d expected %d\n",
|
||||
crash_reason, _NANO_ERR_KERNEL_PANIC);
|
||||
crash_reason, expected_reason);
|
||||
rv = TC_FAIL;
|
||||
}
|
||||
if (rv == TC_FAIL) {
|
||||
|
@ -207,19 +219,18 @@ void main(void)
|
|||
TC_PRINT("PASS\n");
|
||||
}
|
||||
|
||||
TC_PRINT("test stack overflow - swap\n");
|
||||
#ifdef CONFIG_STACK_SENTINEL
|
||||
/* Stack sentinel has to be invoked, make sure it happens during
|
||||
* a context switch
|
||||
*/
|
||||
TC_PRINT("test stack overflow - swap\n");
|
||||
k_thread_create(&alt_thread, overflow_stack, OVERFLOW_STACKSIZE,
|
||||
#else
|
||||
k_thread_create(&alt_thread, alt_stack,
|
||||
K_THREAD_STACK_SIZEOF(alt_stack),
|
||||
#endif
|
||||
(k_thread_entry_t)stack_thread2,
|
||||
NULL, NULL, NULL, K_PRIO_PREEMPT(PRIORITY), 0,
|
||||
K_NO_WAIT);
|
||||
if (crash_reason != _NANO_ERR_STACK_CHK_FAIL) {
|
||||
TC_ERROR("bad reason code got %d expected %d\n",
|
||||
crash_reason, _NANO_ERR_KERNEL_PANIC);
|
||||
crash_reason, _NANO_ERR_STACK_CHK_FAIL);
|
||||
rv = TC_FAIL;
|
||||
}
|
||||
if (rv == TC_FAIL) {
|
||||
|
@ -228,6 +239,7 @@ void main(void)
|
|||
} else {
|
||||
TC_PRINT("PASS\n");
|
||||
}
|
||||
#endif
|
||||
out:
|
||||
TC_END_RESULT(rv);
|
||||
TC_END_REPORT(rv);
|
||||
|
|
|
@ -6,3 +6,8 @@ tests:
|
|||
arch_whitelist: arc
|
||||
extra_args: CONF_FILE=prj-arc.conf
|
||||
tags: core ignore_faults
|
||||
- x86-mmu-stack-checking:
|
||||
platform_whitelist: qemu_x86 qemu_x86_iamcu
|
||||
extra_args: CONF_FILE=prj-x86-mmu.conf
|
||||
tags: core ignore_faults
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue