]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
include/vki: fix vki_siginfo_t definition on amd64, arm64, and ppc64
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 8 Mar 2019 03:07:00 +0000 (04:07 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 19 Sep 2019 22:16:00 +0000 (00:16 +0200)
As it turned out, the size of vki_siginfo_t is incorrect on these 64-bit
architectures:

    (gdb) p sizeof(vki_siginfo_t)
    $1 = 136
    (gdb) ptype struct vki_siginfo
    type = struct vki_siginfo {
        int si_signo;
        int si_errno;
        int si_code;
        union {
            int _pad[29];
            struct {...} _kill;
            struct {...} _timer;
            struct {...} _rt;
            struct {...} _sigchld;
            struct {...} _sigfault;
            struct {...} _sigpoll;
        } _sifields;
    }

It looks like that for this architecture, __VKI_ARCH_SI_PREAMBLE_SIZE
hasn't been defined properly, which resulted in incorrect
VKI_SI_PAD_SIZE calculation (29 instead of 28).

    <6a9e4>   DW_AT_name        : (indirect string, offset: 0xcf59): _sifields
    <6a9ef>   DW_AT_data_member_location: 16

This issue has been discovered with strace's "make check-valgrind-memcheck",
which produced false out-of-bounds writes on ptrace(PTRACE_GETSIGINFO) calls:

    SYSCALL[24264,1](101) sys_ptrace ( 16898, 24283, 0x0, 0x606bd40 )
    ==24264== Syscall param ptrace(getsiginfo) points to unaddressable byte(s)
    ==24264==    at 0x575C06E: ptrace (ptrace.c:45)
    ==24264==    by 0x443244: next_event (strace.c:2431)
    ==24264==    by 0x443D30: main (strace.c:2845)
    ==24264==  Address 0x606bdc0 is 0 bytes after a block of size 144 alloc'd

(Note that the address passed is 0x606bd40 and the address reported is
0x606bdc0).

After the patch, no such errors observed.

* include/vki/vki-amd64-linux.h [__x86_64__ && __ILP32__]
(__vki_kernel_si_clock_t): New typedef.
[__x86_64__ && __ILP32__] (__VKI_ARCH_SI_CLOCK_T,
__VKI_ARCH_SI_ATTRIBUTES): New macros.
[__x86_64__ && !__ILP32__] (__VKI_ARCH_SI_PREAMBLE_SIZE): New macro,
define to 4 ints.
* include/vki/vki-arm64-linux.h (__VKI_ARCH_SI_PREAMBLE_SIZE): Likewise.
* include/vki/vki-ppc64-linux.h [__powerpc64__] (__VKI_ARCH_SI_PREAMBLE_SIZE):
Likewise.
* include/vki/vki-linux.h [!__VKI_ARCH_SI_CLOCK_T]
(__VKI_ARCH_SI_CLOCK_T): New macro, define to vki_clock_t.
[!__VKI_ARCH_SI_ATTRIBUTES] (__VKI_ARCH_SI_ATTRIBUTES): New macro,
define to nil.
(struct vki_siginfo): Use __VKI_ARCH_SI_CLOCK_T type for _utime and
_stime fields.  Add __VKI_ARCH_SI_ATTRIBUTES.

Resolves: https://bugs.kde.org/show_bug.cgi?id=405201
Reported-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Eugene Syromyatnikov <evgsyr@gmail.com>
NEWS
include/vki/vki-amd64-linux.h
include/vki/vki-arm64-linux.h
include/vki/vki-linux.h
include/vki/vki-ppc64-linux.h

diff --git a/NEWS b/NEWS
index 10d922cc25e62c0c367dd8775a1dc697162c2831..2fde3c7cdaa9cc846b31a70d609a4a0452bb9e8a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -72,6 +72,7 @@ where XXXXXX is the bug number as listed below.
 408091  Missing pkey syscalls
 408414  Add support for missing for preadv2 and pwritev2 syscalls
 404406  s390x: z14 miscellaneous instructions not implemented
+405201  Incorrect size of struct vki_siginfo on 64-bit Linux architectures
 409141  Valgrind hangs when SIGKILLed
 409367  exit_group() after signal to thread waiting in futex() causes hangs
 410599  Non-deterministic behaviour of pth_self_kill_15_other test
index d6a5a77e6ab58034793c1bcb72bb2857fd38a77b..fbd353aed09acdba7f9897efdda20fe3fcef56c1 100644 (file)
@@ -297,6 +297,21 @@ struct vki_f_owner_ex {
 #define VKI_RLIMIT_CORE                4       /* max core file size */
 #define VKI_RLIMIT_NOFILE      7       /* max number of open files */
 
+//----------------------------------------------------------------------
+// From linux-5.0.0/arch/x86/include/uapi/asm/siginfo.h
+//----------------------------------------------------------------------
+
+/* We need that to ensure that sizeof(siginfo) == 128. */
+#ifdef __x86_64__
+# ifdef __ILP32__
+typedef long long __vki_kernel_si_clock_t __attribute__((aligned(4)));
+#  define __VKI_ARCH_SI_CLOCK_T             __vki_kernel_si_clock_t
+#  define __VKI_ARCH_SI_ATTRIBUTES          __attribute__((aligned(8)))
+# else
+#  define __VKI_ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
+# endif
+#endif
+
 //----------------------------------------------------------------------
 // From linux-2.6.9/include/asm-x86_64/socket.h
 //----------------------------------------------------------------------
index ecea8cc78203af02596c3eafaa10a91cffcb2981..69fb3ed00cb7aaba39c350d82b7ee20b3b58953f 100644 (file)
@@ -193,6 +193,12 @@ struct vki_sigcontext {
         __vki_u8 __reserved[4096] __attribute__((__aligned__(16)));
 };
 
+//----------------------------------------------------------------------
+// From linux-5.0.0/arch/arm64/include/uapi/asm/siginfo.h
+//----------------------------------------------------------------------
+
+#define __VKI_ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
+
 //----------------------------------------------------------------------
 // From linux-3.10.5/uapi/include/asm-generic/mman-common.h
 //----------------------------------------------------------------------
index 6024f2165baebd8d8965dbc0f98ad59f6023bc46..6903c77db8b29065b3e89eaadc1b86d177c80651 100644 (file)
@@ -426,6 +426,14 @@ typedef union vki_sigval {
 #define __VKI_ARCH_SI_BAND_T long
 #endif
 
+#ifndef __VKI_ARCH_SI_CLOCK_T
+#define __VKI_ARCH_SI_CLOCK_T vki_clock_t
+#endif
+
+#ifndef __VKI_ARCH_SI_ATTRIBUTES
+#define __VKI_ARCH_SI_ATTRIBUTES
+#endif
+
 // [[Nb: this type changed between 2.4 and 2.6, but not in a way that
 // affects Valgrind.]]
 typedef struct vki_siginfo {
@@ -463,8 +471,8 @@ typedef struct vki_siginfo {
                        vki_pid_t _pid;         /* which child */
                        __VKI_ARCH_SI_UID_T _uid;       /* sender's uid */
                        int _status;            /* exit code */
-                       vki_clock_t _utime;
-                       vki_clock_t _stime;
+                       __VKI_ARCH_SI_CLOCK_T _utime;
+                       __VKI_ARCH_SI_CLOCK_T _stime;
                } _sigchld;
 
                /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
@@ -481,7 +489,7 @@ typedef struct vki_siginfo {
                        int _fd;
                } _sigpoll;
        } _sifields;
-} vki_siginfo_t;
+} __VKI_ARCH_SI_ATTRIBUTES vki_siginfo_t;
 #endif
 
 #define __VKI_SI_FAULT 0
index a5e64dd392041599e041f05b48b6fb473c4909d8..04f72048aa489d39fd245b3248beaaa33b050d30 100644 (file)
@@ -335,6 +335,14 @@ struct vki_sigcontext {
   long             vmx_reserve[VKI_ELF_NVRREG+VKI_ELF_NVRREG+1];
 };
 
+//----------------------------------------------------------------------
+// From linux-5.0.0/arch/powerpc/include/uapi/asm/siginfo.h
+//----------------------------------------------------------------------
+
+#ifdef __powerpc64__
+# define __VKI_ARCH_SI_PREAMBLE_SIZE     (4 * sizeof(int))
+#endif
+
 //----------------------------------------------------------------------
 // From linux-2.6.13/include/asm-ppc64/mman.h
 //----------------------------------------------------------------------