csu: Teach csu about PAC and BTI

Add the Branch Target Identification (BTI) note to libc assembly
sources and Pointer Authentication Code (PAC) instructions to _init and
_fini.

_init and _fini may be called indirectly so need a BTI landing pad. As
they are non-leaf functions use the appropriate PAC instruction that
also guards against changing the link register.

As all object files need the note for any binary using these object files
we need to insert it in all asm files.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42227
This commit is contained in:
Andrew Turner 2023-10-12 11:03:37 +01:00
parent 95335dd3c1
commit 522126fea7
6 changed files with 30 additions and 0 deletions

View file

@ -30,6 +30,8 @@
*/
#include <machine/asm.h>
#include <sys/elf_common.h>
/*
* The program entry point
* void _start(char **ap, void (*cleanup)(void)) __dead2
@ -62,3 +64,5 @@ eprol:
END(_start)
.section .note.GNU-stack,"",@progbits
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)

View file

@ -28,11 +28,14 @@
*/
#include <machine/asm.h>
#include <sys/elf_common.h>
.section .init,"ax",@progbits
.align 4
.globl _init
.type _init,@function
_init:
PAC_LR_SIGN
stp x29, x30, [sp, #-16]!
mov x29, sp
@ -41,6 +44,8 @@ _init:
.globl _fini
.type _fini,@function
_fini:
PAC_LR_SIGN
stp x29, x30, [sp, #-16]!
mov x29, sp
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)

View file

@ -28,13 +28,19 @@
*/
#include <machine/asm.h>
#include <sys/elf_common.h>
.section .init,"ax",@progbits
ldp x29, x30, [sp], #16
PAC_LR_AUTH
ret
.section .fini,"ax",@progbits
ldp x29, x30, [sp], #16
PAC_LR_AUTH
ret
.section .note.GNU-stack,"",%progbits
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)

View file

@ -47,3 +47,8 @@
4:
.section .note.GNU-stack,"",%progbits
#ifdef __aarch64__
/* This is needed in all objects for BTI to be used in the linked elf file */
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
#endif

View file

@ -40,3 +40,8 @@
4:
.section .note.GNU-stack,"",%progbits
#ifdef __aarch64__
/* This is needed in all objects for BTI to be used in the linked elf file */
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
#endif

View file

@ -41,3 +41,8 @@
4:
.section .note.GNU-stack,"",%progbits
#ifdef __aarch64__
/* This is needed in all objects for BTI to be used in the linked elf file */
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
#endif