- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.2k
Description
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:
- Checkout masteror pull-request branch [Backport v1.14-branch] 1.14 userspace backports coverage #17079 (for the LTS)
- Build and run tests/kernel/mem_protect/userspacefornrf9160_pca10090
- test_bad_syscallfails.
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