Skip to contentSkip to conversation

bpf: Check for helper calls in check_subprogs()

PATCH Applied Ilya Leoshkevich 3 participants 3 messages Feb 20, 2023 – Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Check for helper calls in check_subprogs()

The condition src_reg != BPF_PSEUDO_CALL && imm == BPF_FUNC_tail_call may be satisfied by a kfunc call. This would lead to unnecessarily setting has_tail_call. Use src_reg == 0 instead.

---
 kernel/bpf/verifier.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +2 -2
index e63af41a7e95..6d4632476c9c 100644
@@ -2462,8 +2462,8 @@ static int check_subprogs(struct bpf_verifier_env *env)
 		u8 code = insn[i].code;
 
 		if (code == (BPF_JMP | BPF_CALL) &&
-		    insn[i].imm == BPF_FUNC_tail_call &&
-		    insn[i].src_reg != BPF_PSEUDO_CALL)
+		    insn[i].src_reg == 0 &&
+		    insn[i].imm == BPF_FUNC_tail_call)
 			subprog[cur_subprog].has_tail_call = true;
 		if (BPF_CLASS(code) == BPF_LD &&
 		    (BPF_MODE(code) == BPF_ABS || BPF_MODE(code) == BPF_IND))
Signature · 1 line
2.39.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Ilya Leoshkevich

The condition src_reg != BPF_PSEUDO_CALL && imm == BPF_FUNC_tail_call may be satisfied by a kfunc call. This would lead to unnecessarily setting has_tail_call. Use src_reg == 0 instead.

(although not sure on src_reg == 0 vs !src_reg. Alexei seems to be favoring the latter?)

Quoted 23 lines
---
 kernel/bpf/verifier.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +2 -3
index e63af41a7e95..6d4632476c9c 100644
@@ -2462,8 +2462,8 @@ static int check_subprogs(struct bpf_verifier_env *env)
                u8 code = insn[i].code;
 
                if (code == (BPF_JMP | BPF_CALL) &&
-                   insn[i].imm == BPF_FUNC_tail_call &&
-                   insn[i].src_reg != BPF_PSEUDO_CALL)
+                   insn[i].src_reg == 0 &&
+                   insn[i].imm == BPF_FUNC_tail_call)
                        subprog[cur_subprog].has_tail_call = true;
                if (BPF_CLASS(code) == BPF_LD &&
                    (BPF_MODE(code) == BPF_ABS || BPF_MODE(code) == BPF_IND))
--

2.39.1

#2 lore raw
In reply to Ilya Leoshkevich
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Mon, 20 Feb 2023 17:37:56 +0100 you wrote:

The condition src_reg != BPF_PSEUDO_CALL && imm == BPF_FUNC_tail_call may be satisfied by a kfunc call. This would lead to unnecessarily setting has_tail_call. Use src_reg == 0 instead.

---
 kernel/bpf/verifier.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Here is the summary with links:
- [bpf-next] bpf: Check for helper calls in check_subprogs()

    https://git.kernel.org/bpf/bpf-next/c/df2ccc180a2e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html