-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
ARM: TLS pointer may not be set correctly #25635
Comments
@andrewboie thanks for reporting this. A few notes:
If this is the case (I believe we really need to make this clear in the Macro documentation), then the error is in the kernel implementation of k_thread_create:
So this needs to be fixed, but should not affect the bug you are reporting here. If I understood correctly, the real problem with TLS here is that in ARM's arch_new_thread()
is executed after setting the userspace local data pointer. It should come first, IMHO, and, unfortunately, I cannot recall why this is not the case. |
@andrewboie, #25654, contains a fix proposal, and your TLS test for mem_protect/userspace, taken from #25636 (had to resolve conflicts while cherry-picking) |
Describe the bug
It's expected that given the following code:
That it is valid to pass either
SIZE
orK_THREAD_STACK_SIZEOF(stack)
to ak_thread_create()
call's stack size argument.This is not the case for ARM Cortex-M. If
SIZE
is passed in, the math is performed improperly and the TLS pointer gets set to memory after the end of the stack object. This will result in either MPU faults when trying to access TLS (at the moment, limited to getting/settingerrno
) or data corruption.The following test code illustrates the issue. Only ARM Cortex-M seems to be affected.
To Reproduce
Run above test code. You will see:
Expected behavior
Passing test. TLS region should be within bounds of the stack object.
Impact
Workaround is possible by always using
K_THREAD_STACK_SIZEOF()
, but users who don't know about this could get MPU faults or data corruption.My PR #24714 fixes this as I rewrote all the relevant code.
For 1.14 branch I need a more targeted solution.
The text was updated successfully, but these errors were encountered: