Skip to content

Commit 5c63188

Browse files
Xu KuohaiNobody
Xu Kuohai
authored and
Nobody
committed
bpf, arm64: sign return address for jited code
Sign return address for jited code when the kernel is built with pointer authentication enabled. 1. Sign lr with paciasp instruction before lr is pushed to stack. Since paciasp acts like landing pads for function entry, no need to insert bti instruction before paciasp. 2. Authenticate lr with autiasp instruction after lr is poped from stack. Signed-off-by: Xu Kuohai <[email protected]>
1 parent 1d8b458 commit 5c63188

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

arch/arm64/net/bpf_jit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@
249249
/* HINTs */
250250
#define A64_HINT(x) aarch64_insn_gen_hint(x)
251251

252+
#define A64_PACIASP A64_HINT(AARCH64_INSN_HINT_PACIASP)
253+
#define A64_AUTIASP A64_HINT(AARCH64_INSN_HINT_AUTIASP)
254+
252255
/* BTI */
253256
#define A64_BTI_C A64_HINT(AARCH64_INSN_HINT_BTIC)
254257
#define A64_BTI_J A64_HINT(AARCH64_INSN_HINT_BTIJ)

arch/arm64/net/bpf_jit_comp.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static bool is_addsub_imm(u32 imm)
192192
}
193193

194194
/* Tail call offset to jump into */
195-
#if IS_ENABLED(CONFIG_ARM64_BTI_KERNEL)
195+
#if IS_ENABLED(CONFIG_ARM64_BTI_KERNEL) || IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL)
196196
#define PROLOGUE_OFFSET 8
197197
#else
198198
#define PROLOGUE_OFFSET 7
@@ -233,8 +233,11 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
233233
*
234234
*/
235235

236+
/* Sign lr */
237+
if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL))
238+
emit(A64_PACIASP, ctx);
236239
/* BTI landing pad */
237-
if (IS_ENABLED(CONFIG_ARM64_BTI_KERNEL))
240+
else if (IS_ENABLED(CONFIG_ARM64_BTI_KERNEL))
238241
emit(A64_BTI_C, ctx);
239242

240243
/* Save FP and LR registers to stay align with ARM64 AAPCS */
@@ -529,6 +532,10 @@ static void build_epilogue(struct jit_ctx *ctx)
529532
/* Set return value */
530533
emit(A64_MOV(1, A64_R(0), r0), ctx);
531534

535+
/* Authenticate lr */
536+
if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL))
537+
emit(A64_AUTIASP, ctx);
538+
532539
emit(A64_RET(A64_LR), ctx);
533540
}
534541

0 commit comments

Comments
 (0)