Skip to contentSkip to conversation

bpf: Check callx operand before requiring JIT support

PATCH Applied Kumar Kartikeya Dwivedi 2 participants 2 messages Sep 25

Subsystems (2)
lore
Share & tools
lore

Kumar Kartikeya Dwivedi

author maintainer
#0 lore raw

PATCH 1/1 bpf: Check callx operand before requiring JIT support

check_func_callx() requires a JIT with callx support before it looks at the register operand. On an architecture whose JIT doesn't support callx, or when the JIT is disabled, every callx is thus rejected with "JIT doesn't support callx" or "JIT is required to use callx", including one whose operand is invalid. The "invalid call insn1" test_verifier test expects "R0 !read_ok" for callx of an uninitialized register and fails on s390x:

#79/u invalid call insn1 FAIL
Unexpected error message!
EXP: R0 !read_ok
RES: JIT doesn't support callx

Validate the operand first and require the JIT only for a callx that is otherwise valid. An invalid callx is then rejected with the same message on every architecture. This fixes various errors when running selftests on JITs where callx is unsupported for now.

---
 kernel/bpf/verifier.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/bpf/verifier.c +5 -4
index c495dc9070de..76172c1e55d5 100644
@@ -11211,10 +11211,6 @@ static int check_func_callx(struct bpf_verifier_env *env, struct bpf_insn *insn,
 	const char *reason;
 	int err, subprog;
 
-	err = require_callx_jit(env);
-	if (err)
-		return err;
-
 	err = check_reg_arg(env, insn->dst_reg, SRC_OP);
 	if (err)
 		return err;
@@ -11240,6 +11236,11 @@ static int check_func_callx(struct bpf_verifier_env *env, struct bpf_insn *insn,
 	if (err)
 		return err;
 
+	/* the callx is valid, but only a JIT can execute it */
+	err = require_callx_jit(env);
+	if (err)
+		return err;
+
 	/* PTR_TO_FUNC is a pointer to a static subprog */
 	subprog = reg->subprogno;
 	err = btf_check_subprog_call(env, subprog, caller->regs);

--
2.53.0

#1 lore raw
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 9 lines · On Fri, 25 Sep 2026 08:09:44 +0200 you wrote:

check_func_callx() requires a JIT with callx support before it looks at the register operand. On an architecture whose JIT doesn't support callx, or when the JIT is disabled, every callx is thus rejected with "JIT doesn't support callx" or "JIT is required to use callx", including one whose operand is invalid. The "invalid call insn1" test_verifier test expects "R0 !read_ok" for callx of an uninitialized register and fails on s390x:

[...]

Here is the summary with links:
- [bpf-next] bpf: Check callx operand before requiring JIT support

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

You are awesome, thank you!

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