[PATCH] linux-user: Move TARGET_SA_RESTORER out of generic/signal.h

Andreas Schwab posted 1 patch 1 month, 3 weeks ago
linux-user/aarch64/target_signal.h    | 2 ++
linux-user/arm/target_signal.h        | 2 ++
linux-user/generic/signal.h           | 1 -
linux-user/i386/target_signal.h       | 2 ++
linux-user/m68k/target_signal.h       | 1 +
linux-user/microblaze/target_signal.h | 2 ++
linux-user/ppc/target_signal.h        | 2 ++
linux-user/s390x/target_signal.h      | 2 ++
linux-user/sh4/target_signal.h        | 2 ++
linux-user/x86_64/target_signal.h     | 2 ++
linux-user/xtensa/target_signal.h     | 2 ++
11 files changed, 19 insertions(+), 1 deletion(-)
[PATCH] linux-user: Move TARGET_SA_RESTORER out of generic/signal.h
Posted by Andreas Schwab 1 month, 3 weeks ago
SA_RESTORER and the associated sa_restorer field of struct sigaction are
an obsolete feature, not expected to be used by future architectures.
They are also absent on RISC-V, LoongArch, Hexagon and OpenRISC, but
defined due to their use of generic/signal.h.  This leads to corrupted
data and out-of-bounds accesses.

Move the definition of TARGET_SA_RESTORER out of generic/signal.h into the
target_signal.h files that need it.  Note that m68k has the sa_restorer
field, but does not use it and does not define SA_RESTORER.

Reported-by: Thomas Weißschuh <thomas@t-8ch.de>
Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 linux-user/aarch64/target_signal.h    | 2 ++
 linux-user/arm/target_signal.h        | 2 ++
 linux-user/generic/signal.h           | 1 -
 linux-user/i386/target_signal.h       | 2 ++
 linux-user/m68k/target_signal.h       | 1 +
 linux-user/microblaze/target_signal.h | 2 ++
 linux-user/ppc/target_signal.h        | 2 ++
 linux-user/s390x/target_signal.h      | 2 ++
 linux-user/sh4/target_signal.h        | 2 ++
 linux-user/x86_64/target_signal.h     | 2 ++
 linux-user/xtensa/target_signal.h     | 2 ++
 11 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h
index 40e399d990..6f66a50bfd 100644
--- a/linux-user/aarch64/target_signal.h
+++ b/linux-user/aarch64/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_SEGV_MTEAERR  8  /* Asynchronous ARM MTE error */
 #define TARGET_SEGV_MTESERR  9  /* Synchronous ARM MTE exception */
 
diff --git a/linux-user/arm/target_signal.h b/linux-user/arm/target_signal.h
index 0e6351d9f7..ff1810b1fe 100644
--- a/linux-user/arm/target_signal.h
+++ b/linux-user/arm/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_ARCH_HAS_SETUP_FRAME
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
diff --git a/linux-user/generic/signal.h b/linux-user/generic/signal.h
index 6fd05b77bb..b34740258e 100644
--- a/linux-user/generic/signal.h
+++ b/linux-user/generic/signal.h
@@ -15,7 +15,6 @@
 #define TARGET_SA_RESTART       0x10000000
 #define TARGET_SA_NODEFER       0x40000000
 #define TARGET_SA_RESETHAND     0x80000000
-#define TARGET_SA_RESTORER      0x04000000
 
 #define TARGET_SIGHUP            1
 #define TARGET_SIGINT            2
diff --git a/linux-user/i386/target_signal.h b/linux-user/i386/target_signal.h
index 9315cba241..eee792ef63 100644
--- a/linux-user/i386/target_signal.h
+++ b/linux-user/i386/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_ARCH_HAS_SETUP_FRAME
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
diff --git a/linux-user/m68k/target_signal.h b/linux-user/m68k/target_signal.h
index 6e0f4b74e3..b05b9303b0 100644
--- a/linux-user/m68k/target_signal.h
+++ b/linux-user/m68k/target_signal.h
@@ -3,6 +3,7 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_ARCH_HAS_SA_RESTORER 1
 #define TARGET_ARCH_HAS_SETUP_FRAME
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
diff --git a/linux-user/microblaze/target_signal.h b/linux-user/microblaze/target_signal.h
index 7dc5c45f00..ffe4442213 100644
--- a/linux-user/microblaze/target_signal.h
+++ b/linux-user/microblaze/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
 #endif /* MICROBLAZE_TARGET_SIGNAL_H */
diff --git a/linux-user/ppc/target_signal.h b/linux-user/ppc/target_signal.h
index 5be24e152b..53fae473f3 100644
--- a/linux-user/ppc/target_signal.h
+++ b/linux-user/ppc/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #if !defined(TARGET_PPC64)
 #define TARGET_ARCH_HAS_SETUP_FRAME
 #endif
diff --git a/linux-user/s390x/target_signal.h b/linux-user/s390x/target_signal.h
index 41e0e34a55..738e0673f4 100644
--- a/linux-user/s390x/target_signal.h
+++ b/linux-user/s390x/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_ARCH_HAS_SETUP_FRAME
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
diff --git a/linux-user/sh4/target_signal.h b/linux-user/sh4/target_signal.h
index eee6a1a7cd..0bde417fd1 100644
--- a/linux-user/sh4/target_signal.h
+++ b/linux-user/sh4/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_ARCH_HAS_SETUP_FRAME
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
diff --git a/linux-user/x86_64/target_signal.h b/linux-user/x86_64/target_signal.h
index 9d9717406f..0af100c661 100644
--- a/linux-user/x86_64/target_signal.h
+++ b/linux-user/x86_64/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 /* For x86_64, use of SA_RESTORER is mandatory. */
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0
 
diff --git a/linux-user/xtensa/target_signal.h b/linux-user/xtensa/target_signal.h
index e4b1bea5cb..8a198bf8ac 100644
--- a/linux-user/xtensa/target_signal.h
+++ b/linux-user/xtensa/target_signal.h
@@ -3,6 +3,8 @@
 
 #include "../generic/signal.h"
 
+#define TARGET_SA_RESTORER      0x04000000
+
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1
 
 #endif
-- 
2.48.1


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

Re: [PATCH] linux-user: Move TARGET_SA_RESTORER out of generic/signal.h
Posted by Richard Henderson 1 month, 2 weeks ago
On 2/10/25 04:59, Andreas Schwab wrote:
> SA_RESTORER and the associated sa_restorer field of struct sigaction are
> an obsolete feature, not expected to be used by future architectures.
> They are also absent on RISC-V, LoongArch, Hexagon and OpenRISC, but
> defined due to their use of generic/signal.h.  This leads to corrupted
> data and out-of-bounds accesses.
> 
> Move the definition of TARGET_SA_RESTORER out of generic/signal.h into the
> target_signal.h files that need it.  Note that m68k has the sa_restorer
> field, but does not use it and does not define SA_RESTORER.
> 
> Reported-by: Thomas Weißschuh <thomas@t-8ch.de>
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>   linux-user/aarch64/target_signal.h    | 2 ++
>   linux-user/arm/target_signal.h        | 2 ++
>   linux-user/generic/signal.h           | 1 -
>   linux-user/i386/target_signal.h       | 2 ++
>   linux-user/m68k/target_signal.h       | 1 +
>   linux-user/microblaze/target_signal.h | 2 ++
>   linux-user/ppc/target_signal.h        | 2 ++
>   linux-user/s390x/target_signal.h      | 2 ++
>   linux-user/sh4/target_signal.h        | 2 ++
>   linux-user/x86_64/target_signal.h     | 2 ++
>   linux-user/xtensa/target_signal.h     | 2 ++
>   11 files changed, 19 insertions(+), 1 deletion(-)

Queued, thanks.


r~

Re: [PATCH] linux-user: Move TARGET_SA_RESTORER out of generic/signal.h
Posted by Thomas Weißschuh 1 month, 2 weeks ago
Hi Andreas,

On 2025-02-10 13:59:34+0100, Andreas Schwab wrote:
> SA_RESTORER and the associated sa_restorer field of struct sigaction are
> an obsolete feature, not expected to be used by future architectures.
> They are also absent on RISC-V, LoongArch, Hexagon and OpenRISC, but
> defined due to their use of generic/signal.h.  This leads to corrupted
> data and out-of-bounds accesses.
> 
> Move the definition of TARGET_SA_RESTORER out of generic/signal.h into the
> target_signal.h files that need it.  Note that m68k has the sa_restorer
> field, but does not use it and does not define SA_RESTORER.
> 
> Reported-by: Thomas Weißschuh <thomas@t-8ch.de>
> Signed-off-by: Andreas Schwab <schwab@suse.de>

Thanks for fixing this properly.

Reviewed-by: Thomas Weißschuh <thomas@t-8ch.de>

> ---
>  linux-user/aarch64/target_signal.h    | 2 ++
>  linux-user/arm/target_signal.h        | 2 ++
>  linux-user/generic/signal.h           | 1 -
>  linux-user/i386/target_signal.h       | 2 ++
>  linux-user/m68k/target_signal.h       | 1 +
>  linux-user/microblaze/target_signal.h | 2 ++
>  linux-user/ppc/target_signal.h        | 2 ++
>  linux-user/s390x/target_signal.h      | 2 ++
>  linux-user/sh4/target_signal.h        | 2 ++
>  linux-user/x86_64/target_signal.h     | 2 ++
>  linux-user/xtensa/target_signal.h     | 2 ++
>  11 files changed, 19 insertions(+), 1 deletion(-)

...

Re: [PATCH] linux-user: Move TARGET_SA_RESTORER out of generic/signal.h
Posted by Richard Henderson 1 month, 3 weeks ago
On 2/10/25 04:59, Andreas Schwab wrote:
> SA_RESTORER and the associated sa_restorer field of struct sigaction are
> an obsolete feature, not expected to be used by future architectures.
> They are also absent on RISC-V, LoongArch, Hexagon and OpenRISC, but
> defined due to their use of generic/signal.h.  This leads to corrupted
> data and out-of-bounds accesses.
> 
> Move the definition of TARGET_SA_RESTORER out of generic/signal.h into the
> target_signal.h files that need it.  Note that m68k has the sa_restorer
> field, but does not use it and does not define SA_RESTORER.
> 
> Reported-by: Thomas Weißschuh<thomas@t-8ch.de>
> Signed-off-by: Andreas Schwab<schwab@suse.de>
> ---
>   linux-user/aarch64/target_signal.h    | 2 ++
>   linux-user/arm/target_signal.h        | 2 ++
>   linux-user/generic/signal.h           | 1 -
>   linux-user/i386/target_signal.h       | 2 ++
>   linux-user/m68k/target_signal.h       | 1 +
>   linux-user/microblaze/target_signal.h | 2 ++
>   linux-user/ppc/target_signal.h        | 2 ++
>   linux-user/s390x/target_signal.h      | 2 ++
>   linux-user/sh4/target_signal.h        | 2 ++
>   linux-user/x86_64/target_signal.h     | 2 ++
>   linux-user/xtensa/target_signal.h     | 2 ++
>   11 files changed, 19 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~