]> granicus.if.org Git - strace/commitdiff
signal: fix decoding of struct old_sigaction on some architectures
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)
On alpha, struct old_sigaction.sa_flags has a 32-bit type.

On mips, only first word of old_sigaction.sa_mask is read.

On all architectures except alpha and mips that have old sigaction
syscall, struct old_sigaction has sa_restorer field that has to be
decoded.

* signal.c (struct old_sigaction) [ALPHA]: Change sa_flags type
to unsigned int, add ATTRIBUTE_PACKED.
[MIPS]: Dhrink sa_mask array to 1 element.
[!ALPHA && !MIPS]: Define sa_restorer field unconditionally.
(struct old_sigaction32): Likewise.
(decode_old_sigaction) [!current_wordsize]: Initialize sa_restorer field
from old_sigaction32.sa_restorer unconditionally.
[!ALPHA && !MIPS]: Print old_sigaction.sa_restorer if SA_RESTORER flag
is set.
* NEWS: Mention this change.

NEWS
signal.c

diff --git a/NEWS b/NEWS
index 20f8640f095ba8bd12248f6d27d6b615f999316a..8d0d4a5b71e3d151d0ba77a7a895b26704a4b965 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Noteworthy changes in release ?.?? (????-??-??)
   * strace no longer resets SIGCHLD handler in tracees to the default action.
   * When traced command is terminated by a blocked signal, strace unblocks
     that signal to ensure its own termination with the same signal.
+  * Fixed corner cases in decoding of old sigaction syscall.
 
 Noteworthy changes in release 4.17 (2017-05-24)
 ===============================================
index c8b0a5f595649474aea2f4d981d0b320a50e16c6..5f6650f2de6eefe9122b5e41e395a4b2791c3ab0 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -300,29 +300,32 @@ SYS_FUNC(ssetmask)
 
 struct old_sigaction {
        /* sa_handler may be a libc #define, need to use other name: */
-#ifdef MIPS
+#if defined MIPS
        unsigned int sa_flags;
        unsigned long sa_handler__;
-       /* Kernel treats sa_mask as an array of longs. */
-       unsigned long sa_mask[NSIG / sizeof(long)];
+       unsigned long sa_mask;
+#elif defined ALPHA
+       unsigned long sa_handler__;
+       unsigned long sa_mask;
+       unsigned int sa_flags;
 #else
        unsigned long sa_handler__;
        unsigned long sa_mask;
        unsigned long sa_flags;
-#endif /* !MIPS */
-#if HAVE_SA_RESTORER
        unsigned long sa_restorer;
 #endif
-};
+}
+#ifdef ALPHA
+       ATTRIBUTE_PACKED
+#endif
+;
 
 struct old_sigaction32 {
        /* sa_handler may be a libc #define, need to use other name: */
        uint32_t sa_handler__;
        uint32_t sa_mask;
        uint32_t sa_flags;
-#if HAVE_SA_RESTORER
        uint32_t sa_restorer;
-#endif
 };
 
 static void
@@ -340,9 +343,7 @@ decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
                memset(&sa, 0, sizeof(sa));
                sa.sa_handler__ = sa32.sa_handler__;
                sa.sa_flags = sa32.sa_flags;
-#if HAVE_SA_RESTORER && defined SA_RESTORER
                sa.sa_restorer = sa32.sa_restorer;
-#endif
                sa.sa_mask = sa32.sa_mask;
        } else
 #endif
@@ -352,15 +353,11 @@ decode_old_sigaction(struct tcb *const tcp, const kernel_ulong_t addr)
        tprints("{sa_handler=");
        print_sa_handler(sa.sa_handler__);
        tprints(", sa_mask=");
-#ifdef MIPS
-       tprintsigmask_addr("", sa.sa_mask);
-#else
        tprintsigmask_val("", sa.sa_mask);
-#endif
        tprints(", sa_flags=");
        printflags(sigact_flags, sa.sa_flags, "SA_???");
-#if HAVE_SA_RESTORER && defined SA_RESTORER
-       if (sa.sa_flags & SA_RESTORER) {
+#if !(defined ALPHA || defined MIPS)
+       if (sa.sa_flags & 0x04000000U) {
                tprints(", sa_restorer=");
                printaddr(sa.sa_restorer);
        }