Commit graph

25 commits

Author SHA1 Message Date
Elliott Hughes
86968d95f1 setjmp_test: riscv64 does have callee-save fp registers.
The setjmp implementation is correct, but this comment was wrong, and we were missing the implementation of the test. This would be slightly simpler if we enabled Zfa in the build system and qemu, but this works for now.

Change-Id: Iad32771019584beacd8b35138ac2bf4c0a14c903
2024-06-03 18:38:10 +00:00
Yi Kong
11f696ad00 Use vmov.f64 for SET_FREG
When implemented using fcpyd, Clang sometimes generates redundant vmovs
after SET_FREGS on ARM32 and touches registers set, causing the test to
fail. Use vmov.f64 instead and that avoids the issue.

Test: atest CtsBionicTestCases:setjmp#setjmp_fp_registers -- --abi armeabi-v7a
Test: atest CtsBionicTestCases:setjmp#setjmp_fp_registers -- --abi arm64-v8a
Bug: 337903801
Change-Id: Ibd89b120f8a3cc80c34905069469fd244a902d1e
2024-05-15 15:29:29 +09:00
Peter Collingbourne
25a7c3fd57 Fix setjmp.bug_152210274 with HWASan/stack MTE enabled.
This test was flaky because there was no synchronization between the end
of the test function scope and the jumper threads, resulting in a racy
use-after-scope when accessing the thread array. Fix it by joining the
threads before leaving the test function scope.

Replace the thread array access, which can race with the store to the
thread array in the main thread, with an access to a pre-initialized
variable, which acts as a kind of enforcement that the threads are done
before leaving the test.

Bug: 227390656
Change-Id: Icfbb0d7cae66c12e5ce31072c34529e3c5fdf563
2023-03-22 13:49:53 -07:00
Colin Cross
23b986c0c8 Fix bionic tests for undefined __SIGRTMIN in musl
Musl doesn't export __SIGRTMIN, and it is being removed from the
Android wrappers to avoid accidentally referencing bionic's
reserved signals when compiling against musl.

Bug: 190084016
Test: m USE_HOST_MUSL=true host-native -k
Change-Id: I342666a17abc31bbc57b383b5cc881c2752886f7
2022-10-20 13:16:21 -07:00
Elliott Hughes
e1905ed629 riscv64 setjmp.
Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Signed-off-by: Xia Lifang <lifang_xia@linux.alibaba.com>
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com>
Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
Signed-off-by: Lu Xufan <luxufan@iscas.ac.cn>
Test: m
Change-Id: I02cf117f67bda74516e4de8cd6f4c05efdb9a85b
2022-10-17 23:23:36 +00:00
Florian Mayer
4817ca64bb Skip setjmp.bug_152210274 on HWASan.
Bug: 227390656
Change-Id: Ic6dc89d844bab4aba93132b3af7942961d3af644
2022-04-15 23:15:26 +00:00
Elliott Hughes
141b917018 Switch to libbase SilentDeathTest.
Bug: http://b/184955378
Test: treehugger
Change-Id: Ie0849224074da92203340a741a86a24a4a3702c2
2021-04-12 10:01:20 -07:00
Elliott Hughes
14ab353e19 Use GTEST_SKIP() rather than GTEST_LOG_() when skipping.
Test: treehugger
Change-Id: I74dca1882c002a51c9758fe7282b10c4413ecb03
2021-04-08 20:59:50 -07:00
Elliott Hughes
c0d41db92e setjmp/longjmp: avoid invalid values in the stack pointer.
arm64 was already being careful, but x86/x86-64 and 32-bit ARM could be
caught by a signal in a state where the stack pointer was mangled.

For 32-bit ARM I've taken care with the link register too, to avoid
potential issues with unwinding.

Bug: http://b/152210274
Test: treehugger
Change-Id: I1ce285b017a633c732dbe04743368f4cae27af85
2021-04-05 17:43:36 -07:00
Elliott Hughes
e657eb4f8a Fix some bionic death tests.
These were creating tombstones and spewing to the log.

You need TEST_F() rather than TEST(), and the modern style is apparently
to use `using` rather than an empty subclass.

Bug: http://b/180605583
Test: run tests, check logcat
Change-Id: I1e639d34854aeff6f042c24643b769a6bcfab877
2021-02-18 17:23:04 -08:00
Elliott Hughes
6a65ccdf52 Remove mips test workarounds.
The mips/mips64 targets were never able to pass these tests, and the
supported architectures don't need any of these workarounds.

Test: treehugger
Change-Id: I640a8b7a98ae13d9d9cdb09b0fbef61d31d4c79a
2020-02-13 09:48:14 -08:00
Peter Collingbourne
734beec3d4 Allocate a small guard region around the shadow call stack.
This lets us do two things:

1) Make setjmp and longjmp compatible with shadow call stack.
   To avoid leaking the shadow call stack address into memory, only the
   lower log2(SCS_SIZE) bits of x18 are stored to jmp_buf. This requires
   allocating an additional guard page so that we're guaranteed to be
   able to allocate a sufficiently aligned SCS.

2) SCS overflow detection. Overflows now result in a SIGSEGV instead
   of corrupting the allocation that comes after it.

