Skip to content

Commit b1ccbc9

Browse files
committed
[AArch64][PAC] Do not execute AUT instructions speculatively
A generic authentication instruction may crash the process on failure. Furthermore, it can be executed conditionally and/or its signing schema can be chosen dynamically. For this reason, while it may be beneficial to permit DCE to remove AUTx16x17 or AUTxMxN instructions unless their results have any uses (at least fake ones, if we just want to check the signature), AUT instructions are not safe to be executed speculatively. As a quick fix for miscompilation possibility, this patch marks AUTxMxN pseudo instruction as having unmodelled side effects.
1 parent 7512ab1 commit b1ccbc9

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ let Predicates = [HasPAuth] in {
21552155
i64imm:$Disc, GPR64:$AddrDisc),
21562156
[], "$AuthVal = $Val">, Sched<[WriteI, ReadI]> {
21572157
let isCodeGenOnly = 1;
2158-
let hasSideEffects = 0;
2158+
let hasSideEffects = 1;
21592159
let mayStore = 0;
21602160
let mayLoad = 0;
21612161
let Size = 32;

llvm/test/CodeGen/AArch64/ptrauth-intrinsic-auth-resign.ll

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,14 @@ define ptr @auth_speculation(i64 %signed, i1 %cond) {
770770
; UNCHECKED-DARWIN-NEXT: autdzb x16
771771
; UNCHECKED-DARWIN-NEXT: [[BB_RETURN]]:
772772
; UNCHECKED-DARWIN-NEXT: ldr x8, [x16]
773-
; UNCHECKED-ELF-NEXT: mov x8, x0
773+
; UNCHECKED-ELF-NEXT: tbz w1, #0, [[BB_ELSE:[A-Za-z0-9_.]+]]
774+
; UNCHECKED-ELF-NEXT: %bb.1:
774775
; UNCHECKED-ELF-NEXT: autdza x0
775-
; UNCHECKED-ELF-NEXT: autdzb x8
776-
; UNCHECKED-ELF-NEXT: tst w1, #0x1
777-
; UNCHECKED-ELF-NEXT: csel x8, x8, x0, eq
778-
; UNCHECKED-ELF-NEXT: ldr x8, [x8]
776+
; UNCHECKED-ELF-NEXT: b [[BB_RETURN:[A-Za-z0-9_.]+]]
777+
; UNCHECKED-ELF-NEXT: [[BB_ELSE]]:
778+
; UNCHECKED-ELF-NEXT: autdzb x0
779+
; UNCHECKED-ELF-NEXT: [[BB_RETURN]]:
780+
; UNCHECKED-ELF-NEXT: ldr x8, [x0]
779781
; UNCHECKED-NEXT: ldr x8, [x8]
780782
; UNCHECKED-NEXT: ldr x8, [x8]
781783
; UNCHECKED-NEXT: ldr x0, [x8]
@@ -792,12 +794,14 @@ define ptr @auth_speculation(i64 %signed, i1 %cond) {
792794
; CHECKED-DARWIN-NEXT: autdzb x16
793795
; CHECKED-DARWIN-NEXT: [[BB_RETURN]]:
794796
; CHECKED-DARWIN-NEXT: ldr x8, [x16]
795-
; CHECKED-ELF-NEXT: mov x8, x0
797+
; CHECKED-ELF-NEXT: tbz w1, #0, [[BB_ELSE:[A-Za-z0-9_.]+]]
798+
; CHECKED-ELF-NEXT: %bb.1:
796799
; CHECKED-ELF-NEXT: autdza x0
797-
; CHECKED-ELF-NEXT: autdzb x8
798-
; CHECKED-ELF-NEXT: tst w1, #0x1
799-
; CHECKED-ELF-NEXT: csel x8, x8, x0, eq
800-
; CHECKED-ELF-NEXT: ldr x8, [x8]
800+
; CHECKED-ELF-NEXT: b [[BB_RETURN:[A-Za-z0-9_.]+]]
801+
; CHECKED-ELF-NEXT: [[BB_ELSE]]:
802+
; CHECKED-ELF-NEXT: autdzb x0
803+
; CHECKED-ELF-NEXT: [[BB_RETURN]]:
804+
; CHECKED-ELF-NEXT: ldr x8, [x0]
801805
; CHECKED-NEXT: ldr x8, [x8]
802806
; CHECKED-NEXT: ldr x8, [x8]
803807
; CHECKED-NEXT: ldr x0, [x8]
@@ -826,24 +830,26 @@ define ptr @auth_speculation(i64 %signed, i1 %cond) {
826830
; TRAP-DARWIN-NEXT: [[L]]auth_success_19:
827831
; TRAP-DARWIN-NEXT: [[BB_RETURN]]:
828832
; TRAP-DARWIN-NEXT: ldr x8, [x16]
829-
; TRAP-ELF-NEXT: mov x8, x0
833+
; TRAP-ELF-NEXT: tbz w1, #0, [[BB_ELSE:[A-Za-z0-9_.]+]]
834+
; TRAP-ELF-NEXT: %bb.1:
830835
; TRAP-ELF-NEXT: autdza x0
831-
; TRAP-ELF-NEXT: mov x9, x0
832-
; TRAP-ELF-NEXT: xpacd x9
833-
; TRAP-ELF-NEXT: cmp x0, x9
836+
; TRAP-ELF-NEXT: mov x8, x0
837+
; TRAP-ELF-NEXT: xpacd x8
838+
; TRAP-ELF-NEXT: cmp x0, x8
834839
; TRAP-ELF-NEXT: b.eq [[L]]auth_success_18
835840
; TRAP-ELF-NEXT: brk #0xc472
836841
; TRAP-ELF-NEXT: [[L]]auth_success_18:
837-
; TRAP-ELF-NEXT: autdzb x8
838-
; TRAP-ELF-NEXT: mov x9, x8
839-
; TRAP-ELF-NEXT: xpacd x9
840-
; TRAP-ELF-NEXT: cmp x8, x9
842+
; TRAP-ELF-NEXT: b [[BB_RETURN:[A-Za-z0-9_.]+]]
843+
; TRAP-ELF-NEXT: [[BB_ELSE]]:
844+
; TRAP-ELF-NEXT: autdzb x0
845+
; TRAP-ELF-NEXT: mov x8, x0
846+
; TRAP-ELF-NEXT: xpacd x8
847+
; TRAP-ELF-NEXT: cmp x0, x8
841848
; TRAP-ELF-NEXT: b.eq [[L]]auth_success_19
842849
; TRAP-ELF-NEXT: brk #0xc473
843850
; TRAP-ELF-NEXT: [[L]]auth_success_19:
844-
; TRAP-ELF-NEXT: tst w1, #0x1
845-
; TRAP-ELF-NEXT: csel x8, x8, x0, eq
846-
; TRAP-ELF-NEXT: ldr x8, [x8]
851+
; TRAP-ELF-NEXT: [[BB_RETURN]]:
852+
; TRAP-ELF-NEXT: ldr x8, [x0]
847853
; TRAP-NEXT: ldr x8, [x8]
848854
; TRAP-NEXT: ldr x8, [x8]
849855
; TRAP-NEXT: ldr x0, [x8]

0 commit comments

Comments
 (0)