As reported by lwhsu and mw on -current, lib.libc.sys.setrlimit_test.setrlimit_stack fails after ASLR was enabled by default Process with PID 5957 exited with signal 11 and dumped core; attempting to gather stack trace [New LWP 101941] Core was generated by `setrlimit_test'. Program terminated with signal SIGSEGV, Segmentation fault. Invalid permissions for mapped object. #0 0x00002acc27fa3bc0 in ?? () #0 0x00002acc27fa3bc0 in ?? () Backtrace stopped: Cannot access memory at address 0x7fffff8bde68 GDB exited successfully Files left in work directory after failure: setrlimit_test.core
Source reference: contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
This issue is caused by the way setrlimit handles stack gap. Currently setrlimit does know about stack gap, however only the rlim_cur value is adjusted taking into consideration the size of the stack gap. rlim_max is a hard limit, so we don't adjust it. This test sets stack both rlim_cur and rlim_max to around 4MiB. By default stack gap that FreeBSD has can be as big as 3% of maximum stack size, so for amd64 this is around 15M. Because of that, when trying to set stack limit to 4M, in most cases the test will receive SIGSEGV immediately when exiting the syscall. Adjusting the resource limit from 4M to a value higher than maximum stack gap size should resolve this problem.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=dad71022bd7a8f95ab2ba656bec61e2424a1c3c5 commit dad71022bd7a8f95ab2ba656bec61e2424a1c3c5 Author: Li-Wen Hsu <lwhsu@FreeBSD.org> AuthorDate: 2021-11-28 06:58:21 +0000 Commit: Li-Wen Hsu <lwhsu@FreeBSD.org> CommitDate: 2021-11-28 06:58:21 +0000 Disable flaky test lib.libc.sys.setrlimit_test.setrlimit_stack PR: 259969 Sponsored by: The FreeBSD Foundation contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c | 3 +++ 1 file changed, 3 insertions(+)
base 4f741801d86089a1c5d631ba1e0f1421cdcf7a7e
By the way, lib/libc/regex/exhaust_test:regcomp_too_big also fails often when ASLR stack_gap is enabled, apparently due to stack overflow. (This test also runs under lib/libregex.)
(In reply to Eric van Gyzen from comment #5) Yep, that's PR 259971.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=7bd2df8c82e863396ae96ad4c43418c762e9f702 commit 7bd2df8c82e863396ae96ad4c43418c762e9f702 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-01-14 19:58:56 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-01-14 19:58:56 +0000 Revert "Disable flaky test lib.libc.sys.setrlimit_test.setrlimit_stack" The stack gap implementation is disabled by default now, so the test passes. This reverts commit dad71022bd7a8f95ab2ba656bec61e2424a1c3c5. PR: 259969 MFC after: 1 week Sponsored by: The FreeBSD Foundation contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c | 3 --- 1 file changed, 3 deletions(-)
Closing for now, the stack gap rework will avoid regressing this test again.