[LTP] [PATCH v2 4/4] signal06: Allocate the alternate signal stack with mmap()
Wake Liu
wakel@google.com
Mon Nov 16 15:22:06 CET 2026
The test mprotect()s the alternate signal stack, which is a statically
allocated array of 4096 * 10 bytes aligned to 4096 bytes. That only
works if the page size is 4096 bytes. With a larger page size,
mprotect() either fails with EINVAL because the stack is not page
aligned or, since the length gets rounded up to the page size, also
write protects the variables placed after the array. The main thread
then faults on them over and over again and the test hangs until it
times out.
That happens with the 16K page size emulation that Android uses on
x86_64. With the stack at 0x53c000, mprotect() of its 40960 bytes
covers memory up to 0x548000 and the main thread keeps faulting right
after the end of the stack:
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x546008}
Allocate the stack with mmap() and size it based on getpagesize().
Nothing changes with a 4096 byte page size.
Signed-off-by: Wake Liu <wakel@google.com>
---
testcases/kernel/syscalls/signal/signal06.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/syscalls/signal/signal06.c b/testcases/kernel/syscalls/signal/signal06.c
index cf0706ea4..e464fc661 100644
--- a/testcases/kernel/syscalls/signal/signal06.c
+++ b/testcases/kernel/syscalls/signal/signal06.c
@@ -48,6 +48,7 @@
#include <errno.h>
#include "test.h"
+#include "tso_safe_macros.h"
#include "lapi/syscalls.h"
char *TCID = "signal06";
@@ -61,7 +62,8 @@ int TST_TOTAL = 5;
volatile double D;
volatile int FLAGE;
-char altstack[4096 * 10] __attribute__((aligned(4096)));
+static char *altstack;
+static size_t altstack_size;
void test(void)
{
@@ -99,12 +101,12 @@ void *tfunc(void *arg LTP_ATTRIBUTE_UNUSED)
for (i = -1; ; i *= -1) {
if (i == -1) {
- TEST(mprotect(altstack, sizeof(altstack), PROT_READ));
+ TEST(mprotect(altstack, altstack_size, PROT_READ));
if (TEST_RETURN == -1)
tst_brkm(TBROK | TTERRNO, NULL, "mprotect failed");
}
- TEST(mprotect(altstack, sizeof(altstack), PROT_READ | PROT_WRITE));
+ TEST(mprotect(altstack, altstack_size, PROT_READ | PROT_WRITE));
if (TEST_RETURN == -1)
tst_brkm(TBROK | TTERRNO, NULL, "mprotect failed");
@@ -120,9 +122,14 @@ int main(int ac, char **av)
tst_parse_opts(ac, av, NULL, NULL);
+ /* mprotect() needs the stack to be aligned to the runtime page size */
+ altstack_size = getpagesize() * 10;
+ altstack = SAFE_MMAP(NULL, NULL, altstack_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
stack_t st = {
.ss_sp = altstack,
- .ss_size = sizeof(altstack),
+ .ss_size = altstack_size,
.ss_flags = SS_ONSTACK,
};
--
2.56.0.611.g1030f0b940-goog
More information about the ltp
mailing list