bpf: fix potential error return
PATCH 1/1 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.
--- kernel/bpf/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/core.c +5 -1
@@ -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)
Signature · 1 line
2.34.1
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Tue, 10 Dec 2024 11:42:45 +0000 you wrote:
The
bpf_remove_insns()function returnsWARN_ON_ONCE(error), where error is a result ofbpf_adj_branches(), and thus should be always 0 However, if for any reason it is not 0, then it will be converted to boolean byWARN_ON_ONCEand 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]>[...]
Here is the summary with links:
- [bpf] bpf: fix potential error return
https://git.kernel.org/bpf/bpf/c/c4441ca86afe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html