Patch "bpf: fix bpf_tail_call() x64 JIT" has been added to the 4.13-stable tree
Subsystems (5)
This is a note to let you know that I've just added the patch titled
bpf: fix bpf_tail_call() x64 JIT
to the 4.13-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-fix-bpf_tail_call-x64-jit.patch
and it can be found in the queue-4.13 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 Mon Oct 9 09:32:35 CEST 2017
From: Alexei Starovoitov <[email protected]>
Date: Tue, 3 Oct 2017 15:37:20 -0700
Subject: bpf: fix bpf_tail_call() x64 JIT
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 90caccdd8cc0215705f18b92771b449b01e2474a ]
- bpf prog_array just like all other types of bpf array accepts 32-bit index. Clarify that in the comment.
- fix x64 JIT of bpf_tail_call which was incorrectly loading 8 instead of 4 bytes
- tighten corresponding check in the interpreter to stay consistent
The JIT bug can be triggered after introduction of BPF_F_NUMA_NODE flag in commit 96eabe7a40aa in 4.14. Before that the map_flags would stay zero and though JIT code is wrong it will check bounds correctly.
Hence two fixes tags. All other JITs don't have this problem.
--- arch/x86/net/bpf_jit_comp.c | 4 ++-- include/uapi/linux/bpf.h | 2 +- kernel/bpf/core.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/net/bpf_jit_comp.c +2 -2
@@ -282,9 +282,9 @@ static void emit_bpf_tail_call(u8 **ppro/* if (index >= array->map.max_entries) * goto out; */ -EMIT4 (0x48 ,0x8B ,0x46 ,/* mov rax, qword ptr [rsi + 16] */ +EMIT2 (0x89 ,0xD2 );/* mov edx, edx */ +EMIT3 (0x39 ,0x56 ,/* cmp dword ptr [rsi + 16], edx */ offsetof(struct bpf_array, map.max_entries)); -EMIT3 (0x48 ,0x39 ,0xD0 );/* cmp rax, rdx */ #define OFFSET1 47/* number of bytes to jump */ EMIT2 (X86_JBE ,OFFSET1 );/* jbe out */ label1 = cnt;
include/uapi/linux/bpf.h +1 -1
@@ -294,7 +294,7 @@ union bpf_attr {* jump into another BPF program * @ctx: context pointer passed to next program * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY -* @index: index inside array that selects specific program to run +* @index: 32-bit index inside array that selects specific program to run * Return: 0 on success or negative error * * int bpf_clone_redirect(skb, ifindex, flags)
kernel/bpf/core.c +1 -1
@@ -1010,7 +1010,7 @@ select_insn:struct bpf_map *map = (struct bpf_map *) (unsigned long )BPF_R2 ; struct bpf_array *array = container_of(map, struct bpf_array, map);struct bpf_prog *prog; -u64 index =BPF_R3 ; +u32 index =BPF_R3 ;if (unlikely (index >= array->map.max_entries)) goto out;
Patches currently in stable-queue which might be from [email protected] are
queue-4.13/bpf-fix-bpf_tail_call-x64-jit.patch