[PATCH bpf 0/2] bpf: Limit writable registers in uprobe context
Jiri Olsa
jolsa at kernel.org
Wed Nov 18 00:44:48 PST 2026
Hi,
a uprobe BPF program can currently write fields in struct pt_regs that
are loaded directly by the architecture’s return-to-user path. Some of
these fields are restricted by ptrace, but the BPF verifier does not
apply the same restrictions.
This series limits uprobe context writes to registers that ptrace can
set to arbitrary values. It adds architecture-specific writable-register
checks for arm64, riscv, and x86-64; other architectures default to
allowing no writes. Reads are unchanged.
The second patch adds verifier tests for writable and read-only registers
on x86-64, arm64, and riscv.
Patch 1 fixes the issue reported by rtm and is marked for stable consideration.
Patch 2 adds the regression tests.
thanks,
jirka
---
Jiri Olsa (2):
bpf: Restrict uprobe ctx writes to the registers ptrace can set
selftests/bpf: Test which ctx registers a uprobe prog can write
arch/arm64/kernel/probes/uprobes.c | 6 ++
arch/riscv/kernel/probes/uprobes.c | 6 ++
arch/x86/kernel/uprobes.c | 15 ++++
include/linux/uprobes.h | 5 ++
kernel/events/uprobes.c | 9 +++
kernel/trace/bpf_trace.c | 10 ++-
tools/testing/selftests/bpf/prog_tests/verifier.c | 2 +
tools/testing/selftests/bpf/progs/verifier_uprobe_write_ctx.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 248 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/progs/verifier_uprobe_write_ctx.c
More information about the linux-riscv
mailing list