• Hou Tao's avatar
    bpf: Pass map file to .map_update_batch directly · 3af43ba4
    Hou Tao authored
    
    
    Currently bpf_map_do_batch() first invokes fdget(batch.map_fd) to get
    the target map file, then it invokes generic_map_update_batch() to do
    batch update. generic_map_update_batch() will get the target map file
    by using fdget(batch.map_fd) again and pass it to bpf_map_update_value().
    
    The problem is map file returned by the second fdget() may be NULL or a
    totally different file compared by map file in bpf_map_do_batch(). The
    reason is that the first fdget() only guarantees the liveness of struct
    file instead of file descriptor and the file description may be released
    by concurrent close() through pick_file().
    
    It doesn't incur any problem as for now, because maps with batch update
    support don't use map file in .map_fd_get_ptr() ops. But it is better to
    fix the potential access of an invalid map file.
    
    Using __bpf_map_get() again in generic_map_update_batch() can not fix
    the problem, because batch.map_fd may be closed and reopened, and the
    returned map file may be different with map file got in
    bpf_map_do_batch(), so just passing the map file directly to
    .map_update_batch() in bpf_map_do_batch().
    Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarYonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20221116075059.1551277-1-houtao@huaweicloud.com
    3af43ba4
syscall.c 127 KB