• Daniel Borkmann's avatar
    bpf: Fix toctou on read-only map's constant scalar tracking · 353050be
    Daniel Borkmann authored
    Commit a23740ec ("bpf: Track contents of read-only maps as scalars") is
    checking whether maps are read-only both from BPF program side and user space
    side, and then, given their content is constant, reading out their data via
    map->ops->map_direct_value_addr() which is then subsequently used as known
    scalar value for the register, that is, it is marked as __mark_reg_known()
    with the read value at verification time. Before a23740ec, the register
    content was marked as an unknown scalar so the verifier could not make any
    assumptions about the map content.
    
    The current implementation however is prone to a TOCTOU race, meaning, the
    value read as known scalar for the register is not guaranteed to be exactly
    the same at a later point when the program is executed, and as such, the
    prior made assumptions of the verifier with regards to the program will be
    invalid which can cause issues such as OOB access, etc.
    
    While the BPF_F_RDONLY_PROG map flag ...
    353050be
verifier.c 401 KB