* [PATCH bpf] bpf: fix constant blinding bypass for PROBE_MEM32 stores
@ 2026-03-06 6:50 CyFun
0 siblings, 0 replies; only message in thread
From: CyFun @ 2026-03-06 6:50 UTC (permalink / raw)
To: bpf@vger.kernel.org
Cc: daniel@iogearbox.net, ast@kernel.org, andrii@kernel.org,
netdev@vger.kernel.org
[-- Attachment #1.1: Type: text/plain, Size: 2363 bytes --]
BPF_ST | BPF_PROBE_MEM32 immediate stores are not handled by
bpf_jit_blind_insn(), allowing user-controlled 32-bit immediates to
survive unblinded into JIT-compiled native code when bpf_jit_harden >= 1.
The root cause is that convert_ctx_accesses() rewrites BPF_ST|BPF_MEM
to BPF_ST|BPF_PROBE_MEM32 for arena pointer stores during verification,
before bpf_jit_blind_constants() runs during JIT compilation. The
blinding switch only matches BPF_ST|BPF_MEM (mode 0x60), not
BPF_ST|BPF_PROBE_MEM32 (mode 0xa0). The instruction falls through
unblinded.
Add BPF_ST|BPF_PROBE_MEM32 cases to bpf_jit_blind_insn() alongside the
existing BPF_ST|BPF_MEM cases. The blinding transformation is identical:
load the blinded immediate into BPF_REG_AX via mov+xor, then convert
the immediate store to a register store (BPF_STX).
The rewritten STX instruction must preserve the BPF_PROBE_MEM32 mode so
the architecture JIT emits the correct arena addressing (R12-based on
x86-64). Cannot use the BPF_STX_MEM() macro here because it hardcodes
BPF_MEM mode; construct the instruction directly instead.
Fixes: 6082b6c328b5 ("bpf: Recognize addr_space_cast instruction in the verifier.")
Signed-off-by: s4ch <xcyfun@protonmail.com>
---
kernel/bpf/core.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 3ece2da55625..000000000000 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2114,6 +2114,22 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
*to++ = BPF_STX_MEM(from->code, from->dst_reg,
BPF_REG_AX, from->off);
break;
+
+ case BPF_ST | BPF_PROBE_MEM32 | BPF_DW:
+ case BPF_ST | BPF_PROBE_MEM32 | BPF_W:
+ case BPF_ST | BPF_PROBE_MEM32 | BPF_H:
+ case BPF_ST | BPF_PROBE_MEM32 | BPF_B:
+ *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^
+ from->imm);
+ *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
+ /* Cannot use BPF_STX_MEM() here: it hardcodes BPF_MEM
+ * mode which would lose BPF_PROBE_MEM32 and break the
+ * arena addressing in the architecture JIT. */
+ *to++ = (struct bpf_insn) {
+ .code = BPF_STX | BPF_PROBE_MEM32 | BPF_SIZE(from->code),
+ .dst_reg = from->dst_reg,
+ .src_reg = BPF_REG_AX,
+ .off = from->off,
+ };
+ break;
}
return to - to_buff;
--
2.53.0
[-- Attachment #1.2: publickey - xcyfun@protonmail.com - 0x33596AE7.asc --]
[-- Type: application/pgp-keys, Size: 653 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 343 bytes --]
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-06 6:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 6:50 [PATCH bpf] bpf: fix constant blinding bypass for PROBE_MEM32 stores CyFun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox