Skip to content
  • Daniel Borkmann's avatar
    bpf, verifier: add ARG_PTR_TO_RAW_STACK type · 435faee1
    Daniel Borkmann authored
    
    
    When passing buffers from eBPF stack space into a helper function, we have
    ARG_PTR_TO_STACK argument type for helpers available. The verifier makes sure
    that such buffers are initialized, within boundaries, etc.
    
    However, the downside with this is that we have a couple of helper functions
    such as bpf_skb_load_bytes() that fill out the passed buffer in the expected
    success case anyway, so zero initializing them prior to the helper call is
    unneeded/wasted instructions in the eBPF program that can be avoided.
    
    Therefore, add a new helper function argument type called ARG_PTR_TO_RAW_STACK.
    The idea is to skip the STACK_MISC check in check_stack_boundary() and color
    the related stack slots as STACK_MISC after we checked all call arguments.
    
    Helper functions using ARG_PTR_TO_RAW_STACK must make sure that every path of
    the helper function will fill the provided buffer area, so that we cannot leak
    any uninitialized stack memory. This f.e. means that error paths need to
    memset() the buffers, but the expected fast-path doesn't have to do this
    anymore.
    
    Since there's no such helper needing more than at most one ARG_PTR_TO_RAW_STACK
    argument, we can keep it simple and don't need to check for multiple areas.
    Should in future such a use-case really appear, we have check_raw_mode() that
    will make sure we implement support for it first.
    
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    435faee1