Skip to content

Commit 90caccd

Browse files
4astdavem330
authored andcommitted
bpf: fix bpf_tail_call() x64 JIT
- 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 96eabe7 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. Signed-off-by: Alexei Starovoitov <[email protected]> Fixes: 96eabe7 ("bpf: Allow selecting numa node during map creation") Fixes: b52f00e ("x86: bpf_jit: implement bpf_tail_call() helper") Acked-by: Daniel Borkmann <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0594687 commit 90caccd

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

arch/x86/net/bpf_jit_comp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ static void emit_bpf_tail_call(u8 **pprog)
284284
/* if (index >= array->map.max_entries)
285285
* goto out;
286286
*/
287-
EMIT4(0x48, 0x8B, 0x46, /* mov rax, qword ptr [rsi + 16] */
287+
EMIT2(0x89, 0xD2); /* mov edx, edx */
288+
EMIT3(0x39, 0x56, /* cmp dword ptr [rsi + 16], edx */
288289
offsetof(struct bpf_array, map.max_entries));
289-
EMIT3(0x48, 0x39, 0xD0); /* cmp rax, rdx */
290290
#define OFFSET1 43 /* number of bytes to jump */
291291
EMIT2(X86_JBE, OFFSET1); /* jbe out */
292292
label1 = cnt;

include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ union bpf_attr {
312312
* jump into another BPF program
313313
* @ctx: context pointer passed to next program
314314
* @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
315-
* @index: index inside array that selects specific program to run
315+
* @index: 32-bit index inside array that selects specific program to run
316316
* Return: 0 on success or negative error
317317
*
318318
* int bpf_clone_redirect(skb, ifindex, flags)

kernel/bpf/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn,
10221022
struct bpf_map *map = (struct bpf_map *) (unsigned long) BPF_R2;
10231023
struct bpf_array *array = container_of(map, struct bpf_array, map);
10241024
struct bpf_prog *prog;
1025-
u64 index = BPF_R3;
1025+
u32 index = BPF_R3;
10261026

10271027
if (unlikely(index >= array->map.max_entries))
10281028
goto out;

0 commit comments

Comments
 (0)