Skip to content

Commit 11d3d2f

Browse files
billatarmcherrymui
authored andcommitted
cmd/internal/obj/arm64: add support for PAC instructions
Add support for the Pointer Authentication Code instructions required for the ELF ABI when enabling PAC aware binaries. This allows for assembly writers to add PAC instructions where needed to support this ABI. Follow up work is to enable the compiler to emit these instructions in the appropriate places. The TL;DR for the Linux ABI is that the prologue of a function that pushes the link register (LR) to the stack, signs the LR with a key managed by the operating system and hardware using a PAC instruction, like "paciasp". The function epilog, when restoring the LR from the stack will verify the signature, using an instruction like "autiasp". This helps prevents attackers from modifying the return address on the stack, a common technique for ROP attacks. Details on PAC can be found here: - https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64 - https://developer.arm.com/documentation/109576/0100/Pointer-Authentication-Code The ABI details can be found here: - https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst Change-Id: I4516ed1294d19f9ff9d278833d542821b6642aa9 Reviewed-on: https://go-review.googlesource.com/c/go/+/676675 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Joel Sing <joel@sing.id.au> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent 4dbf1a5 commit 11d3d2f

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

src/cmd/asm/internal/asm/testdata/arm64.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,4 +1894,12 @@ next:
18941894
BTI J // 9f2403d5
18951895
BTI JC // df2403d5
18961896

1897+
// Pointer Authentication Codes (PAC)
1898+
PACIASP // 3f2303d5
1899+
AUTIASP // bf2303d5
1900+
PACIBSP // 7f2303d5
1901+
AUTIBSP // ff2303d5
1902+
AUTIA1716 // 9f2103d5
1903+
AUTIB1716 // df2103d5
1904+
18971905
END

src/cmd/asm/internal/asm/testdata/arm64error.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,10 @@ TEXT errors(SB),$0
422422
SHA1H V1.B16, V2.B16 // ERROR "invalid operands"
423423
BTI // ERROR "missing operand"
424424
BTI PLDL1KEEP // ERROR "illegal argument"
425+
PACIASP C // ERROR "illegal combination"
426+
AUTIASP R2 // ERROR "illegal combination"
427+
PACIBSP R0 // ERROR "illegal combination"
428+
AUTIBSP C // ERROR "illegal combination"
429+
AUTIA1716 $45 // ERROR "illegal combination"
430+
AUTIB1716 R0 // ERROR "illegal combination"
425431
RET

src/cmd/internal/obj/arm64/a.out.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,12 @@ const (
10201020
AWORD
10211021
AYIELD
10221022
ABTI
1023+
APACIASP
1024+
AAUTIASP
1025+
APACIBSP
1026+
AAUTIBSP
1027+
AAUTIA1716
1028+
AAUTIB1716
10231029
ALAST
10241030
AB = obj.AJMP
10251031
ABL = obj.ACALL

src/cmd/internal/obj/arm64/anames.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,13 @@ func buildop(ctxt *obj.Link) {
30173017
oprangeset(ANOOP, t)
30183018
oprangeset(ADRPS, t)
30193019

3020+
oprangeset(APACIASP, t)
3021+
oprangeset(AAUTIASP, t)
3022+
oprangeset(APACIBSP, t)
3023+
oprangeset(AAUTIBSP, t)
3024+
oprangeset(AAUTIA1716, t)
3025+
oprangeset(AAUTIB1716, t)
3026+
30203027
case ACBZ:
30213028
oprangeset(ACBZW, t)
30223029
oprangeset(ACBNZ, t)
@@ -7016,6 +7023,24 @@ func (c *ctxt7) op0(p *obj.Prog, a obj.As) uint32 {
70167023

70177024
case ASEVL:
70187025
return SYSHINT(5)
7026+
7027+
case APACIASP:
7028+
return SYSHINT(25)
7029+
7030+
case AAUTIASP:
7031+
return SYSHINT(29)
7032+
7033+
case APACIBSP:
7034+
return SYSHINT(27)
7035+
7036+
case AAUTIBSP:
7037+
return SYSHINT(31)
7038+
7039+
case AAUTIA1716:
7040+
return SYSHINT(12)
7041+
7042+
case AAUTIB1716:
7043+
return SYSHINT(14)
70197044
}
70207045

70217046
c.ctxt.Diag("%v: bad op0 %v", p, a)

0 commit comments

Comments
 (0)