Skip to content

bpf: Add arena ASAN runtime and BPF library

Emil Tsalapatis bpf 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest13 patches 14 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13bpf: Add bpf_stream_print_stack stack dumping kfunckernel/bpf/helpers.c kernel/bpf/stream.c tools/lib/bpf/bpf_helpers.h+16 -03 replies
2/13bpf: Allow BPF stream kfuncs while holding a lockkernel/bpf/verifier.c+12 -11 reply
3/13selftests: bpf: Move bpf_arena_spin_lock.h to the top leveltools/testing/selftests/bpf/bpf_arena_spin_lock.h tools/testing/selftests/bpf/progs/arena_spin_lock.c+3 -31 reply
4/13selftests: bpf: Make WRITE_ONCE macro in bpf_atomic.h conditionaltools/testing/selftests/bpf/bpf_atomic.h+2 -03 replies
5/13selftests: bpf: Add basic libarena scaffoldingtools/testing/selftests/bpf/.gitignore tools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/libarena/Makefile +4 more+460 -02 replies
6/13selftests: bpf: Add arena ASAN runtime to libarenatools/testing/selftests/bpf/.gitignore tools/testing/selftests/bpf/libarena/include/asan.h tools/testing/selftests/bpf/libarena/src/asan.bpf.c+597 -01 reply
7/13selftests: bpf: Add ASAN support for libarena selfteststools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/libarena/Makefile tools/testing/selftests/bpf/libarena/include/userapi.h +2 more+155 -41 reply
8/13selftest: bpf: Add bump allocator for libarenatools/testing/selftests/bpf/libarena/include/bump.h tools/testing/selftests/bpf/libarena/src/bump.bpf.c+222 -01 reply
9/13selftests: bpf: Add libarena selftests for the bump allocatortools/testing/selftests/bpf/libarena/selftests/selftest.c tools/testing/selftests/bpf/libarena/selftests/st_asan_bump.bpf.c tools/testing/selftests/bpf/libarena/selftests/st_bump.bpf.c+486 -00 replies
10/13selftest: bpf: Add libarena stack allocatortools/testing/selftests/bpf/libarena/include/stack.h tools/testing/selftests/bpf/libarena/src/stack.bpf.c+382 -00 replies
11/13selftests: bpf: Add selftests for the libarena stack allocatortools/testing/selftests/bpf/libarena/selftests/selftest.c tools/testing/selftests/bpf/libarena/selftests/st_asan_stack.bpf.c+255 -01 reply
12/13selftests: bpf: Add buddy allocator for libarenatools/testing/selftests/bpf/libarena/include/buddy.h tools/testing/selftests/bpf/libarena/src/buddy.bpf.c+846 -00 replies
13/13selftests: bpf: Add selftests for the libarena buddy allocatortools/testing/selftests/bpf/libarena/selftests/selftest.c tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c+473 -00 replies

Reviews trailers per patch

2 of 13 patches have a Reviewed-by or Acked-by.

PatchKumar Kartikeya Dwivedi
1/13
2/13A-b
3/13A-b
4/13
5/13
6/13
7/13
8/13
9/13
10/13
11/13
12/13
13/13

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/13] bpf: Add arena ASAN runtime and BPF library

Add a new subdirectory to tools/testing/selftests/bpf called libarena, along with programs useful for writing arena-based BPF code. This patchset adds the following:

1) libarena, a subdirectory where arena BPF code that is generally useful to BPF arena programs can be easily added and tested.

2) An ASAN runtime for BPF arena programs. BPF arenas allow for accessing memory after it has been freed or if it out of bounds, making it more difficult to triage bugs combined to regular BPF. Use LLVM's recently added support for address-space based sanitization to selectively sanitize just the arena accesses.

3) A set of memory allocators that can be reused by BPF programs to handle memory allocation/deletion. The allocators use the ASAN runtime to add address sanitization if requested.

The patch includes testing for the new allocators and ASAN features that can be built from the top directory using "make libarena_test" and "make libarena_test_asan". The generated binaries reside in libarena/.

The structure of this patch is:

1-2: Add BPF Streams kfunc for dumping the current program stack, and allow BPF Streams kfuncs to be callable while holding a lock.

3-4: Minor changes to the /testing/selftests/bpf directory headers to prepare for the introduction of libarena.

5-7: Add the base libarena directory and testing scaffolding, and introduce the ASAN runtime.

