Skip to content

Commit cbf25fb

Browse files
committed
[PAC] Support signed GOT and PLT GOT
1 parent 2cb2d9f commit cbf25fb

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

arch/aarch64/reloc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
"mov sp,%1 ; br %0" : : "r"(pc), "r"(sp) : "memory" )
2525

2626
#if __has_feature(ptrauth_calls)
27-
#define TARGET_RELOCATE(dso, type, reladdr, sym, addend, is_phase_2) \
28-
do_target_reloc(dso, type, reladdr, sym, addend, is_phase_2)
27+
#define TARGET_RELOCATE(dso, type, reladdr, sym, addend, is_phase_2, error_sym) \
28+
do_target_reloc(dso, type, reladdr, sym, addend, is_phase_2, error_sym)
2929
#define DO_TARGET_RELR(dso, dyn) do_pauth_relr(dso, dyn)
3030

31-
int do_target_reloc(int type, uint64_t* reladdr, uint64_t base,
32-
uint64_t symval, uint64_t addend, int is_phase_2);
31+
int do_target_reloc(int type, uint64_t* reladdr, uint64_t base, uint64_t symval,
32+
uint64_t addend, int is_phase_2, uint64_t error_sym);
3333

3434
void do_pauth_relr(uint64_t base, uint64_t* dyn);
3535

ldso/dynlink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
485485
case REL_GOT:
486486
case REL_PLT:
487487
*reloc_addr = sym_val + addend;
488+
TARGET_RELOCATE(type, reloc_addr, (size_t)base, sym_val, addend, head == &ldso, (uint64_t)error);
488489
break;
489490
case REL_USYMBOLIC:
490491
memcpy(reloc_addr, &(size_t){sym_val + addend}, sizeof(size_t));
@@ -565,7 +566,7 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
565566
#endif
566567
break;
567568
default:
568-
if (TARGET_RELOCATE(type, reloc_addr, (size_t)base, sym_val, addend, head == &ldso))
569+
if (TARGET_RELOCATE(type, reloc_addr, (size_t)base, sym_val, addend, head == &ldso, (uint64_t)error))
569570
break;
570571
error("Error relocating %s: unsupported relocation type %d",
571572
dso->name, type);

src/ldso/aarch64/reloc.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include "reloc.h"
55

66
#define R_AARCH64_AUTH_ABS64 0x244
7+
// Define R_AARCH64_JUMP_SLOT manually to avoid including elf.h
8+
#define R_AARCH64_JUMP_SLOT 0x402
79
#define R_AARCH64_AUTH_RELATIVE 0x411
10+
#define R_AARCH64_AUTH_GLOB_DAT 0xe201
811

12+
#define DT_AARCH64_PAC_PLT 0x70000003
913
#define DT_AARCH64_AUTH_RELRSZ 0x70000011
1014
#define DT_AARCH64_AUTH_RELR 0x70000012
1115
#define DT_AARCH64_AUTH_RELRENT 0x70000013
@@ -66,11 +70,24 @@ static int do_pauth_reloc(uint64_t* reladdr, uint64_t value)
6670
}
6771

6872
int do_target_reloc(int type, uint64_t* reladdr, uint64_t base,
69-
uint64_t symval, uint64_t addend, int is_phase_2)
73+
uint64_t symval, uint64_t addend, int is_phase_2, uint64_t error_sym)
7074
{
75+
if (type == R_AARCH64_JUMP_SLOT) {
76+
*reladdr = do_sign_ia((uint64_t)reladdr, *reladdr);
77+
return 1;
78+
}
79+
if (type == R_AARCH64_AUTH_GLOB_DAT) {
80+
// is_phase_2 is not applicable here
81+
if ((*reladdr & 0xffffffffffffull) == 0)
82+
return do_pauth_reloc(reladdr, symval + addend);
83+
return 1;
84+
}
7185
// We don't process auth relocs until we load all dependencies
7286
if (is_phase_2)
7387
return 1;
88+
// FIXME a horrible hack; we set error = error_impl in __dls3 manually
89+
if (*reladdr == error_sym)
90+
return 1;
7491
switch(type)
7592
{
7693
case R_AARCH64_AUTH_ABS64:

0 commit comments

Comments
 (0)