public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Cc: Pedro Alves <palves@redhat.com>,
	       Jan Kratochvil <jan.kratochvil@redhat.com>,
	       Mark Kettenis <mark.kettenis@xs4all.nl>
Subject: [PATCH 2/3] x86: Use correct .reg-xstate section size
Date: Thu, 15 Jan 2015 15:23:00 -0000	[thread overview]
Message-ID: <1421335311-4239-3-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1421335311-4239-1-git-send-email-arnez@linux.vnet.ibm.com>

When reading the XSAVE extended state from an i386 or AMD64 core file,
the respective regset iterator requests a minimum section size of
zero.  Since the respective regset supply function does not check the
size either, this may lead to accessing data out of range if the
section is too short.

In write mode, the iterator always uses the maximum supported size for
the XSAVE extended state.

This is now changed such that the iterator always requests the
expected size of this section based on xcr0, both for reading and
writing.

gdb/ChangeLog:

	* amd64-linux-tdep.c (amd64_linux_iterate_over_regset_sections):
	For ".reg-xstate", explicitly specify the requested section size
	via X86_XSTATE_SIZE instead of just 0 on input and
	X86_XSTATE_MAX_SIZE on output.
	* i386-linux-tdep.c (i386_linux_iterate_over_regset_sections):
	Likewise.
---
 gdb/amd64-linux-tdep.c | 2 +-
 gdb/i386-linux-tdep.c  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 42d884e..5db04c0 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1639,7 +1639,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 
   cb (".reg", 27 * 8, &i386_gregset, NULL, cb_data);
   cb (".reg2", 512, &amd64_fpregset, NULL, cb_data);
-  cb (".reg-xstate",  regcache ? X86_XSTATE_MAX_SIZE : 0,
+  cb (".reg-xstate",  X86_XSTATE_SIZE (tdep->xcr0),
       &amd64_linux_xstateregset, "XSAVE extended state", cb_data);
 }
 
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 8a5209a..4a0ce60 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -690,8 +690,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
   cb (".reg", 68, &i386_gregset, NULL, cb_data);
 
   if (tdep->xcr0 & X86_XSTATE_AVX)
-    /* Use max size for writing, accept any size when reading.  */
-    cb (".reg-xstate", regcache ? X86_XSTATE_MAX_SIZE : 0,
+    cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
 	&i386_linux_xstateregset, "XSAVE extended state", cb_data);
   else if (tdep->xcr0 & X86_XSTATE_SSE)
     cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
-- 
1.8.4.2

  parent reply	other threads:[~2015-01-15 15:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-15 15:22 [PATCH 0/3] Fix for PR 17808 and some related changes Andreas Arnez
2015-01-15 15:22 ` [PATCH 1/3] [PR corefiles/17808] Fix internal error when core file section is too big Andreas Arnez
2015-01-15 15:23 ` Andreas Arnez [this message]
2015-01-15 15:24 ` [PATCH 3/3] Warn if core file register section is larger than expected Andreas Arnez
2015-01-22 11:38 ` [PING] [PATCH 0/3] Fix for PR 17808 and some related changes Andreas Arnez
2015-01-23 16:14 ` Pedro Alves

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=1421335311-4239-3-git-send-email-arnez@linux.vnet.ibm.com \
    --to=arnez@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=mark.kettenis@xs4all.nl \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).