From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kaleshsingh@google.com
Subject: [LTP] [PATCH 4/4] signal06: Allocate the alternate signal stack with mmap()
Date: Wed, 11 Nov 2026 09:31:51 +0000 [thread overview]
Message-ID: <20261111093151.374731-5-wakel@google.com> (raw)
In-Reply-To: <20261111093151.374731-1-wakel@google.com>
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.567.gdb80ae8cd5-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-11-11 9:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 9:31 [LTP] [PATCH 0/4] Don't derive kernel granularities from getpagesize() Wake Liu via ltp
2026-11-11 9:31 ` [LTP] [PATCH 1/4] epoll_wait06, fcntl35: Don't assume a pipe buffer is getpagesize() Wake Liu via ltp
2026-11-11 9:31 ` [LTP] [PATCH 2/4] memcg, userfaultfd07: Populate whole pages instead of single bytes Wake Liu via ltp
2026-11-11 9:31 ` [LTP] [PATCH 3/4] ioctl10: Compare vma_page_size with KernelPageSize from smaps Wake Liu via ltp
2026-11-11 9:31 ` Wake Liu via ltp [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261111093151.374731-5-wakel@google.com \
--to=ltp@lists.linux.it \
--cc=kaleshsingh@google.com \
--cc=wakel@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox