From patchwork Thu Jan 15 15:21:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 4704 Received: (qmail 19951 invoked by alias); 15 Jan 2015 15:23:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19940 invoked by uid 89); 15 Jan 2015 15:23:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp10.uk.ibm.com Received: from e06smtp10.uk.ibm.com (HELO e06smtp10.uk.ibm.com) (195.75.94.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 15 Jan 2015 15:23:18 +0000 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 15 Jan 2015 15:23:15 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 15 Jan 2015 15:23:13 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id ED9E51B0804B for ; Thu, 15 Jan 2015 15:23:49 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t0FFNDv549414262 for ; Thu, 15 Jan 2015 15:23:13 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t0FAJKHo001500 for ; Thu, 15 Jan 2015 05:19:20 -0500 Received: from br87z6lw.boeblingen.de.ibm.com (dyn-9-152-212-115.boeblingen.de.ibm.com [9.152.212.115]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t0FAHxsu030532; Thu, 15 Jan 2015 05:19:20 -0500 From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Pedro Alves , Jan Kratochvil , Mark Kettenis Subject: [PATCH 2/3] x86: Use correct .reg-xstate section size Date: Thu, 15 Jan 2015 16:21:10 +0100 Message-Id: <1421335311-4239-3-git-send-email-arnez@linux.vnet.ibm.com> In-Reply-To: <1421335311-4239-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1421335311-4239-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15011515-0041-0000-0000-000002E349B0 X-IsSubscribed: yes 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",