[RFC PATCH bpf-next 0/2] bpf: Add bpf_memmem and bpf_dynptr_memmem kfuncs

From: Abhishek Khade

Date: Sun Nov 22 2026 - 05:38:55 EST


This patch series introduces two new BPF kfuncs for binary-safe
substring searching in raw memory and dynamic pointers:
- bpf_memmem(): Searches for a binary needle within a flat memory buffer.
- bpf_dynptr_memmem(): Searches for a binary needle within a BPF dynptr.

Both kfuncs utilize a two-tier search strategy (memchr() for initial byte
matching followed by memcmp()) and enforce maximum buffer length
boundaries (BPF_MEMMEM_MAX_LEN). Selftests covering boundary conditions,
embedded null bytes, and dynptr integration are included.

Abhishek Khade (2):
bpf: Add bpf_memmem and bpf_dynptr_memmem kfuncs
selftests/bpf: Add selftests for bpf_memmem and bpf_dynptr_memmem
kfuncs

kernel/bpf/helpers.c | 115 ++++++++
.../selftests/bpf/prog_tests/memmem_kfunc.c | 9 +
.../selftests/bpf/progs/memmem_kfunc.c | 259 ++++++++++++++++++
3 files changed, 383 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/memmem_kfunc.c
create mode 100644 tools/testing/selftests/bpf/progs/memmem_kfunc.c

--
2.53.0