From: Andrii Nakryiko <andrii@kernel.org>
To: bpf@vger.kernel.org
Cc: linux-mm@kvack.org, akpm@linux-foundation.org,
adobriyan@gmail.com, shakeel.butt@linux.dev, hannes@cmpxchg.org,
ak@linux.intel.com, osandov@osandov.com, song@kernel.org,
Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH v2 bpf-next 00/10] Harden and extend ELF build ID parsing logic
Date: Wed, 24 Jul 2024 15:52:00 -0700 [thread overview]
Message-ID: <20240724225210.545423-1-andrii@kernel.org> (raw)
The goal of this patch set is to extend existing ELF build ID parsing logic,
currently mostly used by BPF subsystem, with support for working in sleepable
mode in which memory faults are allowed and can be relied upon to fetch
relevant parts of ELF file to find and fetch .note.gnu.build-id information.
This is useful and important for BPF subsystem itself, but also for
PROCMAP_QUERY ioctl(), built atop of /proc/<pid>/maps functionality (see [0]),
which makes use of the same build_id_parse() functionality. PROCMAP_QUERY is
always called from sleepable user process context, so it doesn't have to
suffer from current restrictions of build_id_parse() which are due to the NMI
context assumption.
Along the way, we harden the logic to avoid TOCTOU problems. We also lift
existing limitations of only working as long as ELF program headers and build
ID note section is contained strictly within the very first page of ELF file.
We achieve all of the above without duplication of logic between sleepable and
non-sleepable modes through freader abstraction that manages underlying page
cache page (on demand) and giving a simple to use direct memory access
interface. With that, single page restrictions and adding sleepable mode
support is rather straightforward.
We also extend existing set of BPF selftests with a few tests targeting build
ID logic across sleepable and non-sleepabe contexts (we utilize sleepable and
non-sleepable uprobes for that).
[0] https://lore.kernel.org/linux-mm/20240627170900.1672542-4-andrii@kernel.org/
v1->v2:
- ensure MADV_PAGEOUT works reliably by paging data in first (Shakeel);
- to fix BPF CI build optionally define MADV_POPULATE_READ in selftest.
Andrii Nakryiko (10):
lib/buildid: add single page-based file reader abstraction
lib/buildid: take into account e_phoff when fetching program headers
lib/buildid: remove single-page limit for PHDR search
lib/buildid: rename build_id_parse() into build_id_parse_nofault()
lib/buildid: implement sleepable build_id_parse() API
lib/buildid: don't limit .note.gnu.build-id to the first page in ELF
lib/buildid: harden build ID parsing logic some more
bpf: decouple stack_map_get_build_id_offset() from
perf_callchain_entry
bpf: wire up sleepable bpf_get_stack() and bpf_get_task_stack()
helpers
selftests/bpf: add build ID tests
include/linux/bpf.h | 2 +
include/linux/buildid.h | 4 +-
kernel/bpf/stackmap.c | 131 +++++--
kernel/events/core.c | 2 +-
kernel/trace/bpf_trace.c | 5 +-
lib/buildid.c | 370 +++++++++++++-----
tools/testing/selftests/bpf/Makefile | 5 +-
.../selftests/bpf/prog_tests/build_id.c | 118 ++++++
.../selftests/bpf/progs/test_build_id.c | 31 ++
tools/testing/selftests/bpf/uprobe_multi.c | 41 ++
tools/testing/selftests/bpf/uprobe_multi.ld | 11 +
11 files changed, 591 insertions(+), 129 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/build_id.c
create mode 100644 tools/testing/selftests/bpf/progs/test_build_id.c
create mode 100644 tools/testing/selftests/bpf/uprobe_multi.ld
--
2.43.0
next reply other threads:[~2024-07-24 22:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 22:52 Andrii Nakryiko [this message]
2024-07-24 22:52 ` [PATCH v2 bpf-next 01/10] lib/buildid: add single page-based file reader abstraction Andrii Nakryiko
2024-07-25 12:03 ` Jiri Olsa
2024-07-25 19:58 ` Andrii Nakryiko
2024-07-26 12:31 ` Jiri Olsa
2024-07-25 22:43 ` Andi Kleen
2024-07-27 0:26 ` Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 02/10] lib/buildid: take into account e_phoff when fetching program headers Andrii Nakryiko
2024-07-25 12:03 ` Jiri Olsa
2024-07-25 19:59 ` Andrii Nakryiko
2024-07-25 22:45 ` Andi Kleen
2024-07-27 0:30 ` Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 03/10] lib/buildid: remove single-page limit for PHDR search Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 04/10] lib/buildid: rename build_id_parse() into build_id_parse_nofault() Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 05/10] lib/buildid: implement sleepable build_id_parse() API Andrii Nakryiko
2024-07-25 22:46 ` Andi Kleen
2024-07-27 0:36 ` Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 06/10] lib/buildid: don't limit .note.gnu.build-id to the first page in ELF Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 07/10] lib/buildid: harden build ID parsing logic some more Andrii Nakryiko
2024-07-29 16:15 ` Jann Horn
2024-07-29 16:57 ` Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 08/10] bpf: decouple stack_map_get_build_id_offset() from perf_callchain_entry Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 09/10] bpf: wire up sleepable bpf_get_stack() and bpf_get_task_stack() helpers Andrii Nakryiko
2024-07-24 22:52 ` [PATCH v2 bpf-next 10/10] selftests/bpf: add build ID tests Andrii Nakryiko
2024-07-25 12:04 ` Jiri Olsa
2024-07-25 20:01 ` Andrii Nakryiko
2024-07-25 12:12 ` Jiri Olsa
2024-07-25 20:03 ` Andrii Nakryiko
2024-07-26 12:27 ` Jiri Olsa
2024-07-27 0:37 ` Andrii Nakryiko
2024-07-28 19:38 ` Jiri Olsa
2024-07-30 20:03 ` Andrii Nakryiko
2024-07-30 20:18 ` Jiri Olsa
2025-09-10 6:09 ` Saket Kumar Bhaskar
2025-09-10 14:18 ` Andrii Nakryiko
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=20240724225210.545423-1-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=adobriyan@gmail.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=bpf@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=osandov@osandov.com \
--cc=shakeel.butt@linux.dev \
--cc=song@kernel.org \
/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