Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf, x86_64: Fail gracefully on bpf_jit_binary_pack_finalize failures

Instead of BUG_ON(), fail gracefully and return orig_prog.

Fixes: 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220208062533.3802081-1-song@kernel.org

authored by

Song Liu and committed by
Alexei Starovoitov
f95f768f 5d1e9f43

+6 -2
+6 -2
arch/x86/net/bpf_jit_comp.c
··· 2378 2378 * 1) header is not pointing to proper module memory; 2379 2379 * 2) the arch doesn't support bpf_arch_text_copy(). 2380 2380 * 2381 - * Both cases are serious bugs that we should not continue. 2381 + * Both cases are serious bugs and justify WARN_ON. 2382 2382 */ 2383 - BUG_ON(bpf_jit_binary_pack_finalize(prog, header, rw_header)); 2383 + if (WARN_ON(bpf_jit_binary_pack_finalize(prog, header, rw_header))) { 2384 + prog = orig_prog; 2385 + goto out_addrs; 2386 + } 2387 + 2384 2388 bpf_tail_call_direct_fixup(prog); 2385 2389 } else { 2386 2390 jit_data->addrs = addrs;