Patchwork Add PTRACE_GET_SYSCALL_INFO from Linux 5.3 to sys/ptrace.h

login
register
mail settings
Submitter Joseph Myers
Date Oct. 14, 2019, 9:49 p.m.
Message ID <alpine.DEB.2.21.1910142148190.31880@digraph.polyomino.org.uk>
Download mbox | patch
Permalink /patch/34975/
State New
Headers show

Comments

Joseph Myers - Oct. 14, 2019, 9:49 p.m.
Linux 5.3 adds a PTRACE_GET_SYSCALL_INFO constant, with an associated
structure and PTRACE_SYSCALL_INFO_* constants.

This patch adds these to sys/ptrace.h in glibc
(PTRACE_GET_SYSCALL_INFO in each architecture version, the rest in
bits/ptrace-shared.h).  As with previous such constants and associated
structures, the glibc version of the structure is named struct
__ptrace_syscall_info.

Tested for x86_64, and with build-many-glibcs.py.
Dmitry Levin - Oct. 14, 2019, 10:44 p.m.
On Mon, Oct 14, 2019 at 09:49:22PM +0000, Joseph Myers wrote:
> Linux 5.3 adds a PTRACE_GET_SYSCALL_INFO constant, with an associated
> structure and PTRACE_SYSCALL_INFO_* constants.
> 
> This patch adds these to sys/ptrace.h in glibc
> (PTRACE_GET_SYSCALL_INFO in each architecture version, the rest in
> bits/ptrace-shared.h).  As with previous such constants and associated
> structures, the glibc version of the structure is named struct
> __ptrace_syscall_info.
> 
> Tested for x86_64, and with build-many-glibcs.py.

This is obviously correct, with one exception: on those architectures
where we do #undef PTRACE_GET_SYSCALL_INFO, we have to #undef
PTRACE_SYSCALL_INFO_* as well.

Besides that,
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
Joseph Myers - Oct. 14, 2019, 11:45 p.m.
On Tue, 15 Oct 2019, Dmitry V. Levin wrote:

> On Mon, Oct 14, 2019 at 09:49:22PM +0000, Joseph Myers wrote:
> > Linux 5.3 adds a PTRACE_GET_SYSCALL_INFO constant, with an associated
> > structure and PTRACE_SYSCALL_INFO_* constants.
> > 
> > This patch adds these to sys/ptrace.h in glibc
> > (PTRACE_GET_SYSCALL_INFO in each architecture version, the rest in
> > bits/ptrace-shared.h).  As with previous such constants and associated
> > structures, the glibc version of the structure is named struct
> > __ptrace_syscall_info.
> > 
> > Tested for x86_64, and with build-many-glibcs.py.
> 
> This is obviously correct, with one exception: on those architectures
> where we do #undef PTRACE_GET_SYSCALL_INFO, we have to #undef
> PTRACE_SYSCALL_INFO_* as well.

Thanks.  I added those #undefs, retested with build-many-glibcs.py for 
those architectures and committed.

Patch

diff --git a/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h b/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
index cf9f29f885..5f724aeffe 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sys/ptrace.h
@@ -136,8 +136,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };
 
 
diff --git a/sysdeps/unix/sysv/linux/arm/sys/ptrace.h b/sysdeps/unix/sysv/linux/arm/sys/ptrace.h
index 2965248da4..c586fe4db1 100644
--- a/sysdeps/unix/sysv/linux/arm/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/arm/sys/ptrace.h
@@ -196,8 +196,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };
 
 
diff --git a/sysdeps/unix/sysv/linux/bits/ptrace-shared.h b/sysdeps/unix/sysv/linux/bits/ptrace-shared.h
index 1dc1ec79b1..f351d2f45b 100644
--- a/sysdeps/unix/sysv/linux/bits/ptrace-shared.h
+++ b/sysdeps/unix/sysv/linux/bits/ptrace-shared.h
@@ -52,6 +52,15 @@  enum __ptrace_eventcodes
   PTRACE_EVENT_STOP	= 128
 };
 
+/* Type of stop for PTRACE_GET_SYSCALL_INFO.  */
+enum __ptrace_get_syscall_info_op
+{
+  PTRACE_SYSCALL_INFO_NONE = 0,
+  PTRACE_SYSCALL_INFO_ENTRY = 1,
+  PTRACE_SYSCALL_INFO_EXIT = 2,
+  PTRACE_SYSCALL_INFO_SECCOMP = 3
+};
+
 /* Arguments for PTRACE_PEEKSIGINFO.  */
 struct __ptrace_peeksiginfo_args
 {
@@ -73,6 +82,44 @@  struct __ptrace_seccomp_metadata
   __uint64_t flags;		/* Output: filter's flags.  */
 };
 
