Patch "bpf, arm64: fix jit branch offset related to ldimm64" has been added to the 4.9-stable tree
Subsystems (5)
This is a note to let you know that I've just added the patch titled
bpf, arm64: fix jit branch offset related to ldimm64
to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
bpf-arm64-fix-jit-branch-offset-related-to-ldimm64.patch
and it can be found in the queue-4.9 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Thu May 11 11:08:24 CEST 2017
From: Daniel Borkmann <[email protected]>
Date: Tue, 2 May 2017 20:34:54 +0200
Subject: bpf, arm64: fix jit branch offset related to ldimm64
From: Daniel Borkmann <[email protected]>
[ Upstream commit ddc665a4bb4b728b4e6ecec8db1b64efa9184b9c ]
When the instruction right before the branch destination is a 64 bit load immediate, we currently calculate the wrong jump offset in the ctx->offset[] array as we only account one instruction slot for the 64 bit load immediate although it uses two BPF instructions. Fix it up by setting the offset into the right slot after we incremented the index.
Before (ldimm64 test 1):
[...]
00000020: 52800007 mov w7, #0x0 // #0 00000024: d2800060 mov x0, #0x3 // #3 00000028: d2800041 mov x1, #0x2 // #2 0000002c: eb01001f cmp x0, x1 00000030: 54ffff82 b.cs 0x00000020 00000034: d29fffe7 mov x7, #0xffff // #65535 00000038: f2bfffe7 movk x7, #0xffff, lsl #16 0000003c: f2dfffe7 movk x7, #0xffff, lsl #32 00000040: f2ffffe7 movk x7, #0xffff, lsl #48 00000044: d29dddc7 mov x7, #0xeeee // #61166 00000048: f2bdddc7 movk x7, #0xeeee, lsl #16 0000004c: f2ddddc7 movk x7, #0xeeee, lsl #32 00000050: f2fdddc7 movk x7, #0xeeee, lsl #48
[...]
After (ldimm64 test 1):
[...]
00000020: 52800007 mov w7, #0x0 // #0 00000024: d2800060 mov x0, #0x3 // #3 00000028: d2800041 mov x1, #0x2 // #2 0000002c: eb01001f cmp x0, x1 00000030: 540000a2 b.cs 0x00000044 00000034: d29fffe7 mov x7, #0xffff // #65535 00000038: f2bfffe7 movk x7, #0xffff, lsl #16 0000003c: f2dfffe7 movk x7, #0xffff, lsl #32 00000040: f2ffffe7 movk x7, #0xffff, lsl #48 00000044: d29dddc7 mov x7, #0xeeee // #61166 00000048: f2bdddc7 movk x7, #0xeeee, lsl #16 0000004c: f2ddddc7 movk x7, #0xeeee, lsl #32 00000050: f2fdddc7 movk x7, #0xeeee, lsl #48
[...]
Also, add a couple of test cases to make sure JITs pass this test. Tested on Cavium ThunderX ARMv8. The added test cases all pass after the fix.
--- arch/arm64/net/bpf_jit_comp.c | 8 +++---- lib/test_bpf.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-)
arch/arm64/net/bpf_jit_comp.c +4 -4
@@ -779,14 +779,14 @@ static int build_body(struct jit_ctx *ctint ret; ret =build_insn (insn, ctx); - -if (ctx->image ==NULL ) - ctx->offset[i] = ctx->idx; -if (ret >0 ) { i++; +if (ctx->image ==NULL ) + ctx->offset[i] = ctx->idx;continue ; } +if (ctx->image ==NULL ) + ctx->offset[i] = ctx->idx;if (ret)return ret; }
lib/test_bpf.c +45 -0
51 lines not on this page · raw message
Patches currently in stable-queue which might be from [email protected] are
queue-4.9/bpf-arm64-fix-jit-branch-offset-related-to-ldimm64.patch queue-4.9/bpf-don-t-let-ldimm64-leak-map-addresses-on-unprivileged.patch queue-4.9/bpf-enhance-verifier-to-understand-stack-pointer-arithmetic.patch