On Thu, Sep 25, 2025 at 05:46:46PM +0100, Catalin Marinas wrote:
On Sun, Sep 21, 2025 at 02:21:35PM +0100, Mark Brown wrote:
- } else if (task == current &&
task->thread.gcs_el0_mode & PR_SHADOW_STACK_EXIT_TOKEN) {
I checked the code paths leading here and task is always current. But better to keep the test in case the core code ever changes.
We can't have scheduled? That's actually a pleasant surprise, that was the main hole I was thinking of in the cover letter.
/*
* We can't do anything constructive if this fails,
* and the thread might be exiting due to being in a
* bad state anyway.
*/
put_user_gcs(cap_val, cap_ptr, &ret);
/*
* Ensure the new cap is ordered before standard
* memory accesses to the same location.
*/
gcsb_dsync();
- }
The only downside is that, if the thread did not unwind properly, we don't write the token where it was initially. We could save the token address from clone3() and restore it there instead.
If we do that and the thread pivots away to another GCS and exits from there then we'll write the token onto a different stack. Writing onto the location that userspace provided when creating the thread should be fine for glibc's needs but it feels like the wrong assumption to bake in, to me it feels less bad to have to map a new GCS in the case where we didn't unwind properly. There will be overhead in doing that but the thread is already exiting uncleanly so imposing a cost doesn't seem disproportionate.