Skip to content

bpf: Mitigate Spectre v1 using barriers #5279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: bpf-next_base
Choose a base branch
from

Conversation

kernel-patches-daemon-bpf-rc[bot]
Copy link

Pull request for series with
subject: selftests/bpf: Fix caps for __xlated/jited_unpriv
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=958739

Kernel Patches Daemon and others added 3 commits April 30, 2025 16:03
Currently, __xlated_unpriv and __jited_unpriv do not work because the
BPF syscall will overwrite info.jited_prog_len and info.xlated_prog_len
with 0 if the process is not bpf_capable(). This bug was not noticed
before, because there is no test that actually uses
__xlated_unpriv/__jited_unpriv.

To resolve this, simply restore the capabilities earlier (but still
after loading the program). Adding this here unconditionally is fine
because the function first checks that the capabilities were initialized
before attempting to restore them.

This will be important later when we add tests that check whether a
speculation barrier was inserted in the correct location.

Signed-off-by: Luis Gerhorst <[email protected]>
Fixes: 9c9f733 ("selftests/bpf: allow checking xlated programs in verifier_* tests")
Fixes: 7d743e4 ("selftests/bpf: __jited test tag to check disassembly after jit")
This is required to catch the errors later and fall back to a nospec if
on a speculative path.

Eliminate the regs variable as it is only used once and insn_idx is not
modified in-between the definition and usage.

Still pass insn simply to match the other check_*() functions. As Eduard
points out [1], insn is assumed to correspond to env->insn_idx in many
places (e.g, __check_reg_arg()).

Move code into do_check_insn(), replace
* "continue" with "return 0" after modifying insn_idx
* "goto process_bpf_exit" with "return PROCESS_BPF_EXIT"
* "do_print_state = " with "*do_print_state = "

[1] https://lore.kernel.org/all/[email protected]/

Signed-off-by: Luis Gerhorst <[email protected]>
Acked-by: Henriette Herzog <[email protected]>
Cc: Maximilian Ott <[email protected]>
Cc: Milan Stephan <[email protected]>
@kernel-patches-daemon-bpf-rc
Copy link
Author

Upstream branch: 358b1c0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=958739
version: 3

@kernel-patches-daemon-bpf-rc kernel-patches-daemon-bpf-rc bot changed the title selftests/bpf: Fix caps for __xlated/jited_unpriv bpf: Mitigate Spectre v1 using barriers May 1, 2025
@kernel-patches-daemon-bpf-rc kernel-patches-daemon-bpf-rc bot force-pushed the bpf-next_base branch 5 times, most recently from db1c311 to 874975c Compare May 1, 2025 21:07
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