Skip to content
  • Magnus Karlsson's avatar
    2f996198
    xsk: Fix missing validation for skb and unaligned mode · 2f996198
    Magnus Karlsson authored
    
    
    Fix a missing validation of a Tx descriptor when executing in skb mode
    and the umem is in unaligned mode. A descriptor could point to a
    buffer straddling the end of the umem, thus effectively tricking the
    kernel to read outside the allowed umem region. This could lead to a
    kernel crash if that part of memory is not mapped.
    
    In zero-copy mode, the descriptor validation code rejects such
    descriptors by checking a bit in the DMA address that tells us if the
    next page is physically contiguous or not. For the last page in the
    umem, this bit is not set, therefore any descriptor pointing to a
    packet straddling this last page boundary will be rejected. However,
    the skb path does not use this bit since it copies out data and can do
    so to two different pages. (It also does not have the array of DMA
    address, so it cannot even store this bit.) The code just returned
    that the packet is always physically contiguous. But this is
    unfortunately also returned for the last page in the umem, which means
    that packets that cross the end of the umem are being allowed, which
    they should not be.
    
    Fix this by introducing a check for this in the SKB path only, not
    penalizing the zero-copy path.
    
    Fixes: 2b43470a ("xsk: Introduce AF_XDP buffer allocation API")
    Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarBjörn Töpel <bjorn@kernel.org>
    Link: https://lore.kernel.org/bpf/20210617092255.3487-1-magnus.karlsson@gmail.com
    2f996198
    xsk: Fix missing validation for skb and unaligned mode
    Magnus Karlsson authored
    
    
    Fix a missing validation of a Tx descriptor when executing in skb mode
    and the umem is in unaligned mode. A descriptor could point to a
    buffer straddling the end of the umem, thus effectively tricking the
    kernel to read outside the allowed umem region. This could lead to a
    kernel crash if that part of memory is not mapped.
    
    In zero-copy mode, the descriptor validation code rejects such
    descriptors by checking a bit in the DMA address that tells us if the
    next page is physically contiguous or not. For the last page in the
    umem, this bit is not set, therefore any descriptor pointing to a
    packet straddling this last page boundary will be rejected. However,
    the skb path does not use this bit since it copies out data and can do
    so to two different pages. (It also does not have the array of DMA
    address, so it cannot even store this bit.) The code just returned
    that the packet is always physically contiguous. But this is
    unfortunately also returned for the last page in the umem, which means
    that packets that cross the end of the umem are being allowed, which
    they should not be.
    
    Fix this by introducing a check for this in the SKB path only, not
    penalizing the zero-copy path.
    
    Fixes: 2b43470a ("xsk: Introduce AF_XDP buffer allocation API")
    Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarBjörn Töpel <bjorn@kernel.org>
    Link: https://lore.kernel.org/bpf/20210617092255.3487-1-magnus.karlsson@gmail.com
Loading