Re: um: PTRACE_SETREGSET failure with XSTATE on Kabylake CPU

From: Yu-cheng Yu
Date: Tue Jun 20 2017 - 14:06:25 EST


On Tue, 2017-06-20 at 11:05 +0200, Richard Weinberger wrote:
> [adding x86 folks]
>
> Am 20.06.2017 um 10:49 schrieb Thomas Meyer:
> >
> > In UML the first userspace ptrace always fails, so init get's killed.
> >
> > The check "count < fpu_user_xstate_size" was introduced by commit:
> >
> > commit 91c3dba7dbc199191272f4a9863f86ea3bfd679f
> > Author: Yu-cheng Yu <yu-cheng.yu@xxxxxxxxx>
> > Date: Fri Jun 17 13:07:17 2016 -0700
> >
> > x86/fpu/xstate: Fix PTRACE frames for XSAVES
> >
> > XSAVES uses compacted format and is a kernel instruction. The kernel
> > should use standard-format, non-supervisor state data for PTRACE.
> >
> > So to summarize:
> >
> > - PTRACE_GETREGSET with NT_X86_XSTATE gets 832 and return 832, with no
> > error.
> >
> > - PTRACE_SETREGSET get 832 (sizeof struct _xstate) but wants at least
> > 1088, otherwise it will fail with -EFAULT (why not -EINVAL?)
> >
> > Ideas?

We considered allowing a partial XSAVE buffer for PTRACE_SETREGSET, but
it was that the XSAVE instruction requires a full-size buffer led to
this choice. Using a smaller buffer for XSAVE causes a fault.

Yu-cheng