Skip to content
  • Daniel Borkmann's avatar
    bpf: add new arg_type that allows for 0 sized stack buffer · 8e2fe1d9
    Daniel Borkmann authored
    
    
    Currently, when we pass a buffer from the eBPF stack into a helper
    function, the function proto indicates argument types as ARG_PTR_TO_STACK
    and ARG_CONST_STACK_SIZE pair. If R<X> contains the former, then R<X+1>
    must be of the latter type. Then, verifier checks whether the buffer
    points into eBPF stack, is initialized, etc. The verifier also guarantees
    that the constant value passed in R<X+1> is greater than 0, so helper
    functions don't need to test for it and can always assume a non-NULL
    initialized buffer as well as non-0 buffer size.
    
    This patch adds a new argument types ARG_CONST_STACK_SIZE_OR_ZERO that
    allows to also pass NULL as R<X> and 0 as R<X+1> into the helper function.
    Such helper functions, of course, need to be able to handle these cases
    internally then. Verifier guarantees that either R<X> == NULL && R<X+1> == 0
    or R<X> != NULL && R<X+1> != 0 (like the case of ARG_CONST_STACK_SIZE), any
    other combinations are not possible to load.
    
    I went through various options of extending the verifier, and introducing
    the type ARG_CONST_STACK_SIZE_OR_ZERO seems to have most minimal changes
    needed to the verifier.
    
    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>
    8e2fe1d9