Skip to content

bpf: fix constant blinding bypass for PROBE_MEM32 stores#11312

Closed
kernel-patches-daemon-bpf[bot] wants to merge 1 commit intobpf_basefrom
series/1062438=>bpf
Closed

bpf: fix constant blinding bypass for PROBE_MEM32 stores#11312
kernel-patches-daemon-bpf[bot] wants to merge 1 commit intobpf_basefrom
series/1062438=>bpf

Conversation

@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Pull request for series with
subject: bpf: fix constant blinding bypass for PROBE_MEM32 stores
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 56145d2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 6895e1d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 325d1ba
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: b0dcdcb
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 1954c4f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 014441d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 1f318b9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 1f318b9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

To: bpf@vger.kernel.org
Cc: daniel@iogearbox.net, ast@kernel.org, andrii@kernel.org, netdev@vger.kernel.org
Subject: [PATCH bpf v2] bpf: fix constant blinding bypass for PROBE_MEM32 stores

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: 6082b6c ("bpf: Recognize addr_space_cast instruction in the verifier.")
Signed-off-by: s4ch <xcyfun@protonmail.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 1f318b9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438
version: 2

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1062438 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