Re: [PATCH] x86: Check if shadow stack is active for ssp_get()

From: Dave Hansen
Date: Tue Jan 07 2025 - 13:01:24 EST


Some missing background: The x86 shadow stack support has its own set of
registers. Those registers are XSAVE-managed, but they are "supervisor
state components" which means that userspace can't touch them with
XSAVE/XRSTOR. It also means that they are not accessible from the
existing ptrace ABI like the FPU register or GPRs. Thus, there is a new
ptrace get/set interface for it.

The ptrace code is also provided an ->active() handler in addition to
the get/set ones. But this ->active() handler is _not_ checked before
the get/set handlers are called. This was not understood when shadow
stack support was put in place.

I think I'd also phrase the problem like this:

As a result, both the set/get handlers can be called with
XFEATURE_CET_USER in its init state, which would cause get_xsave_addr()
to return NULL and trigger a WARN_ON(). The ssp_set() handler luckily
has an ssp_active() check to avoid surprising the kernel with shadow
stack behavior when the kernel is not read for it (ARCH_SHSTK_SHSTK==0).
That check just happened to avoid the warning.

But the ->get() side wasn't so lucky. It can be called with shadow
stacks disabled, triggering the warning in practice, as reported by
Christina Schimpe:

...

Ensure that shadow stacks are active in a thread before looking them up
in the XSAVE buffer. Since ARCH_SHSTK_SHSTK and user_ssp[SHSTK_EN] are
set at the same time, the active check ensures that there will be
something to find in the XSAVE buffer.

---------------

We also want this to cc:stable, right?