From: Viktor Malik <vmalik@redhat.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Viktor Malik <vmalik@redhat.com>
Subject: [PATCH bpf-next v3 0/3] Fix attaching fentry/fexit/fmod_ret/lsm to modules
Date: Mon, 5 Dec 2022 16:26:03 +0100 [thread overview]
Message-ID: <cover.1670249590.git.vmalik@redhat.com> (raw)
While working on bpftrace support for BTF in modules [1], I noticed that
the verifier behaves incorrectly when attaching to fentry of multiple
functions of the same name located in different modules (or in vmlinux).
The reason for this is that if the target program is not specified, the
verifier will search kallsyms for the trampoline address to attach to.
The entire kallsyms is always searched, not respecting the module in
which the function to attach to is located.
This patch fixes the above issue by extracting the module name from the
BTF of the attachment target (which must be specified) and by doing the
search in kallsyms of the correct module.
This also adds a new test in test_progs which tries to attach a program
to fentry of two functions of the same name, one located in vmlinux and
the other in bpf_testmod. Prior to the fix, the verifier would always
use the vmlinux function address as the target trampoline, attempting to
attach two functions to the same trampoline (which is prohibited).
[1] https://github.com/iovisor/bpftrace/pull/2315
---
Changes in v3:
- added trivial implementation for kallsyms_lookup_name_in_module() for
!CONFIG_MODULES (noticed by test robot, fix suggested by Hao Luo)
Changes in v2:
- introduced and used more space-efficient kallsyms lookup function,
suggested by Jiri Olsa
- included Hao Luo's comments
Viktor Malik (3):
kallsyms: add space-efficient lookup in one module
bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules
bpf/selftests: Test fentry attachment to shadowed functions
include/linux/btf.h | 1 +
include/linux/module.h | 7 +
kernel/bpf/btf.c | 5 +
kernel/bpf/verifier.c | 5 +-
kernel/module/kallsyms.c | 16 +++
net/bpf/test_run.c | 5 +
.../selftests/bpf/bpf_testmod/bpf_testmod.c | 7 +
.../bpf/prog_tests/module_attach_shadow.c | 124 ++++++++++++++++++
8 files changed, 169 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/module_attach_shadow.c
--
2.38.1
next reply other threads:[~2022-12-05 15:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 15:26 Viktor Malik [this message]
2022-12-05 15:26 ` [PATCH bpf-next v3 1/3] kallsyms: add space-efficient lookup in one module Viktor Malik
2022-12-05 15:26 ` [PATCH bpf-next v3 2/3] bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules Viktor Malik
2022-12-07 0:10 ` Alexei Starovoitov
2022-12-07 6:57 ` Viktor Malik
2022-12-05 15:26 ` [PATCH bpf-next v3 3/3] bpf/selftests: Test fentry attachment to shadowed functions Viktor Malik
2022-12-05 20:49 ` Jiri Olsa
2022-12-06 6:15 ` Viktor Malik
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=cover.1670249590.git.vmalik@redhat.com \
--to=vmalik@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.