bpf: arena: fix use-after-free in VMA tracking on fork
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 69 lines · Daniel Hodges
arena_vm_open()only increments a refcount on the existingvma_listentry without creating a new entry for the child's VMA. After fork,vml->vmastill points to the parent's VMA. When the parent unmaps (arena_vm_closedecrements refcount but doesn't remove the entry),vml->vmabecomes a dangling pointer. A subsequentbpf_arena_free_pagescall reacheszap_pages()which dereferences the freed VMA viazap_vma_range(vml->vma, ...), causing a use-after-free:BUG: KASAN: slab-use-after-free in zap_vma_range+0xf2/0x100 Read of size 8 at addr ff11000113ec9b10 by task test_progs/198 Call Trace: zap_vma_range+0xf2/0x100 arena_free_pages+0x6de/0x970 bpf_prog_a2b540a82b1066f3_arena_free+0x8b/0xb6 bpf_prog_test_run_syscall+0x3d3/0x8a0The same issue is triggered by
__split_vma(partial munmap) andcopy_vma(mremap), both of which callvm_ops->open.Fix this by giving each VMA its own
vma_listentry instead of sharing one with a refcount.arena_vm_opennow allocates a new entry for the new VMA, andarena_vm_closealways removes and frees its own entry. If the allocation fails inarena_vm_open,vm_private_datais set to NULL andarena_vm_closehandles this gracefully, meaning the VMA simply won't be zapped during arena page frees.Fixes 317460317a02 ("bpf: Introduce bpf_arena.")Signed-off-by Daniel Hodges <[email protected]>Assisted-by Claude-Code:claude-opus-4-6--- kernel/bpf/arena.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)kernel/bpf/arena.c +0
-3@@ -310,64 +310,71 @@ static int arena_map_check_btf(struct bpf_map *map, const struct btf *btf, }static u64 arena_map_mem_usage (const struct bpf_map *map) {return 0 ; }struct vma_list {struct vm_area_struct *vma;struct list_head head; -refcount_t mmap_count; };static int remember_vma (struct bpf_arena *arena,struct vm_area_struct *vma) {struct vma_list *vml; vml =kmalloc_obj (*vml);if (!vml)return -ENOMEM ; -refcount_set (&vml->mmap_count,1 ); vma->vm_private_data = vml; vml->vma = vma;list_add (&vml->head, &arena->vma_list);return 0 ; }static void arena_vm_open (struct vm_area_struct *vma) { -struct vma_list *vml = vma->vm_private_data;
kernel/bpf/arena.c static int arena_map_check_btf(struct bpf_map *map, const struct btf *btf, · line 345
Quoted 10 lines
kernel/bpf/arena.c +8
-1+struct bpf_map *map = vma->vm_file->private_data; + struct bpf_arena *arena = container_of(map, struct bpf_arena, map); +struct vma_list *vml; -refcount_inc (&vml->mmap_count); + vml =kmalloc_obj (*vml); +if (!vml) { + vma->vm_private_data =NULL ; +return ; + }
I'm tired of seeing the same garbage patch from claude for the 3rd time.
Please make sure you use claude on the latest kernel.
The fix 4fddde2a732d ("bpf: Fix use-after-free in arena_vm_close on fork") landed a month ago.
pw-bot: cr