bpf: Fix precedence bug in convert_bpf_ld_abs alignment check
Subsystems (4)
Daniel Borkmann
maintainerPATCH 1/1 bpf: Fix precedence bug in convert_bpf_ld_abs alignment check
Fix an operator precedence issue in convert_bpf_ld_abs() where the expression offset + ip_align % size evaluates as offset + (ip_align % size) due to % having higher precedence than +. That latter evaluation does not make any sense. The intended check is (offset + ip_align) % size == 0 to verify that the packet load offset is properly aligned for direct access.
With NET_IP_ALIGN == 2, the bug causes the inline fast-path for direct packet loads to almost never be taken on !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS platforms. This forces nearly all cBPF BPF_LD_ABS packet loads through the bpf_skb_load_helper slow path on the affected archs.
--- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
@@ -508,7 +508,7 @@ static bool convert_bpf_ld_abs(struct sock_filter *fp, struct bpf_insn **insnp) ((unaligned_ok && offset >= 0) || (!unaligned_ok && offset >= 0 && offset + ip_align >= 0 && - offset + ip_align % size == 0))) { + (offset + ip_align) % size == 0))) {bool ldx_off_ok = offset <=S16_MAX ; *insn++ =BPF_MOV64_REG (BPF_REG_TMP ,BPF_REG_H );
Signature · 1 line
2.43.0
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 8 lines · On Thu, 16 Apr 2026 14:27:19 +0200 you wrote:
Fix an operator precedence issue in
convert_bpf_ld_abs()where the expression offset +ip_align% size evaluates as offset + (ip_align% size) due to % having higher precedence than +. That latter evaluation does not make any sense. The intended check is (offset +ip_align) % size == 0 to verify that the packet load offset is properly aligned for direct access.[...]
Here is the summary with links:
- [bpf] bpf: Fix precedence bug in convert_bpf_ld_abs alignment check
https://git.kernel.org/bpf/bpf/c/e5f635edd393
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html