]> git.ipfire.org Git - thirdparty/gcc.git/commit
aarch64: fix __builtin_eh_return with pac-ret [PR94891]
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 4 Jun 2020 12:42:16 +0000 (13:42 +0100)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Mon, 17 Aug 2020 16:17:29 +0000 (13:17 -0300)
commit35d0774f492394d42e8d1407e8b0f96d74791591
tree5f4e139e92083d195ff7ebb6c44f553c29460f7c
parenta9b4f77cea3cf4224417ab10b48fa52afad95c3f
aarch64: fix __builtin_eh_return with pac-ret [PR94891]

Currently __builtin_eh_return takes a signed return address, which can
cause ABI and API issues: 1) pointer representation problems if the
address is passed around before eh return, 2) the source code needs
pac-ret specific changes and needs to know if pac-ret is used in the
current frame, 3) signed address may not be representible as void *
(with ilp32 abi).

Using address signing to protect eh return is ineffective because the
instruction sequence in the unwinder that starts from the address
signing and ends with a ret can be used as a return to anywhere gadget.
Using indirect branch istead of ret with bti j landing pads at the
target can reduce the potential of such gadget, which also implies
that __builtin_eh_return should not take a signed address.

This is a big hammer fix to the ABI and API issues: it turns pac-ret
off for the caller completely (not just on the eh return path).  To
harden the caller against ROP attacks, it should use indirect branch
instead of ret, this is not attempted so the patch remains small and
backportable.

2020-07-13  Szabolcs Nagy  <szabolcs.nagy@arm.com>

gcc/ChangeLog:

PR target/94891
* config/aarch64/aarch64.c (aarch64_return_address_signing_enabled):
Disable return address signing if __builtin_eh_return is used.

gcc/testsuite/ChangeLog:

PR target/94891
* gcc.target/aarch64/return_address_sign_1.c: Update test.
* gcc.target/aarch64/return_address_sign_b_1.c: Likewise.
gcc/config/aarch64/aarch64.c
gcc/testsuite/gcc.target/aarch64/return_address_sign_1.c
gcc/testsuite/gcc.target/aarch64/return_address_sign_b_1.c