From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
stable@dpdk.org, Marat Khalili <marat.khalili@huawei.com>,
Konstantin Ananyev <konstantin.ananyev@huawei.com>,
Ferruh Yigit <ferruh.yigit@amd.com>
Subject: [PATCH v7 01/10] bpf/x86: fix JIT encoding of fixed-width immediates
Date: Wed, 22 Jul 2026 09:05:13 -0700 [thread overview]
Message-ID: <20260722183351.633025-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20260722183351.633025-1-stephen@networkplumber.org>
Several places in the x86 JIT size an immediate with imm_size(), which
returns 1 or 4 bytes depending on the value. That is wrong for opcodes
whose immediate width is fixed by the encoding, and it breaks in both
directions.
TEST (0xF7 /0, used for BPF_JSET) has no imm8 form; the immediate is
always 32 bits. For a small mask such as BPF_JSET | BPF_K #0x1,
imm_size() returns 1, so the JIT emits a 1-byte immediate. The CPU
still consumes 4, swallowing 3 bytes of the following Jcc. The
instruction stream desyncs and the program crashes.
ROR and the shifts (0xC1 group) have the opposite problem: their
immediate is always imm8. For a count >= 128, imm_size() returns 4 and
the JIT emits 3 stray bytes, again desyncing the stream.
Size each immediate by its encoding: 32 bits for TEST, 8 bits for ROR
and the shifts.
Bugzilla ID: 1959
Fixes: cc752e43e079 ("bpf: add JIT compilation for x86_64 ISA")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Marat Khalili <marat.khalili@huawei.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
---
lib/bpf/bpf_jit_x86.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/bpf/bpf_jit_x86.c b/lib/bpf/bpf_jit_x86.c
index 54eb279643..912d3f69bc 100644
--- a/lib/bpf/bpf_jit_x86.c
+++ b/lib/bpf/bpf_jit_x86.c
@@ -300,7 +300,7 @@ emit_ror_imm(struct bpf_jit_state *st, uint32_t dreg, uint32_t imm)
emit_rex(st, BPF_ALU, 0, dreg);
emit_bytes(st, &ops, sizeof(ops));
emit_modregrm(st, MOD_DIRECT, mods, dreg);
- emit_imm(st, imm, imm_size(imm));
+ emit_imm(st, imm, sizeof(uint8_t));
}
/*
@@ -441,7 +441,7 @@ emit_shift_imm(struct bpf_jit_state *st, uint32_t op, uint32_t dreg,
uint32_t imm)
{
emit_shift(st, op, dreg);
- emit_imm(st, imm, imm_size(imm));
+ emit_imm(st, imm, sizeof(uint8_t));
}
/*
@@ -921,7 +921,7 @@ emit_tst_imm(struct bpf_jit_state *st, uint32_t op, uint32_t dreg, uint32_t imm)
emit_rex(st, op, 0, dreg);
emit_bytes(st, &ops, sizeof(ops));
emit_modregrm(st, MOD_DIRECT, mods, dreg);
- emit_imm(st, imm, imm_size(imm));
+ emit_imm(st, imm, sizeof(int32_t));
}
static void
--
2.53.0
next prev parent reply other threads:[~2026-07-22 18:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <0260608203322.1116296-1-stephen@networkplumber.org>
2026-07-22 16:05 ` [PATCH v7 00/10] bpf: bug fixes Stephen Hemminger
2026-07-22 16:05 ` Stephen Hemminger [this message]
2026-07-22 16:05 ` [PATCH v7 02/10] test/bpf: add JSET test with small immediate Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 03/10] bpf: mask shift count in interpreter per RFC 9669 Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 04/10] bpf/arm64: mask shift count " Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 05/10] test/bpf: add test for large shift Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 06/10] bpf/arm64: fix offset type to allow a negative jump Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 07/10] bpf/arm64: add BPF_ABS/BPF_IND packet load support Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 08/10] test/bpf: check that JIT was generated Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 09/10] test/bpf: check that bpf_convert can be JIT'd Stephen Hemminger
2026-07-22 16:05 ` [PATCH v7 10/10] bpf: fix uninitialized warning Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260722183351.633025-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=konstantin.ananyev@huawei.com \
--cc=marat.khalili@huawei.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox