diff mbox series

[bpf] riscv, bpf: Fix potential NULL dereference

Message ID 20211028125115.514587-1-bjorn@kernel.org (mailing list archive)
State Accepted
Commit 27de809a3d83a6199664479ebb19712533d6fd9b
Delegated to: BPF
Headers show
Series [bpf] riscv, bpf: Fix potential NULL dereference | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag present in non-next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf
netdev/subject_prefix success Link
netdev/cc_maintainers warning 11 maintainers not CCed: paul.walmsley@sifive.com john.fastabend@gmail.com aou@eecs.berkeley.edu yhs@fb.com songliubraving@fb.com xi.wang@gmail.com luke.r.nels@gmail.com kafai@fb.com kpsingh@kernel.org andrii@kernel.org palmer@dabbelt.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Fixes tag looks correct
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf fail VM_Test
bpf/vmtest-bpf-PR fail PR summary

Commit Message

Björn Töpel Oct. 28, 2021, 12:51 p.m. UTC
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")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 arch/riscv/net/bpf_jit_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


base-commit: 72f898ca0ab85fde6facf78b14d9f67a4a7b32d1

Comments

Jakub Kicinski Oct. 28, 2021, 3:16 p.m. UTC | #1
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")
> Signed-off-by: Björn Töpel <bjorn@kernel.org>

Looks pretty trivial so applied to net with Daniel's off-list blessing.
patchwork-bot+netdevbpf@kernel.org Oct. 28, 2021, 3:40 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

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")
> Signed-off-by: Björn Töpel <bjorn@kernel.org>
> 
> [...]

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!
diff mbox series

Patch

diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
index 0fee2cbaaf53..753d85bdfad0 100644
--- a/arch/riscv/net/bpf_jit_core.c
+++ b/arch/riscv/net/bpf_jit_core.c
@@ -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;
 	}