diff mbox series

[bpf-next] bpf, x86_64: fail gracefully on bpf_jit_binary_pack_finalize failures

Message ID 20220208062533.3802081-1-song@kernel.org (mailing list archive)
State Accepted
Commit f95f768f0af4cec806ce86cd67934a10617d96d0
Delegated to: BPF
Headers show
Series [bpf-next] bpf, x86_64: fail gracefully on bpf_jit_binary_pack_finalize failures | expand

Checks

Context Check Description
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: songliubraving@fb.com; 14 maintainers not CCed: hpa@zytor.com bp@alien8.de kpsingh@kernel.org yoshfuji@linux-ipv6.org john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com x86@kernel.org dsahern@kernel.org dave.hansen@linux.intel.com yhs@fb.com mingo@redhat.com tglx@linutronix.de davem@davemloft.net
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 93 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Song Liu Feb. 8, 2022, 6:25 a.m. UTC
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>
---
 arch/x86/net/bpf_jit_comp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Alexei Starovoitov Feb. 8, 2022, 5:28 p.m. UTC | #1
On Mon, Feb 7, 2022 at 10:26 PM Song Liu <song@kernel.org> wrote:
>
> 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>
> ---
>  arch/x86/net/bpf_jit_comp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 643f38b91e30..08e8fd8f954a 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -2380,7 +2380,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
>                          *
>                          * Both cases are serious bugs that we should not continue.

I tweaked that comment a bit, since it's no longer accurate and
pushed to bpf-next.
Thanks!

>                          */
> -                       BUG_ON(bpf_jit_binary_pack_finalize(prog, header, rw_header));
> +                       if (WARN_ON(bpf_jit_binary_pack_finalize(prog, header, rw_header))) {
> +                               prog = orig_prog;
> +                               goto out_addrs;
> +                       }
> +
>                         bpf_tail_call_direct_fixup(prog);
>                 } else {
>                         jit_data->addrs = addrs;
> --
> 2.30.2
>
patchwork-bot+netdevbpf@kernel.org Feb. 8, 2022, 5:30 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Mon, 7 Feb 2022 22:25:33 -0800 you wrote:
> 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>
> ---
>  arch/x86/net/bpf_jit_comp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Here is the summary with links:
  - [bpf-next] bpf, x86_64: fail gracefully on bpf_jit_binary_pack_finalize failures
    https://git.kernel.org/bpf/bpf-next/c/f95f768f0af4

You are awesome, thank you!
Song Liu Feb. 8, 2022, 5:34 p.m. UTC | #3
> On Feb 8, 2022, at 9:28 AM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> 
> On Mon, Feb 7, 2022 at 10:26 PM Song Liu <song@kernel.org> wrote:
>> 
>> 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>
>> ---
>> arch/x86/net/bpf_jit_comp.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>> 
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> index 643f38b91e30..08e8fd8f954a 100644
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
>> @@ -2380,7 +2380,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
>>                         *
>>                         * Both cases are serious bugs that we should not continue.
> 
> I tweaked that comment a bit, since it's no longer accurate and
> pushed to bpf-next.
> Thanks!

Thanks for the fix! I had that in mind initially, but forgot about it
when I got to the keyboard. 

Song
diff mbox series

Patch

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 643f38b91e30..08e8fd8f954a 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -2380,7 +2380,11 @@  struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
 			 *
 			 * Both cases are serious bugs that we should not continue.
 			 */
-			BUG_ON(bpf_jit_binary_pack_finalize(prog, header, rw_header));
+			if (WARN_ON(bpf_jit_binary_pack_finalize(prog, header, rw_header))) {
+				prog = orig_prog;
+				goto out_addrs;
+			}
+
 			bpf_tail_call_direct_fixup(prog);
 		} else {
 			jit_data->addrs = addrs;