From: Thomas Gleixner <tglx@linutronix.de>
To: Andrei Vagin <avagin@gmail.com>, Dave Hansen <dave.hansen@intel.com>
Cc: Andrei Vagin <avagin@google.com>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] x86/fpu: verify xstate buffer size according with requested features
Date: Thu, 18 Jan 2024 20:07:28 +0100 [thread overview]
Message-ID: <87le8mfojz.ffs@tglx> (raw)
In-Reply-To: <CANaxB-zQYC8=7frWGU2pRTDJrkVu0iR8QZCmUxSzGmBG-_b1cg@mail.gmail.com>
On Wed, Jan 17 2024 at 23:59, Andrei Vagin wrote:
> On Wed, Jan 17, 2024 at 3:52 PM Dave Hansen <dave.hansen@intel.com> wrote:
>> I'm not really following the logic there. What's the downside of taking
>> the fault?
>
> Let's consider a scenario where someone messed up with an fpu state on a
> signal frame.
Then he can rightfully keep the pieces...
> With my approach, a mistake can be promptly detected.
How so? Everything which ends up at the 'setfx:' label will just
silently fall back to FX only and init all other components.
> However, if we incorporate the page fault handling of xrstor, a
> mistake will only be identified if xrstor triggers a fault. In cases
> where a buffer is allocated in a large memory mapping, xrstor may
> silently read memory beyond the buffer.
It's either failing the restore due to invalid data (#GP) or it will
restore garbage. User space asked for it.
> Next time, a page beyond a buffer might be swapped out, xrstore
> triggers a fault leading to application crashes.
If it's swapped out it will be swapped back in, no crash.
There are two ways for crashing:
1) There is no mapping or a non-sufficient mapping
i.e. fault_in_readable() fails.
2) The data in the buffer is invalid.
Crashing the application in both cases is just fine.
The nasty part is that the expected size of the user space buffer is
taken from fx_sw->xstate_size.
So you can construct a sigreturn frame where
1) fx_sw->xstate_size is smaller than the size required by
the valid bits in fx_sw->xfeatures.
2) user space unmapped parts of the stack so that not all
of the buffer (as required by XRSTOR) is accessible.
Now XRSTOR tries to restore and accesses the unmapped part of the stack,
which results in a fault. But fault_in_readable() succeeds because 'buf
+ fx_sw->xstate_size' is within the still mapped stack.
So it goes back and tries XRSTOR again. Lather, rinse and repeat.
That's what Andrej is trying to prevent by calculating the size required
by the valid bits in fx_sw->xfeatures and validating that against
fx_sw->xstate_size.
That fx_sw construct is yet another horror from the past. It's not much
better than xsave itself.
Thanks,
tglx
next prev parent reply other threads:[~2024-01-18 19:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240116234901.3238852-1-avagin@google.com>
2024-01-17 19:34 ` [PATCH] x86/fpu: verify xstate buffer size according with requested features Dave Hansen
2024-01-17 22:30 ` Andrei Vagin
2024-01-17 23:52 ` Dave Hansen
2024-01-18 7:59 ` Andrei Vagin
2024-01-18 18:27 ` Dave Hansen
2024-01-18 19:54 ` Thomas Gleixner
2024-01-18 22:02 ` Dave Hansen
2024-01-18 22:11 ` Thomas Gleixner
2024-01-22 3:58 ` Andrei Vagin
2024-01-22 13:26 ` Thomas Gleixner
2024-01-18 19:07 ` Thomas Gleixner [this message]
2024-01-22 6:43 ` Andrei Vagin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87le8mfojz.ffs@tglx \
--to=tglx@linutronix.de \
--cc=avagin@gmail.com \
--cc=avagin@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox