Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attaching fentry/fexit/fmod_ret/lsm to modules #4159

Closed
wants to merge 3 commits into from

Commits on Dec 5, 2022

  1. kallsyms: add space-efficient lookup in one module

    Until now, the only way to look up a symbol in kallsyms of a particular
    module was using the "module_kallsyms_lookup_name" function with the
    "module:symbol" string passed as a parameter. This syntax often requires
    to build the parameter string on stack, needlessly wasting space.
    
    This commit introduces function "kallsyms_lookup_name_in_module" which
    takes the module and the symbol names as separate parameters and
    therefore allows more space-efficient lookup.
    
    Signed-off-by: Viktor Malik <vmalik@redhat.com>
    Viktor Malik authored and Kernel Patches Daemon committed Dec 5, 2022
    Configuration menu
    Copy the full SHA
    3a069bf View commit details
    Browse the repository at this point in the history
  2. bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules

    When attaching fentry/fexit/fmod_ret/lsm to a function located in a
    module without specifying the target program, the verifier tries to find
    the address to attach to in kallsyms. This is always done by searching
    the entire kallsyms, not respecting the module in which the function is
    located.
    
    This approach causes an incorrect attachment address to be computed if
    the function to attach to is shadowed by a function of the same name
    located earlier in kallsyms.
    
    Since the attachment must contain the BTF of the program to attach to,
    we may extract the module name from it (if the attach target is a
    module) and search for the function address in the correct module.
    
    Signed-off-by: Viktor Malik <vmalik@redhat.com>
    Acked-by: Hao Luo <haoluo@google.com>
    Viktor Malik authored and Kernel Patches Daemon committed Dec 5, 2022
    Configuration menu
    Copy the full SHA
    75c027c View commit details
    Browse the repository at this point in the history
  3. bpf/selftests: Test fentry attachment to shadowed functions

    Adds a new test that tries to attach a program to fentry of two
    functions of the same name, one located in vmlinux and the other in
    bpf_testmod.
    
    To avoid conflicts with existing tests, a new function
    "bpf_fentry_shadow_test" was created both in vmlinux and in bpf_testmod.
    
    The previous commit fixed a bug which caused this test to fail. The
    verifier would always use the vmlinux function's address as the target
    trampoline address, hence trying to attach two programs to the same
    trampoline.
    
    Signed-off-by: Viktor Malik <vmalik@redhat.com>
    Viktor Malik authored and Kernel Patches Daemon committed Dec 5, 2022
    Configuration menu
    Copy the full SHA
    54c36bd View commit details
    Browse the repository at this point in the history