Skip to content

Commit c4441ca

Browse files
aspskAlexei Starovoitov
authored andcommitted
bpf: fix potential error return
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 <aspsk@isovalent.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20241210114245.836164-1-aspsk@isovalent.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent cf8b876 commit c4441ca

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
@@ -539,14 +539,18 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
539539

540540
int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt)
541541
{
542+
int err;
543+
542544
/* Branch offsets can't overflow when program is shrinking, no need
543545
* to call bpf_adj_branches(..., true) here
544546
*/
545547
memmove(prog->insnsi + off, prog->insnsi + off + cnt,
546548
sizeof(struct bpf_insn) * (prog->len - off - cnt));
547549
prog->len -= cnt;
548550

549-
return WARN_ON_ONCE(bpf_adj_branches(prog, off, off + cnt, off, false));
551+
err = bpf_adj_branches(prog, off, off + cnt, off, false);
552+
WARN_ON_ONCE(err);
553+
return err;
550554
}
551555

552556
static void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp)

0 commit comments

Comments
 (0)