Skip to contentSkip to conversation

riscv, bpf: Fix potential NULL dereference

PATCH Applied Björn Töpel 3 participants 3 messages Oct 28, 2021

Subsystems (6)
lore
Share & tools
lore

Björn Töpel

author maintainer
#0 lore raw

PATCH 1/1 riscv, bpf: Fix potential NULL dereference

The bpf_jit_binary_free() function requires a non-NULL argument. When the RISC-V BPF JIT fails to converge in NR_JIT_ITERATIONS steps, jit_data->header will be NULL, which triggers a NULL dereference. Avoid this by checking the argument, prior calling the function.

Fixes ca6cb5447cec ("riscv, bpf: Factor common RISC-V JIT code")
---
 arch/riscv/net/bpf_jit_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/net/bpf_jit_core.c +2 -1
index 0fee2cbaaf53..753d85bdfad0 100644
@@ -125,7 +125,8 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
 
 	if (i == NR_JIT_ITERATIONS) {
 		pr_err("bpf-jit: image did not converge in <%d passes!\n", i);
-		bpf_jit_binary_free(jit_data->header);
+		if (jit_data->header)
+			bpf_jit_binary_free(jit_data->header);
 		prog = orig_prog;
 		goto out_offset;
 	}

base-commit: 72f898ca0ab85fde6facf78b14d9f67a4a7b32d1

Signature · 1 line
2.32.0
maintainer
#1 lore raw
Quoted 8 lines · On Thu, 28 Oct 2021 14:51:15 +0200 Björn Töpel wrote:

The bpf_jit_binary_free() function requires a non-NULL argument. When the RISC-V BPF JIT fails to converge in NR_JIT_ITERATIONS steps, jit_data->header will be NULL, which triggers a NULL dereference. Avoid this by checking the argument, prior calling the function.

Fixes ca6cb5447cec ("riscv, bpf: Factor common RISC-V JIT code")

Looks pretty trivial so applied to net with Daniel's off-list blessing.

#2 lore raw
In reply to Björn Töpel
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 28 Oct 2021 14:51:15 +0200 you wrote:

The bpf_jit_binary_free() function requires a non-NULL argument. When the RISC-V BPF JIT fails to converge in NR_JIT_ITERATIONS steps, jit_data->header will be NULL, which triggers a NULL dereference. Avoid this by checking the argument, prior calling the function.

Fixes ca6cb5447cec ("riscv, bpf: Factor common RISC-V JIT code")

[...]

Here is the summary with links:
- [bpf] riscv, bpf: Fix potential NULL dereference

    https://git.kernel.org/netdev/net/c/27de809a3d83

You are awesome, thank you!

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