+/* Results of PTRACE_GET_SYSCALL_INFO.  */
+struct __ptrace_syscall_info
+{
+  __uint8_t op;			/* One of the enum
+				   __ptrace_get_syscall_info_op
+				   values.  */
+  __uint32_t arch __attribute__ ((__aligned__ (4))); /* AUDIT_ARCH_*
+							value.  */
+  __uint64_t instruction_pointer; /* Instruction pointer.  */
+  __uint64_t stack_pointer;	/* Stack pointer.  */
+  union
+  {
+    /* System call number and arguments, for
+       PTRACE_SYSCALL_INFO_ENTRY.  */
+    struct
+    {
+      __uint64_t nr;
+      __uint64_t args[6];
+    } entry;
+    /* System call return value and error flag, for
+       PTRACE_SYSCALL_INFO_EXIT.  */
+    struct
+    {
+      __int64_t rval;
+      __uint8_t is_error;
+    } exit;
+    /* System call number, arguments and SECCOMP_RET_DATA portion of
+       SECCOMP_RET_TRACE return value, for
+       PTRACE_SYSCALL_INFO_SECCOMP.  */
+    struct
+    {
+      __uint64_t nr;
+      __uint64_t args[6];
+      __uint32_t ret_data;
+    } seccomp;
+  };
+};
+
 /* Perform process tracing functions.  REQUEST is one of the values
    above, and determines the action to be taken.
    For all requests except PTRACE_TRACEME, PID specifies the process to be
diff --git a/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h b/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
index 92e3ae901a..07da89d2c4 100644
--- a/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
@@ -149,8 +149,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };
 
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h b/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
index 939e7e6690..6d69462048 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/ptrace.h
@@ -38,6 +38,7 @@  __BEGIN_DECLS
 # undef PTRACE_GETREGSET
 # undef PTRACE_GETSIGINFO
 # undef PTRACE_GETSIGMASK
+# undef PTRACE_GET_SYSCALL_INFO
 # undef PTRACE_GETVRREGS
 # undef PTRACE_GETVSRREGS
 # undef PTRACE_INTERRUPT
@@ -241,8 +242,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };
 
 
diff --git a/sysdeps/unix/sysv/linux/s390/sys/ptrace.h b/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
index 70b92d113e..9a6cbaeb40 100644
--- a/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
@@ -79,6 +79,7 @@  __BEGIN_DECLS
 # undef PTRACE_EVENT_SECCOMP
 # undef PTRACE_EVENT_STOP
 # undef PTRACE_PEEKSIGINFO_SHARED
+# undef PTRACE_GET_SYSCALL_INFO
 #endif
 /* Type of the REQUEST argument to `ptrace.'  */
 enum __ptrace_request
@@ -198,6 +199,10 @@  enum __ptrace_request
   PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
 
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e,
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
+
   PTRACE_PEEKUSR_AREA = 0x5000,
 #define PTRACE_PEEKUSR_AREA PTRACE_PEEKUSR_AREA
 
diff --git a/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h b/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h
index fd0fc37e14..73e54036a8 100644
--- a/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/sparc/sys/ptrace.h
@@ -217,8 +217,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };
 
 
diff --git a/sysdeps/unix/sysv/linux/sys/ptrace.h b/sysdeps/unix/sysv/linux/sys/ptrace.h
index c99fde3441..61981e849c 100644
--- a/sysdeps/unix/sysv/linux/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/sys/ptrace.h
@@ -166,8 +166,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };
 
 
diff --git a/sysdeps/unix/sysv/linux/x86/sys/ptrace.h b/sysdeps/unix/sysv/linux/x86/sys/ptrace.h
index 7f0c16fd3e..9f21385fa0 100644
--- a/sysdeps/unix/sysv/linux/x86/sys/ptrace.h
+++ b/sysdeps/unix/sysv/linux/x86/sys/ptrace.h
@@ -186,8 +186,12 @@  enum __ptrace_request
 #define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER
 
   /* Get seccomp BPF filter metadata.  */
-  PTRACE_SECCOMP_GET_METADATA = 0x420d
+  PTRACE_SECCOMP_GET_METADATA = 0x420d,
 #define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
+
+  /* Get information about system call.  */
+  PTRACE_GET_SYSCALL_INFO = 0x420e
+#define PTRACE_GET_SYSCALL_INFO PTRACE_GET_SYSCALL_INFO
 };