Skip to content
Permalink
Browse files

tests: kernel: fatal: add HW stack check for priv stack

This commit adds a test in tests/kernel/fatal test-suite, which checks
that the HW stack overflow detection works as expected during a user
thread system call.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and andrewboie committed Jun 17, 2019
1 parent 93e643c commit f4f2b13126d5fa3541bc3230ec68d83722bf3c36
Showing with 51 additions and 1 deletion.
  1. +1 −0 tests/kernel/fatal/prj.conf
  2. +35 −1 tests/kernel/fatal/src/main.c
  3. +15 −0 tests/kernel/fatal/src/test_syscalls.h
@@ -2,4 +2,5 @@ CONFIG_HW_STACK_PROTECTION=y
CONFIG_ZTEST=y
CONFIG_COVERAGE=n
CONFIG_TEST_USERSPACE=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_SMP=n
@@ -11,6 +11,11 @@
#include <irq_offload.h>
#include <kswap.h>

#if defined(CONFIG_USERSPACE)
#include <syscall_handler.h>
#include "test_syscalls.h"
#endif

#if defined(CONFIG_X86) && defined(CONFIG_X86_MMU)
#define STACKSIZE (8192)
#else
@@ -136,7 +141,18 @@ void blow_up_stack(void)
{
stack_smasher(37);
}
#endif

#if defined(CONFIG_USERSPACE)

void z_impl_blow_up_priv_stack(void)
{
blow_up_stack();
}

Z_SYSCALL_HANDLER0_SIMPLE_VOID(blow_up_priv_stack);

#endif /* CONFIG_USERSPACE */
#endif /* CONFIG_STACK_SENTINEL */

void stack_sentinel_timer(void)
{
@@ -174,6 +190,18 @@ void stack_hw_overflow(void)
rv = TC_FAIL;
}

#if defined(CONFIG_USERSPACE)
void user_priv_stack_hw_overflow(void)
{
/* Test that HW stack overflow check works
* on a user thread's privilege stack.
*/
blow_up_priv_stack();
TC_ERROR("should never see this\n");
rv = TC_FAIL;
}
#endif /* CONFIG_USERSPACE */

void check_stack_overflow(void *handler, u32_t flags)
{
crash_reason = -1;
@@ -289,6 +317,12 @@ void test_fatal(void)

TC_PRINT("test stack HW-based overflow - user 2\n");
check_stack_overflow(stack_hw_overflow, K_USER);

TC_PRINT("test stack HW-based overflow - user priv stack 1\n");
check_stack_overflow(user_priv_stack_hw_overflow, K_USER);

TC_PRINT("test stack HW-based overflow - user priv stack 2\n");
check_stack_overflow(user_priv_stack_hw_overflow, K_USER);
#endif /* CONFIG_USERSPACE */

#endif /* !CONFIG_ARCH_POSIX */
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef _TEST_SYSCALLS_H_
#define _TEST_SYSCALLS_H_
#include <zephyr.h>

__syscall void blow_up_priv_stack(void);

#include <syscalls/test_syscalls.h>

#endif /* _TEST_SYSCALLS_H_ */

0 comments on commit f4f2b13

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