| Issue |
237975
|
| Summary |
[AArch64][PAC] Signed-GOT load of an ifunc is authenticated with IA, but the PAuth ABI (and lld) sign non-STT_FUNC slots with DA
|
| Labels |
|
| Assignees |
|
| Reporter |
zjy-dev
|
PAUTHELF64 ("Default signing schema") says: signed GOT entries use the `IA` key for symbols of type `STT_FUNC`
and the `DA` key for all other symbol types. An `ifunc` is `STT_GNU_IFUNC`. However, `AArch64AsmPrinter::LowerLOADgotAUTH`
selects the key from the IR value type (`getValueType()->isFunctionTy()`), so it emits `autia` for the ifunc slot. lld follows
the ABI and encodes DA in that slot, so the address of an ifunc taken under `-fptrauth-elf-got` fails authentication.
```c
static void impl(void) {}
static void *resolver(void) { return (void *)impl; }
void ifn(void) __attribute__((ifunc("resolver"))); /* STT_GNU_IFUNC */
extern void efn(void); /* STT_FUNC (control) */
extern int edata; /* data (control) */
void *take_ifunc(void) { return (void *)&ifn; }
void *take_func(void) { return (void *)&efn; }
int *take_data(void) { return &edata; }
```
Compile flag: `clang --target=aarch64-linux-pauthtest -march=armv8.3-a -O2 -fPIC -fptrauth-elf-got -c t.c && ld.lld -shared t.o`
```
take_ifunc: adrp x17, :got_auth:ifn ; autia x16, x17 # IA
take_func: adrp x17, :got_auth:efn ; autia x16, x17 # IA (STT_FUNC, ok)
take_data: adrp x17, :got_auth:edata; autda x16, x17 # DA (ok)
symbol types: IFUNC ifn / FUNC efn / NOTYPE edata
lld -shared .got (AUTH_GLOB_DAT): 205b0 ifn -> ...a0 (DA) 205b8 efn -> ...80 (IA) 205c0 edata -> ...a0 (DA)
lld -pie: ifn slot is a plain R_AARCH64_IRELATIVE (unsigned) in .got.plt, still read with autia
```
At run time, both the -shared and the -pie layout make `take_ifunc` fail `autia` and reach `brk #0xc470`, even though the
program is valid. `llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:3063-3064`:
`IsFunctionTy = GAMO.getGlobal()->getValueType()->isFunctionTy(); AuthKey = IsFunctionTy ? IA : DA;`. A `GlobalIFunc`
has a function value type but is emitted as `STT_GNU_IFUNC`. lld (`SyntheticSections.cpp:591`, `sym.isFunc()` ==
`STT_FUNC`) implements the ABI rule. For non-preemptible ifuncs, lld also does not yet support `R_AARCH64_AUTH_IRELATIVE`
(`Relocations.cpp:1270`). This reproduces with clang trunk (Compiler Explorer, `autia` on `:got_auth:ifn`).
**Suggested fix:** select the key from the symbol type that will be emitted (`isa<GlobalIFunc>` -> DA), or clarify the ABI
for `STT_GNU_IFUNC` and make lld agree. Either way, the compiler and lld must use the same rule, and lld should not emit
an unsigned IRELATIVE for an AUTH GOT slot.
Environment: clang/lld 23.1.2 (llvmorg-23.1.2), target aarch64-unknown-linux-pauthtest.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs