Skip to content

Commit 75ed436

Browse files
committed
[AArch64] PAUTH_PROLOGUE should not be duplicated with PAuthLR
When using PAuthLR, the PAUTH_PROLOGUE expands into a sequence of instructions which takes the address of one of those instructions, and uses that address to compute the return address signature. If this is duplicated, there will be two different addresses used in calculating the signature, so the epilogue will only be correct for (at most) one of them. This change also restricts code generation when using v8.3-A return address signing, without PAuthLR. This isn't strictly needed, as duplicating the prologue there would be valid. We could fix this by having two copies of PAUTH_PROLOGUE, with and without isNotDuplicable, but I don't think it's worth adding the extra complexity to a security feature for that.
1 parent 5f99333 commit 75ed436

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,12 @@ def : InstAlias<"xpaclri", (XPACLRI), 0>;
17731773

17741774
let Uses = [LR, SP], Defs = [LR] in {
17751775
// Insertion point of LR signing code.
1776-
def PAUTH_PROLOGUE : Pseudo<(outs), (ins), []>, Sched<[]>;
1776+
def PAUTH_PROLOGUE : Pseudo<(outs), (ins), []>, Sched<[]> {
1777+
// When using PAuthLR, the address of one of the instructions this expands
1778+
// into is used as an input to the signature calculation, so this must not be
1779+
// duplicated.
1780+
let isNotDuplicable = 1;
1781+
}
17771782
// Insertion point of LR authentication code.
17781783
// The RET terminator of the containing machine basic block may be replaced
17791784
// with a combined RETA(A|B) instruction when rewriting this Pseudo.

llvm/test/CodeGen/AArch64/pauthlr-prologue-duplication.mir

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@ body: |
2525
; CHECK-NEXT: CBZW renamable $w0, %bb.1
2626
; CHECK-NEXT: {{ $}}
2727
; CHECK-NEXT: bb.2:
28-
; CHECK-NEXT: successors: %bb.5(0x30000000), %bb.4(0x50000000)
28+
; CHECK-NEXT: successors: %bb.3(0x80000000)
2929
; CHECK-NEXT: liveins: $w0, $w1, $lr
3030
; CHECK-NEXT: {{ $}}
31+
; CHECK-NEXT: B %bb.3
32+
; CHECK-NEXT: {{ $}}
33+
; CHECK-NEXT: bb.1:
34+
; CHECK-NEXT: successors: %bb.3(0x80000000)
35+
; CHECK-NEXT: liveins: $w1, $lr
36+
; CHECK-NEXT: {{ $}}
37+
; CHECK-NEXT: renamable $w8 = MOVZWi 1, 0
38+
; CHECK-NEXT: {{ $}}
39+
; CHECK-NEXT: bb.3:
40+
; CHECK-NEXT: successors: %bb.5(0x30000000), %bb.4(0x50000000)
41+
; CHECK-NEXT: liveins: $w1, $w8, $lr
42+
; CHECK-NEXT: {{ $}}
3143
; CHECK-NEXT: frame-setup PAUTH_PROLOGUE implicit-def $lr, implicit killed $lr, implicit $sp
3244
; CHECK-NEXT: CBZW killed renamable $w1, %bb.5
3345
; CHECK-NEXT: {{ $}}
@@ -40,15 +52,6 @@ body: |
4052
; CHECK-NEXT: BL @f, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp
4153
; CHECK-NEXT: frame-destroy PAUTH_EPILOGUE implicit-def $lr, implicit killed $lr, implicit $sp
4254
; CHECK-NEXT: TCRETURNdi @f, 0, csr_aarch64_aapcs, implicit $sp
43-
; CHECK-NEXT: {{ $}}
44-
; CHECK-NEXT: bb.1:
45-
; CHECK-NEXT: successors: %bb.5(0x30000000), %bb.4(0x50000000)
46-
; CHECK-NEXT: liveins: $w1, $lr
47-
; CHECK-NEXT: {{ $}}
48-
; CHECK-NEXT: renamable $w8 = MOVZWi 1, 0
49-
; CHECK-NEXT: frame-setup PAUTH_PROLOGUE implicit-def $lr, implicit killed $lr, implicit $sp
50-
; CHECK-NEXT: CBNZW killed renamable $w1, %bb.4
51-
; CHECK-NEXT: B %bb.5
5255
bb.0.entry:
5356
successors: %bb.1(0x30000000), %bb.2(0x50000000)
5457
liveins: $w0, $w1, $lr

0 commit comments

Comments
 (0)