bpf: Fix trampoline generation for fmod_ret programs
authorAlexei Starovoitov <ast@kernel.org>
Wed, 11 Mar 2020 00:39:06 +0000 (17:39 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 11 Mar 2020 13:07:32 +0000 (14:07 +0100)
commit13fac1d851e09109096b5862bf37c3da6908fb48
tree927815f0128976e44e7f0435f52b91dd348ca4ea
parentbabf3164095b0670435910340c2a1eec37757b57
bpf: Fix trampoline generation for fmod_ret programs

fmod_ret progs are emitted as:

start = __bpf_prog_enter();
call fmod_ret
*(u64 *)(rbp - 8) = rax
__bpf_prog_exit(, start);
test eax, eax
jne do_fexit

That 'test eax, eax' is working by accident. The compiler is free to use rax
inside __bpf_prog_exit() or inside functions that __bpf_prog_exit() is calling.
Which caused "test_progs -t modify_return" to sporadically fail depending on
compiler version and kconfig. Fix it by using 'cmp [rbp - 8], 0' instead of
'test eax, eax'.

Fixes: ae24082331d9 ("bpf: Introduce BPF_MODIFY_RETURN")
Reported-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: KP Singh <kpsingh@google.com>
Link: https://lore.kernel.org/bpf/20200311003906.3643037-1-ast@kernel.org
arch/x86/net/bpf_jit_comp.c