]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: fix potential error return
authorAnton Protopopov <aspsk@isovalent.com>
Tue, 10 Dec 2024 11:42:45 +0000 (11:42 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 10 Dec 2024 19:17:53 +0000 (11:17 -0800)
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>
kernel/bpf/core.c

index 6fa8041d48318dbc3bc5c7e02994ee8411c68b91..da729cbbaeb90cba9eb8ad3b615486e546eae800 100644 (file)
@@ -539,6 +539,8 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
 
 int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt)
 {
+       int err;
+
        /* Branch offsets can't overflow when program is shrinking, no need
         * to call bpf_adj_branches(..., true) here
         */
@@ -546,7 +548,9 @@ int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt)
                sizeof(struct bpf_insn) * (prog->len - off - cnt));
        prog->len -= cnt;
 
-       return WARN_ON_ONCE(bpf_adj_branches(prog, off, off + cnt, off, false));
+       err = bpf_adj_branches(prog, off, off + cnt, off, false);
+       WARN_ON_ONCE(err);
+       return err;
 }
 
 static void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp)