From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/x86: Fix write out of mxcsr register for xsave targets
Date: Fri, 11 May 2018 21:55:00 -0000 [thread overview]
Message-ID: <20180511195628.GD3797@embecosm.com> (raw)
In-Reply-To: <d31ffaec-0692-f9d8-35f6-c17f14b7f01e@redhat.com>
* Pedro Alves <palves@redhat.com> [2018-05-11 18:14:20 +0100]:
> On 05/11/2018 12:52 PM, Andrew Burgess wrote:
> > In commit:
> >
> > commit 8ee22052f690c007556b97eed59f49350ece5ca9
> > Author: Andrew Burgess <andrew.burgess@embecosm.com>
> > Date: Thu May 3 17:46:14 2018 +0100
> >
> > gdb/x86: Handle kernels using compact xsave format
> >
> > in two places FXSAVE_ADDR was used instead of FXSAVE_MXCSR_ADDR to get
> > the address of the mxcsr register within the xsave buffer. This will
> > mean we are potentially accessing the wrong location within the xsave
> > buffer.
> >
> > There are no tests included with this patch. The first mistake would
> > only trigger an issue if/when the user tries to manually set the mxcsr
> > register to a value that matches the random (value off stack) value
> > that is in the xsave buffer, in this case the change by the user will
> > go unnoticed by GDB, and the default value of mxcsr will be preserved.
> >
> > The second mistake only happens on the code path where all x87
> > registers are being written out of the register cache. I'm not sure
> > how to trigger that code path.
> >
>
> OK as is.
>
> How did you notice this? Valgrind?
That's a funny story...
I had reason to compile HEAD on a machine with GCC 5.4, and the build
failed with a warning that 'i' was used uninitialised in this block:
/* The mxcsr register is written into the xsave buffer if either AVX
or SSE is enabled, so only clear it if both of those features
require clearing. */
if ((clear_bv & (X86_XSTATE_AVX | X86_XSTATE_SSE))
== (X86_XSTATE_AVX | X86_XSTATE_SSE))
store_unsigned_integer (FXSAVE_ADDR (tdep, regs, i), 2, byte_order,
I387_MXCSR_INIT_VAL);
Now the warning from GCC is bogus, 'i' will be initialised, but it's
not going to be initialised correctly, and when I looked into how to
set 'i' to the correct value I realised the mistake I made.
After that I double checked all the accesses to mxcsr that I changed,
and found the second bug.
Just a lucky find at the end of the day :)
Thanks,
Andrew
prev parent reply other threads:[~2018-05-11 19:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-11 14:47 Andrew Burgess
2018-05-11 18:26 ` Pedro Alves
2018-05-11 21:55 ` Andrew Burgess [this message]
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=20180511195628.GD3797@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/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