| Issue |
237862
|
| Summary |
[AArch64][PAC] Calling a function pointer held in a data-key __ptrauth slot authenticates with IA instead of the slot's DA/DB key
|
| Labels |
|
| Assignees |
|
| Reporter |
zjy-dev
|
A function pointer stored through `__ptrauth(ptrauth_key_process_dependent_data, 1, 42)` is signed with `pacdb`.
When it is called, clang attaches the operand bundle `"ptrauth"(i32 3, ...)` (key DB). The AArch64 backend only
supports IA and IB for authenticated calls: it checks the key with an `assert` and picks the opcode with `Key == IB`.
In a release build, key DB therefore becomes `braa`/`blraa` (IA). The call always fails authentication, and the
program does not run correctly.
```c
#include <ptrauth.h>
typedef int (*fn_t)(void);
static int target(void) { return 7; }
fn_t __ptrauth(ptrauth_key_process_dependent_data, 1, 42) slot;
__attribute__((noinline)) int call_slot(void) { return slot(); }
/* _start: slot = target; exit(call_slot()); -- full file in poc/trigger.c */
```
Compile flag: `clang --target=aarch64-linux-pauthtest -march=armv8.3-a -O2 -fno-ptrauth-returns -nostdlib -static trigger.c`
```
== IR: call-site bundle key (3 = DB)
%3 = tail call i32 %1() #5 [ "ptrauth"(i32 3, i64 %2) ]
== asm: sign on store vs. authenticate on call
call_slot:
braa x1, x16 # IA key
_start:
pacdb x8, x16 # DB key
== run (qemu-aarch64 -cpu max, 10s limit)
IA-key control: exit=7
DB-key trigger: exit=137 (expected 7) # killed: never returns from the mis-authenticated branch
```
`llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:10789-10791` only has
`assert((Key == IA || Key == IB) && "Invalid auth call key")`, and the opcode tables (`AArch64InstrInfo.h:830-845`) are
indexed by `K == IB`, so DA/DB silently become IA. Neither Sema nor the IR Verifier rejects a `ptrauth` call bundle with a
data key, and `EmitCallee` (`clang/lib/CodeGen/CGExpr.cpp:6628-6643`) passes the qualifier's key through unchanged.
This reproduces with clang trunk for `arm64e-apple-ios` (Compiler Explorer: `pacdb` on store, `braa` on call).
**Suggested fix:** in clang, when the callee's `__ptrauth` key is not an instruction key, emit `auth` + a plain call (or
re-sign to IA) instead of a bundle. In LLVM, have the Verifier or ISel reject `ptrauth` call bundles with keys other than IA/IB,
rather than relying on an assert.
Environment: clang 23.1.2 (llvmorg-23.1.2), targets aarch64-unknown-linux-pauthtest and arm64e-apple-ios.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs