Skip to content

ARM: userspace/test_bad_syscall fails on ARMv8-M #17177

@ioannisg

Description

@ioannisg

After increasing the test coverage in tests/kernel/mem_protect/userspace (FYI @andrewboie), the test is failing for ARMv8-M platforms.

To Reproduce
Steps to reproduce the behavior:

  1. Checkout master or pull-request branch [Backport v1.14-branch] 1.14 userspace backports coverage #17079 (for the LTS)
  2. Build and run tests/kernel/mem_protect/userspace for nrf9160_pca10090
  3. test_bad_syscall fails.

The logs are provided below:

===================================================================
starting test - test_bad_syscall
Bad system call id 2147483647 invoked
***** Hardware exception *****
Current thread ID = 0x200011d0 (unknown)
Faulting instruction address = 0x33c9
Caught system error -- reason 0
***** USAGE FAULT *****
  Stack overflow (context area not valid)
***** Stack Check Fail! *****
Current thread ID = 0x200011d0 (unknown)
Faulting instruction address = 0xffffffff
Caught system error -- reason 2

    Assertion failed at ../src/main.c:107: z_SysFatalErrorHandler: (Reached unreachable code)
Unexpected fault during test
FAIL - test_bad_syscall

The failure is not yet observed in v1.14-branch, since the PR with the test coverage increase has not yet been merged.

The root cause of the failing test is an implementation bug in system call handling for ARM platforms: the system call initialization code is using the default (un-privileged) stack before switching to the privilege stack.

The fail is only detected in ARMv8-M, because ARMv8-M has more strict rules for pushing to the stack, when stack-overflow mechanisms are activated (i.e. does not allow any push to stack memory below the stack limit; not only a push into a programmed read-only guard, as the traditional MPU-based guard mechanism).

Impact
Affects ARM builds with CONFIG_USERSPACE=y.
The userspace test is failing
Any swap during system-call initialization in ARMv8-M builds will trigger a stack-overflow.

Fix
The fix is provided in #17146

Metadata

Metadata

Assignees

Labels

area: ARMARM (32-bit) Architecturearea: UserspaceUserspacebugThe issue is a bug, or the PR is fixing a bugpriority: highHigh impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions