• Andrii Nakryiko's avatar
    bpf: add support for passing dynptr pointer to global subprog · a64bfe61
    Andrii Nakryiko authored
    Add ability to pass a pointer to dynptr into global functions.
    This allows to have global subprogs that accept and work with generic
    dynptrs that are created by caller. Dynptr argument is detected based on
    the name of a struct type, if it's "bpf_dynptr", it's assumed to be
    a proper dynptr pointer. Both actual struct and forward struct
    declaration types are supported.
    
    This is conceptually exactly the same semantics as
    bpf_user_ringbuf_drain()'s use of dynptr to pass a variable-sized
    pointer to ringbuf record. So we heavily rely on CONST_PTR_TO_DYNPTR
    bits of already existing logic in the verifier.
    
    During global subprog validation, we mark such CONST_PTR_TO_DYNPTR as
    having LOCAL type, as that's the most unassuming type of dynptr and it
    doesn't have any special helpers that can try to free or acquire extra
    references (unlike skb, xdp, or ringbuf dynptr). So that seems like a safe
    "choice" to make from correctness standpoint. It's still possible to
    pass any type of dynptr to such subprog, though, because generic dynptr
    helpers, like getting data/slice pointers, read/write memory copying
    routines, dynptr adjustment and getter routines all work correctly with
    any type of dynptr.
    Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20231215011334.2307144-8-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    a64bfe61
btf.c 217 KB