8-9: Add a arena memory bump allocator along with testing. This allocator is used for permanent allocations during program init.

10-11: Add a stack page-oriented allocator along with testing. This allocator is used for repeated large allocations to avoid constant bpf_arena_{alloc,free}_pages calls.

12-13: Add a buddy allocator along with testing. The allocator acts as a general allocator for arena-based BPF programs.

v1->v2 (https://lore.kernel.org/bpf/[email protected]/)

- Added missing format string argument (AI)
- Fix outdated selftests prog name check (AI)
- Fixed stack allocation check for segment creation (AI)
- Fix errors in non-ASAN bump allocator selftests (AI)
- Propagate error value from individual selftests in selftest.c
- Removed embedded metadata from bump allocator as it was needlessly complicating its behavior

Emil Tsalapatis (13):
bpf: Add bpf_stream_print_stack stack dumping kfunc
bpf: Allow BPF stream kfuncs while holding a lock
selftests: bpf: Move bpf_arena_spin_lock.h to the top level
selftests: bpf: Make WRITE_ONCE macro in bpf_atomic.h conditional
selftests: bpf: Add basic libarena scaffolding
selftests: bpf: Add arena ASAN runtime to libarena
selftests: bpf: Add ASAN support for libarena selftests
selftest: bpf: Add bump allocator for libarena
selftests: bpf: Add libarena selftests for the bump allocator
selftest: bpf: Add libarena stack allocator
selftests: bpf: Add selftests for the libarena stack allocator
selftests: bpf: Add buddy allocator for libarena
selftests: bpf: Add selftests for the libarena buddy allocator

 kernel/bpf/helpers.c                          |   1 +
 kernel/bpf/stream.c                           |  13 +
 kernel/bpf/verifier.c                         |  13 +-
 tools/lib/bpf/bpf_helpers.h                   |   2 +
 tools/testing/selftests/bpf/.gitignore        |   2 +
 tools/testing/selftests/bpf/Makefile          |  24 +
 .../bpf/{progs => }/bpf_arena_spin_lock.h     |   4 +-
 tools/testing/selftests/bpf/bpf_atomic.h      |   2 +
 tools/testing/selftests/bpf/libarena/Makefile |  69 ++
 .../selftests/bpf/libarena/include/asan.h     | 133 +++
 .../selftests/bpf/libarena/include/buddy.h    |  62 ++
 .../selftests/bpf/libarena/include/bump.h     |  26 +
 .../selftests/bpf/libarena/include/common.h   | 118 +++
 .../selftests/bpf/libarena/include/stack.h    |  44 +
 .../selftests/bpf/libarena/include/userapi.h  |  23 +
 .../bpf/libarena/selftests/selftest.c         | 328 ++++++++
 .../bpf/libarena/selftests/selftest.h         |  17 +
 .../libarena/selftests/st_asan_buddy.bpf.c    | 238 ++++++
 .../bpf/libarena/selftests/st_asan_bump.bpf.c | 193 +++++
 .../bpf/libarena/selftests/st_asan_common.h   |  49 ++
 .../libarena/selftests/st_asan_stack.bpf.c    | 253 ++++++
 .../bpf/libarena/selftests/st_buddy.bpf.c     | 231 ++++++
 .../bpf/libarena/selftests/st_bump.bpf.c      | 281 +++++++
 .../selftests/bpf/libarena/src/asan.bpf.c     | 463 +++++++++++
 .../selftests/bpf/libarena/src/buddy.bpf.c    | 784 ++++++++++++++++++
 .../selftests/bpf/libarena/src/bump.bpf.c     | 196 +++++
 .../selftests/bpf/libarena/src/stack.bpf.c    | 338 ++++++++
 .../selftests/bpf/progs/arena_spin_lock.c     |   2 +-
 28 files changed, 3905 insertions(+), 4 deletions(-)
 rename tools/testing/selftests/bpf/{progs => }/bpf_arena_spin_lock.h (99%)
 create mode 100644 tools/testing/selftests/bpf/libarena/Makefile
 create mode 100644 tools/testing/selftests/bpf/libarena/include/asan.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/buddy.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/bump.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/common.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/stack.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/userapi.h
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/selftest.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/selftest.h
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_bump.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_common.h
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_stack.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_bump.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/asan.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/bump.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/stack.bpf.c
Signature · 1 line
2.49.0