Skip to content

bpf, x86: Fix signed 32-bit div/mod in the i386 JIT#12801

Closed
kernel-patches-daemon-bpf[bot] wants to merge 1 commit into
bpf_basefrom
series/1126868=>bpf
Closed

bpf, x86: Fix signed 32-bit div/mod in the i386 JIT#12801
kernel-patches-daemon-bpf[bot] wants to merge 1 commit into
bpf_basefrom
series/1126868=>bpf

Conversation

@kernel-patches-daemon-bpf

Copy link
Copy Markdown

Pull request for series with
subject: bpf, x86: Fix signed 32-bit div/mod in the i386 JIT
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1126868

@kernel-patches-daemon-bpf

Copy link
Copy Markdown
Author

Upstream branch: 7cbd0c4
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1126868
version: 1

emit_ia32_div_mod_r() always emits an unsigned divide (xor edx,edx +
div ecx), regardless of the BPF instruction's signedness. Signed
ALU32 BPF_DIV and BPF_MOD (off=1) therefore get an unsigned quotient
and remainder in the i386 JIT, diverging from the verifier's and the
interpreter's signed result for negative operands.

Thread is_signed = (insn->off == 1) into emit_ia32_div_mod_r() and
emit cdq + idiv ecx on the signed path, xor edx,edx + div ecx
unchanged on the unsigned path, mirroring the cdq/idiv-vs-xor/div
split the x86_64 JIT uses for the same instructions. bpf_do_misc_fixups()
rewrites the zero-divisor and INT_MIN/-1 cases out of the instruction
stream before the JIT runs.

The RV32 JIT has the same gap.

Fixes: ec0e2da ("bpf: Support new signed div/mod instructions.")
Signed-off-by: Nicholas Dudar <main.kalliope@gmail.com>
Assisted-by: Claude:claude-opus-4-8
@kernel-patches-daemon-bpf

Copy link
Copy Markdown
Author

Upstream branch: 71836d0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1126868
version: 1

@kernel-patches-daemon-bpf

Copy link
Copy Markdown
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1126868 expired. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant