• Hou Tao's avatar
    selftests/bpf: Test the release of map btf · e58aac1a
    Hou Tao authored
    When there is bpf_list_head or bpf_rb_root field in map value, the free
    of map btf and the free of map value may run concurrently and there may
    be use-after-free problem, so add two test cases to demonstrate it. And
    the use-after-free problem can been easily reproduced by using bpf_next
    tree and a KASAN-enabled kernel.
    
    The first test case tests the racing between the free of map btf and the
    free of array map. It constructs the racing by releasing the array map in
    the end after other ref-counter of map btf has been released. To delay
    the free of array map and make it be invoked after btf_free_rcu() is
    invoked, it stresses system_unbound_wq by closing multiple percpu array
    maps before it closes the array map.
    
    The second case tests the racing between the free of map btf and the
    free of inner map. Beside using the similar method as the first one
    does, it uses bpf_map_delete_elem() to delete the inner map and to defer
    the release of inner map after one RCU grace period.
    
    The reason for using two skeletons is to prevent the release of outer
    map and inner map in map_in_map_btf.c interfering the release of bpf
    map in normal_map_btf.c.
    Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
    Link: https://lore.kernel.org/bpf/20231216035510.4030605-1-houtao@huaweicloud.com
    e58aac1a
map_btf.c 2.55 KB