BPF List
 help / color / mirror / Atom feed
From: Martin Kelly <martin.kelly@crowdstrike.com>
To: <bpf@vger.kernel.org>
Cc: Rahul Shah <rahul.shah@crowdstrike.com>
Subject: Best way to check for fentry attach support
Date: Tue, 12 Sep 2023 11:50:24 -0700	[thread overview]
Message-ID: <f76a8cb2-6cc7-be5d-0335-cc6b98baaed8@crowdstrike.com> (raw)

Hi all,

I'm trying to figure out the best way to handle the fact that 
fentry/fexit trampolines are not fully supported on all architectures 
and kernel versions. As an example, I want to be able to load an fentry 
if the kernel supports it, and a kprobe otherwise.

It's tempting to use libbpf_probe_bpf_prog_type for this, but on ARM64 
kernels >= 5.5 (when BPF trampolines were introduced) but before the 
most recent ones, loading an fentry program will pass, but attaching it 
will still fail. This also means that libbpf_probe_bpf_prog_type will 
return true even if the program can't be attached, so that can't be used 
to test for attachability.

I can work around this by attempting to attach a dummy fentry program in 
my application, but I'm wondering if this is something that should be 
done more generally by libbpf. Some possible ways to do this are:

- Extend the libbpf_probe API to add libbpf_probe_trampoline or similar, 
attempting attach to a known-exported function, such as the BPF syscall, 
or to a user-specified symbol.

- Extend the libbpf_probe API to add a generic libbpf_probe_attach API 
to check if a given function is attachable. However, as attach code is 
different depending on the hook, this might be very complex and require 
a ton of parameters.

- Maybe there are other options that I haven't thought of.

I have a patch I could send for libbpf_probe_trampoline, but I wanted to 
first check if this is a good idea or if it's preferred to simply have 
applications probe this themselves.

Thanks,

Martin


             reply	other threads:[~2023-09-12 18:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 18:50 Martin Kelly [this message]
2023-09-14 18:05 ` Best way to check for fentry attach support Andrii Nakryiko
2023-09-14 19:07   ` Martin Kelly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f76a8cb2-6cc7-be5d-0335-cc6b98baaed8@crowdstrike.com \
    --to=martin.kelly@crowdstrike.com \
    --cc=bpf@vger.kernel.org \
    --cc=rahul.shah@crowdstrike.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox