]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Fix ld_{abs,ind} failure path analysis in subprogs
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 8 Apr 2026 19:12:40 +0000 (21:12 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 9 Apr 2026 01:43:28 +0000 (18:43 -0700)
commitee861486e377edc55361c08dcbceab3f6b6577bd
treedd20440c32c8909b48d0b28c47854a8509663994
parent6bd96e40f31dde8f8cd79772b4df0f171cf8a915
bpf: Fix ld_{abs,ind} failure path analysis in subprogs

Usage of ld_{abs,ind} instructions got extended into subprogs some time
ago via commit 09b28d76eac4 ("bpf: Add abnormal return checks."). These
are only allowed in subprograms when the latter are BTF annotated and
have scalar return types.

The code generator in bpf_gen_ld_abs() has an abnormal exit path (r0=0 +
exit) from legacy cBPF times. While the enforcement is on scalar return
types, the verifier must also simulate the path of abnormal exit if the
packet data load via ld_{abs,ind} failed.

This is currently not the case. Fix it by having the verifier simulate
both success and failure paths, and extend it in similar ways as we do
for tail calls. The success path (r0=unknown, continue to next insn) is
pushed onto stack for later validation and the r0=0 and return to the
caller is done on the fall-through side.

Fixes: 09b28d76eac4 ("bpf: Add abnormal return checks.")
Reported-by: STAR Labs SG <info@starlabs.sg>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20260408191242.526279-2-daniel@iogearbox.net
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c