Skip to content

bpf: Fix arena VMA use-after-free on fork

Weiming Shi bpf lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 5 repliesIn review
  2. v32 patches 0 repliesSuperseded
  3. v22 patches 4 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches0 repliesSuperseded

Changes in v4 from the cover letter

- Fixed commit message: OOM case description, may_split rationale

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: Fix use-after-free of arena VMA on forkkernel/bpf/arena.c+17 -65 replies
2/2selftests/bpf: Add test for arena VMA use-after-free on forktools/testing/selftests/bpf/prog_tests/arena_fork.c tools/testing/selftests/bpf/progs/arena_fork.c+121 -00 replies

Reviews trailers per patch

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

Read the v4 thread

Cover letter [PATCH bpf v4 0/2] bpf: Fix arena VMA use-after-free on fork

arena_vm_open() only increments a refcount on the shared vma_list entry but never registers the new VMA. After fork + parent munmap, vml->vma becomes a dangling pointer. bpf_arena_free_pages -> zap_pages then dereferences it, causing a slab-use-after-free in zap_page_range_single.

Patch 1 fixes the bug by tracking each child VMA separately in arena_vm_open, and adds arena_vm_may_split() to prevent VMA splitting. Patch 2 adds a selftest that reproduces the issue (requires KASAN to detect the UAF).

v4:
- Fixed commit message: OOM case description, may_split rationale

v3:
- Added arena_vm_may_split() to prevent VMA splitting
- Reuse remember_vma() in arena_vm_open(), removed HugeTLB references
- selftests: fixed copyright, trimmed comments, use sysconf()

v2:
- Added missing Reported-by tag

Weiming Shi (2):
bpf: Fix use-after-free of arena VMA on fork selftests/bpf: Add test for arena VMA use-after-free on fork

 kernel/bpf/arena.c                            | 23 ++++--
 .../selftests/bpf/prog_tests/arena_fork.c     | 80 +++++++++++++++++++
 .../testing/selftests/bpf/progs/arena_fork.c  | 41 ++++++++++
 3 files changed, 138 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_fork.c
 create mode 100644 tools/testing/selftests/bpf/progs/arena_fork.c
Signature · 1 line
2.43.0