Skip to content

Commit f53b373

Browse files
aspskgregkh
authored andcommitted
bpf: fix potential error return
[ Upstream commit c4441ca ] The bpf_remove_insns() function returns WARN_ON_ONCE(error), where error is a result of bpf_adj_branches(), and thus should be always 0 However, if for any reason it is not 0, then it will be converted to boolean by WARN_ON_ONCE and returned to user space as 1, not an actual error value. Fix this by returning the original err after the WARN check. Signed-off-by: Anton Protopopov <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 73a30cb commit f53b373

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/bpf/core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,18 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
529529

530530
int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt)
531531
{
532+
int err;
533+
532534
/* Branch offsets can't overflow when program is shrinking, no need
533535
* to call bpf_adj_branches(..., true) here
534536
*/
535537
memmove(prog->insnsi + off, prog->insnsi + off + cnt,
536538
sizeof(struct bpf_insn) * (prog->len - off - cnt));
537539
prog->len -= cnt;
538540

539-
return WARN_ON_ONCE(bpf_adj_branches(prog, off, off + cnt, off, false));
541+
err = bpf_adj_branches(prog, off, off + cnt, off, false);
542+
WARN_ON_ONCE(err);
543+
return err;
540544
}
541545

542546
static void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp)

0 commit comments

Comments
 (0)