BPF List
 help / color / mirror / Atom feed
* [PATCH v2 0/4] libbpf: move arena variables out of the zero page
@ 2025-11-18  3:00 Emil Tsalapatis
  2025-11-18  3:00 ` [PATCH v2 1/4] selftests/bpf: explicitly account for globals in verifier_arena_large Emil Tsalapatis
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Emil Tsalapatis @ 2025-11-18  3:00 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, john.fastabend, memxor, andrii, eddyz87,
	yonghong.song, Emil Tsalapatis

Modify libbpf to place arena globals in a small offset inside the arena
mapping instead of at the very beginning. This allows programs to leave
the "zero page" of the arena unmapped, so that NULL arena pointer 
dereferences trigger a page fault and associated backtrace in BPF streams.
In contrast, the current policy of placing global data in the zero pages
means that NULL dereferences silently corrupt global data, e.g, arena 
qspinlock state. This makes arena bugs more difficult to debug.

The patchset adds code to libbpf to move global arena data 16 pages into 
the arena mapping. If this move is impossible, libbpf tries progressively
smaller increments, and finally defaults to 0 if there is not enough
space in the arena. At load time, libbpf adjusts each symbol's location
within the arena by that offset. The patchset also adds padding to the 
BPF skeleton struct arena datasec to ensure the arena's fields are 
pointing in the right locations within the mapping.

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>

HISTORY
-------

v1->v2
------

v1: https://lore.kernel.org/bpf/20251117235636.140259-1-emil@etsalapatis.com/

- Fix ifdef guards causing unused variable errors for
  architectures/compilers without addr_space_cast support (CI)

Emil Tsalapatis (4):
  selftests/bpf: explicitly account for globals in verifier_arena_large
  libbpf: add stub for offset-related skeleton padding
  libbpf: offset global arena data into the arena if possible
  selftests/bpf: add tests for the arena offset of globals

 tools/bpf/bpftool/gen.c                       | 23 ++++++-
 tools/lib/bpf/libbpf.c                        | 36 ++++++++++-
 tools/lib/bpf/libbpf.h                        |  9 +++
 tools/lib/bpf/libbpf.map                      |  1 +
 .../selftests/bpf/prog_tests/verifier.c       |  6 ++
 .../bpf/progs/verifier_arena_globals1.c       | 60 ++++++++++++++++++
 .../bpf/progs/verifier_arena_globals2.c       | 49 +++++++++++++++
 .../bpf/progs/verifier_arena_globals3.c       | 61 +++++++++++++++++++
 .../bpf/progs/verifier_arena_large.c          | 25 ++++++--
 9 files changed, 261 insertions(+), 9 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena_globals1.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena_globals2.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena_globals3.c

-- 
2.49.0


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH v2 0/4] libbpf: move arena variables out of the zero
@ 2025-12-03 16:26 Emil Tsalapatis
  2025-12-03 16:26 ` [PATCH v2 1/4] selftests/bpf: explicitly account for globals in verifier_arena_large Emil Tsalapatis
  0 siblings, 1 reply; 15+ messages in thread
From: Emil Tsalapatis @ 2025-12-03 16:26 UTC (permalink / raw)
  To: bpf
  Cc: andrii, eddyz87, ast, daniel, john.fastabend, memxor,
	yonghong.song, Emil Tsalapatis

Modify libbpf to place arena globals in a small offset inside the arena
mapping instead of the very beginning. This allows programs to leave
the "zero page" of the arena unmapped, so that NULL arena pointer
dereferences trigger a page fault and associated backtrace in BPF streams.
In contrast, the current policy of placing global data in the zero pages
means that NULL dereferences silently corrupt global data, e.g, arena
qspinlock state. This makes arena bugs more difficult to debug.

The patchset adds code to libbpf to move global arena data to the end of
the arena. At load time, libbpf adjusts each symbol's location within
the arena to point to the right location in the arena. The patchset 
also adjusts the arena skeleton pointer to point to the arena globals,
now that they are not in the beginning of the arena region.

CHANGESET
=========

v1->v2: (https://lore.kernel.org/bpf/20251118030058.162967-1-emil@etsalapatis.com)

- Moved globals to the end of the mapping: (Andrii)
	- Removed extra parameter for offset and parameter picking logic
	- Removed padding in the skeleton
	- Removed additional libbpf call
- Added Reviewed-by from Eduard on patch 1

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>

Emil Tsalapatis (4):
  selftests/bpf: explicitly account for globals in verifier_arena_large
  bpf/verifier: do not limit maximum direct offset into arena map
  libbpf: move arena globals to the end of the arena
  selftests/bpf: add tests for the arena offset of globals

 kernel/bpf/verifier.c                         |  8 +--
 tools/lib/bpf/libbpf.c                        | 19 ++++--
 .../selftests/bpf/prog_tests/verifier.c       |  4 ++
 .../bpf/progs/verifier_arena_globals1.c       | 58 +++++++++++++++++++
 .../bpf/progs/verifier_arena_globals2.c       | 49 ++++++++++++++++
 .../bpf/progs/verifier_arena_large.c          | 21 +++++--
 6 files changed, 147 insertions(+), 12 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena_globals1.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena_globals2.c

-- 
2.49.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-12-03 16:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18  3:00 [PATCH v2 0/4] libbpf: move arena variables out of the zero page Emil Tsalapatis
2025-11-18  3:00 ` [PATCH v2 1/4] selftests/bpf: explicitly account for globals in verifier_arena_large Emil Tsalapatis
2025-11-22  1:44   ` Eduard Zingerman
2025-11-18  3:00 ` [PATCH v2 2/4] libbpf: add stub for offset-related skeleton padding Emil Tsalapatis
2025-11-18  3:00 ` [PATCH v2 3/4] libbpf: offset global arena data into the arena if possible Emil Tsalapatis
2025-11-22  3:17   ` Eduard Zingerman
2025-12-01 18:34     ` Emil Tsalapatis
2025-12-01 22:35       ` Eduard Zingerman
2025-12-03 16:07         ` Emil Tsalapatis
2025-11-25 22:11   ` Andrii Nakryiko
2025-12-01 20:41     ` Emil Tsalapatis
2025-12-01 22:45       ` Andrii Nakryiko
2025-12-03 16:13         ` Emil Tsalapatis
2025-11-18  3:00 ` [PATCH v2 4/4] selftests/bpf: add tests for the arena offset of globals Emil Tsalapatis
  -- strict thread matches above, loose matches on Subject: below --
2025-12-03 16:26 [PATCH v2 0/4] libbpf: move arena variables out of the zero Emil Tsalapatis
2025-12-03 16:26 ` [PATCH v2 1/4] selftests/bpf: explicitly account for globals in verifier_arena_large Emil Tsalapatis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox