Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/kernel/fatal/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 35 additions & 1 deletion tests/kernel/fatal/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
15 changes: 15 additions & 0 deletions tests/kernel/fatal/src/test_syscalls.h
Original file line number Diff line number Diff line change
@@ -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_ */