Change-Id: I04d6634f96162bf625684672a87fba8b402b7fd1
Test: bionic-unit-tests
2018-11-16 14:37:08 -08:00
Josh Gao
baf20fc912 Block TIMER_SIGNAL in sigprocmask(SIG_SETMASK, ...).
Previously, we were zeroing out the reserved signals, when we actually
wanted to have TIMER_SIGNAL always be blocked, and the other signals
always be unblocked. This resulted in process termination when a
SIGEV_THREAD timer callback calls sigprocmask(SIG_SETMASK, ...) with
any signal mask value, and then subsequently fails to complete its
callback and reach the sigtimedwait in bionic before the next timer
iteration triggers.

Add a how argument to filter_reserved_signals to appropriately
block/unblock our reserved signals.

Bug: http://b/116783733
Test: bionic-unit-tests32/64
Change-Id: Ie5339682cdeb914711cd4089cd26ee395704d0df
2018-10-09 16:27:22 -07:00
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Elliott Hughes
71ba5899ae Rewrite system(3) to use posix_spawn(3).
We saw crashes from pthread_exit+debuggerd on LP32
(https://issuetracker.google.com/72291624), and it seems like the
equivalent problem should exist with system(3). I fixed posix_spawn(3)
as part of that bug, so the easiest fix is probably to reuse that.

Bug: http://b/72470344
Test: ran tests
Change-Id: I05f838706f2b4a14ac3ee21292833e6c8579b0d4
2018-03-05 17:20:12 -08:00
Elliott Hughes
460130b7d0 Fix sigsetjmp/siglongjmp to save/restore RT signals on arm/x86 too.
Our arm and x86 ABIs shipped with a 32-bit `sigset_t`, so we need to
use sigprocmask64 to save/restore the RT signals too. (This is important
because several are in use by the system, and the behavior of our 32-bit
`sigset_t` is to clear the RT signals.)

Bug: http://b/72493232
Test: ran tests
Change-Id: Idff91f8b2849276e5a3073d07eccd84e02a34410
2018-01-31 17:47:16 -08:00
Predrag Blagojevic
3299590dfe Add a checksum to jmp_buf on mips and mips64.
Make it easier to diagnose applications mucking with the contents of
jmp_buf by checksumming its contents.

Bug: http://b/27417786
Change-Id: I473bc2871dece23a9b9d02481945246160d671c6
2016-03-28 14:54:49 +00:00
Josh Gao
a4c69137c6 Add a checksum to jmp_buf on ARM.
Make it easier to diagnose applications mucking with the contents of
jmp_buf by checksumming its contents.

Bug: http://b/27417786
Change-Id: I9989e2ea3979a36ae0bc4c9e1bacafddbacc731b
2016-03-03 12:45:08 -08:00
Nikola Veljkovic
1b519c0ae4 Implement setjmp cookies on MIPS and MIPS64
Bug: http://b/23942752
Change-Id: Ie58892a97b5075d30d7607667251007cda99d38c
2015-10-09 13:42:58 +02:00
Josh Gao
7fda8d2aa4 Implement setjmp cookies on ARM.
Reuse the top bits of _JB_SIGFLAG field previously used to store a
boolean to store a cookie that's validated by [sig]longjmp to make it
harder to use as a ROP gadget. Additionally, encrypt saved registers
with the cookie so that an attacker can't modify a register's value to
a specific value without knowing the cookie.

Bug: http://b/23942752
Change-Id: Id0eb8d06916e89d5d776bfcaa9458f8826717ba3
2015-09-17 14:07:24 -07:00
Elliott Hughes
87dd503018 Add a test for float registers across setjmp/logjmp.
Change-Id: I17cc056b185755e0b91de096b5ceefee4f4e0b3a
2015-01-26 20:52:34 -08:00
Elliott Hughes
1510a1c1ae Fix the setjmp tests for mips.
Although the LP32 mips sigset_t is large enough to represent all signals,
their jmp_buf is too small. This test succeeded on arm and x86 because the
RT signals were never in the 'expected' sigset_t, so the equality comparison
with the 'actual' sigset_t worked fine --- everyone was blind to the RT
signal. On mips the tests fail because the 'expected' sigset_t does contain
the RT signal but the 'actual' doesn't because the jmp_buf only saves and
restores the first 32 signals.

There are 32 free bits (currently used as padding) in the LP32 mips jmp_buf,
and they might choose to use those to provide better support than the other
two platforms, but I'll leave that to them. It will be easy to just remove
the #if defined(__LP64__) from this change in that case.

For mips64 it's not to late to increase the size of the jmp_buf and fix
the setjmp family, but since there are decisions to be made here for LP32,
I'll leave it all to Imagination folks...

Bug: 16918359
Change-Id: I6b723712fce0e9210dafa165d8599d950b2d3500
2014-12-10 11:48:19 -08:00
Elliott Hughes
1c0c0ede57 Fix signal mask save/restore for x86-64.
Bug: 16918359
Change-Id: I30bf61e7d5f1c21daa3a1a21d361e98d77220bf3
2014-12-08 12:46:15 -08:00
Yabin Cui
e323e99ffb restore sigprocmask in setjmp/longjmp test.
Bug: 18571921
Change-Id: Ib8ca7a36abd3ccc729c20c0e32d45b1b33069f65
2014-12-02 10:35:25 -08:00
Yongqin Liu
9fea4090f1 bionic tests: add setjmp/_setjmp/sigsetjmp tests.
Bug: 17288973
Change-Id: I2808eee58cbddae1b16fbe19a715b72d6dbaaec3
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2014-11-26 17:31:24 -08:00