https://chromium.googlesource.com/v8/v8/+/f0e1ca1449e03d55f6a1aacfe93933aa0c5b3157commit f0e1ca1449e03d55f6a1aacfe93933aa0c5b3157
Author: Pierre Langlois <
pierre....@arm.com>
Date: Wed Mar 29 14:28:27 2023
[arm64][cfi] Use xpaclri instruction to check authentication status
The AuthenticatePC() and ReplacePC() pointer-authentication utilities
are written so that they should cause a crash in case the authentication
fails. We use the `autib1716` instruction to do the authentication,
however this instruction isn't guaranteed to cause a crash. Instead, it
may yield an invalid pointer which is then guaranteed to cause a crash
on use.
To ensure that we crash as soon as possible in the case of a failed
authentication, we have a load instruction on the result:
;; Place result in x17.
autib1716
;; Ensure that x17 can be dereferenced.
ldr xzr, [x17]
However, this approach does not always work, for two reasons:
- The address at `x17` may not be dereferenceable. This can happen
when using ReplacePC(), which ensures that the previous address is
correctly authenticated before replacing it. However the GC may have
reclaimed the memory the previous address points to.
- The `ldr` instruction is a *data* load, while the address at `x17`
is an instruction address. The specification only guarantees that
`autib1716` generates an invalid *instruction* pointer, and the only
way to ensure it is valid is to use it via a call instruction, not a
data load.
This can happen if TBI (top-byte-ignore) is disabled for instruction
addresses but enabled on data addresses. In this case, a failed
authentication of an instruction address will be indicated by a bit
set in the TBI range. It then will *not* cause a crash when used
with `ldr`, as it's a *data* load subject to TBI.
To fix this, this CL uses an alternative sequence to check if the
authentication is successful, by using the `xpaclri` instruction.
Bug: v8:10026
Change-Id: Ie1e4bff380fca226beb29d3dfe27e48d87ec736c
Reviewed-on:
https://chromium-review.googlesource.com/c/v8/v8/+/4381728Commit-Queue: Pierre Langlois <
pierre....@arm.com>
Reviewed-by: Igor Sheludko <
ish...@chromium.org>
Cr-Commit-Position: refs/heads/main@{#86782}
[modify]
https://crrev.com/f0e1ca1449e03d55f6a1aacfe93933aa0c5b3157/test/unittests/BUILD.gn[add]
https://crrev.com/f0e1ca1449e03d55f6a1aacfe93933aa0c5b3157/test/unittests/execution/pointer-auth-arm64-unittest.cc[modify]
https://crrev.com/f0e1ca1449e03d55f6a1aacfe93933aa0c5b3157/src/execution/arm64/pointer-authentication-arm64.h[delete]
https://crrev.com/4f94782e87a227072295dde051c50634af3eda05/test/unittests/codegen/pointer-auth-arm64-unittest.cc