Skip to contentSkip to conversation

bpf, x86_64: fail gracefully on bpf_jit_binary_pack_finalize failures

PATCH Applied Song Liu 4 participants 4 messages Feb 8, 2022

Subsystems (5)
Networking Network drivers x86 BPF +1 more subsystems
lore
Share & tools
lore

Song Liu

author reviewer
#0 lore raw

PATCH 1/1 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")
---
 arch/x86/net/bpf_jit_comp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/net/bpf_jit_comp.c +5 -1
index 643f38b91e30..08e8fd8f954a 100644
@@ -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;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 14 lines · Song Liu

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

Fixes 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")
---
 arch/x86/net/bpf_jit_comp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/net/bpf_jit_comp.c +0 -0
index 643f38b91e30..08e8fd8f954a 100644

arch/x86/net/bpf_jit_comp.c struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) · line 2381

Quoted 2 lines
arch/x86/net/bpf_jit_comp.c +0 -0
@@ -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!

Quoted 13 lines
arch/x86/net/bpf_jit_comp.c +5 -2
                         */
-                       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

#2 lore raw
Quoted 14 lines · Alexei Starovoitov
Quoted 9 lines · Song Liu

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

Fixes 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")

---
arch/x86/net/bpf_jit_comp.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 11 lines

arch/x86/net/bpf_jit_comp.c struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) · line 2381

Quoted 7 lines
arch/x86/net/bpf_jit_comp.c +0 -0
index 643f38b91e30..08e8fd8f954a 100644
@@ -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

#3 lore raw
In reply to Song Liu
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 7 lines · 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")
---
 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html