Re: question about save_xstate_sig() - WHY DOES THIS WORK?

From: H. Peter Anvin
Date: Fri Jan 23 2015 - 16:07:55 EST


On 01/23/2015 11:34 AM, Rik van Riel wrote:
> While working on a patch series to defer FPU state loading until
> kernel -> user space transition, and be more lazy with FPU state
> while in the kernel, I came across this code in save_xstate_sig().
>
> Not only is this broken with my new code, but it looks like it may
> be broken with the current code, too...
>
> Specifically, save_user_xstate() may page fault and sleep. After
> returning from the page fault, there is no guarantee that the
> FPU state will be restored into the CPU, when the system is not
> running with eager fpu mode.
>
> In that case, what prevents us from saving random FPU register state
> to the user's stack frame? Potentially state containing data from
> other programs...
>

If the FPU state is not current, we'll have CR0.TS = 1 and the XSAVE
will cause an #NM exception, which will cause the FPU state to be
swapped in.

-hpa


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/