• Andrii Nakryiko's avatar
    libbpf: add ksyscall/kretsyscall sections support for syscall kprobes · 708ac5be
    Andrii Nakryiko authored
    Add SEC("ksyscall")/SEC("ksyscall/<syscall_name>") and corresponding
    kretsyscall variants (for return kprobes) to allow users to kprobe
    syscall functions in kernel. These special sections allow to ignore
    complexities and differences between kernel versions and host
    architectures when it comes to syscall wrapper and corresponding
    __<arch>_sys_<syscall> vs __se_sys_<syscall> differences, depending on
    whether host kernel has CONFIG_ARCH_HAS_SYSCALL_WRAPPER (though libbpf
    itself doesn't rely on /proc/config.gz for detecting this, see
    BPF_KSYSCALL patch for how it's done internally).
    
    Combined with the use of BPF_KSYSCALL() macro, this allows to just
    specify intended syscall name and expected input arguments and leave
    dealing with all the variations to libbpf.
    
    In addition to SEC("ksyscall+") and SEC("kretsyscall+") add
    bpf_program__attach_ksyscall() API which allows to specify syscall name
    at runtime and provide associated BPF cookie value.
    
    At the moment SEC("ksyscall") and bpf_program__attach_ksyscall() do not
    handle all the calling convention quirks for mmap(), clone() and compat
    syscalls. It also only attaches to "native" syscall interfaces. If host
    system supports compat syscalls or defines 32-bit syscalls in 64-bit
    kernel, such syscall interfaces won't be attached to by libbpf.
    
    These limitations may or may not change in the future. Therefore it is
    recommended to use SEC("kprobe") for these syscalls or if working with
    compat and 32-bit interfaces is required.
    Tested-by: default avatarAlan Maguire <alan.maguire@oracle.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20220714070755.3235561-5-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    708ac5be
libbpf.h 54.9 KB