Skip to content

bpf: Limit writable registers in uprobe context

Jiri Olsa bpf linux-arm-kernel linux-riscv linux-trace-kernel stable 1 version Applied

Status from this message: This series was applied to bpf/bpf.git (master)

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesApplied 2/2

Patches in v1 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: Restrict uprobe ctx writes to the registers ptrace can setarch/arm64/kernel/probes/uprobes.c arch/riscv/kernel/probes/uprobes.c arch/x86/kernel/uprobes.c +3 more+50 -10 repliesApplied
2/2selftests/bpf: Test which ctx registers a uprobe prog can writetools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/verifier_uprobe_write_ctx.c+198 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH bpf 0/2] bpf: Limit writable registers in uprobe context

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