public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [pushed] Fix PR gdb/20413 - x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER
Date: Tue, 26 Jul 2016 19:33:00 -0000	[thread overview]
Message-ID: <1469561600-24051-2-git-send-email-palves@redhat.com> (raw)

An x32 gdb always issues this warning:

 (gdb) start
 Temporary breakpoint 1 at 0x4043e9: file foo.c, line 25.
 Starting program: a.out
 warning: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: Input/output error

 Temporary breakpoint 1, main (argc=1, argv=0xffffd544) at foo.c:25
 25      {
 (gdb)

As described in Linux commit 55283e253771 (x32: Add ptrace for x32):

    [...] PTRACE_PEEKUSR and PTRACE_POKEUSR are only allowed to access
    segment and debug registers. [...]

The fix is to use PTRACE_GETREGS instead.

gdb/ChangeLog:
2016-07-26  Pedro Alves  <palves@redhat.com>

	* nat/linux-ptrace.c: Include "gregset.h".
	(linux_ptrace_test_ret_to_nx): Use PTRACE_GETREGS instead of
	PTRACE_PEEKUSER.
---
 gdb/ChangeLog          |  6 ++++++
 gdb/nat/linux-ptrace.c | 22 ++++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3a5e870..2f3710d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2016-07-26  Pedro Alves  <palves@redhat.com>
 
+	* nat/linux-ptrace.c: Include "gregset.h".
+	(linux_ptrace_test_ret_to_nx): Use PTRACE_GETREGS instead of
+	PTRACE_PEEKUSER.
+
+2016-07-26  Pedro Alves  <palves@redhat.com>
+
 	* amd64-linux-nat.c (amd64_linux_siginfo_fixup): Rename 'native'
 	parameter to 'ptrace'.
 	* nat/amd64-linux-siginfo.c (GDB_SI_SIZE): New define.
diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c
index 0eaf9a3..980ed53 100644
--- a/gdb/nat/linux-ptrace.c
+++ b/gdb/nat/linux-ptrace.c
@@ -23,6 +23,7 @@
 #include "buffer.h"
 #include "gdb_wait.h"
 #include "gdb_ptrace.h"
+#include "gregset.h"
 
 /* Stores the ptrace options supported by the running kernel.
    A value of -1 means we did not check for features yet.  A value
@@ -100,6 +101,7 @@ linux_ptrace_test_ret_to_nx (void)
   gdb_byte *return_address, *pc;
   long l;
   int status, kill_status;
+  elf_gregset_t regs;
 
   return_address
     = (gdb_byte *) mmap (NULL, 2, PROT_READ | PROT_WRITE,
@@ -188,23 +190,19 @@ linux_ptrace_test_ret_to_nx (void)
       return;
     }
 
-  errno = 0;
+  if (ptrace (PTRACE_GETREGS, child, (PTRACE_TYPE_ARG3) 0,
+	      (PTRACE_TYPE_ARG4) &regs) < 0)
+    {
+      warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_GETREGS: %s"),
+	       safe_strerror (errno));
+    }
 #if defined __i386__
-  l = ptrace (PTRACE_PEEKUSER, child, (PTRACE_TYPE_ARG3) (uintptr_t) (EIP * 4),
-	      (PTRACE_TYPE_ARG4) NULL);
+  pc = (gdb_byte *) (uintptr_t) regs[EIP];
 #elif defined __x86_64__
-  l = ptrace (PTRACE_PEEKUSER, child, (PTRACE_TYPE_ARG3) (uintptr_t) (RIP * 8),
-	      (PTRACE_TYPE_ARG4) NULL);
+  pc = (gdb_byte *) (uintptr_t) regs[RIP];
 #else
 # error "!__i386__ && !__x86_64__"
 #endif
-  if (errno != 0)
-    {
-      warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: %s"),
-	       safe_strerror (errno));
-      return;
-    }
-  pc = (gdb_byte *) (uintptr_t) l;
 
   kill (child, SIGKILL);
   ptrace (PTRACE_KILL, child, (PTRACE_TYPE_ARG3) NULL,
-- 
2.5.5

                 reply	other threads:[~2016-07-26 19:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1469561600-24051-2-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).