Bug 259969 - lib.libc.sys.setrlimit_test.setrlimit_stack fails with ASLR on by default
Summary: lib.libc.sys.setrlimit_test.setrlimit_stack fails with ASLR on by default
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: tests (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks: 259968
  Show dependency treegraph
 
Reported: 2021-11-21 16:05 UTC by Ed Maste
Modified: 2022-01-14 20:40 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2021-11-21 16:05:48 UTC
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
Comment 1 Ed Maste freebsd_committer freebsd_triage 2021-11-21 20:23:57 UTC
Source reference: contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
Comment 2 Dawid Gorecki 2021-11-21 22:47:05 UTC
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.
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-11-28 07:00:45 UTC
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(+)
Comment 4 Li-Wen Hsu freebsd_committer freebsd_triage 2021-12-20 06:26:38 UTC
base 4f741801d86089a1c5d631ba1e0f1421cdcf7a7e
Comment 5 Eric van Gyzen freebsd_committer freebsd_triage 2022-01-13 22:49:10 UTC
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.)
Comment 6 Mark Johnston freebsd_committer freebsd_triage 2022-01-14 14:05:06 UTC
(In reply to Eric van Gyzen from comment #5)
Yep, that's PR 259971.
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-01-14 20:39:39 UTC
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(-)
Comment 8 Mark Johnston freebsd_committer freebsd_triage 2022-01-14 20:40:58 UTC
Closing for now, the stack gap rework will avoid regressing this test again.