Re: [PATCH bpf-next v3 2/2] selftests/bpf: Add selftests for bpf_memmem and bpf_dynptr_memmem kfuncs
From: bot+bpf-ci
Date: Sun Nov 22 2026 - 10:18:01 EST
> selftests/bpf: Add selftests for bpf_memmem and bpf_dynptr_memmem kfuncs
TL;DR:
- Test issue: the "periodic" needle "ababac" appears to take the non-periodic
branch, so the periodic memory/shift logic goes untested
- Commit message overstates cases 16 and 17 (no timing or budget check)
> selftests/bpf: Add selftests for bpf_memmem and bpf_dynptr_memmem kfuncs
>
> Add automated BPF selftests validating in-kernel binary byte sequence
> matching for bpf_memmem() and bpf_dynptr_memmem().
> Covered test cases:
[ ... ]
> 16. Periodic needle patterns validating Two-Way critical factorization.
> 17. Pathological repetitive prefix patterns validating linear-time immunity
> without premature budget aborts.
> Signed-off-by: Abhishek Khade <abhishekkhade69@xxxxxxxxx>
This isn't a bug, but the list describes two cases as covering more than
the tests can show.
For item 16, the needle is periodic_needle = "ababac". Its shortest
period is its full length, 6. In __bpf_memmem(), bpf_max_suffix() returns
split 5 with period 1, and bpf_max_suffix_rev() returns split 0, so
split_idx = 5 and period = 1. memcmp("ababa", "babac", 5) is nonzero, so
the search takes the "Case 2: Non-periodic needle" branch. The expected
__retval(2) is what any correct substring search returns. The periodic
branch is actually reached by test_memmem_embedded_null, whose needle
{ 0x00, 0xff, 0x00 } has period 2.
For item 17, test_memmem_repetitive_prefix searches a 31-byte buffer for a
7-byte needle and checks only the offset (24). It does not measure time,
so a quadratic search would pass as well. The kfunc has no comparison
budget, so "without premature budget aborts" describes something this
series does not have.
Would it be more accurate to describe items 16 and 17 as correctness checks
on those inputs? Or could the periodic case use a needle that really is
periodic, for example "abab" or "aaa"? Could the changelog also say why
the cases were chosen instead of only listing them?
> diff --git a/tools/testing/selftests/bpf/progs/memmem_kfunc.c b/tools/testing/selftests/bpf/progs/memmem_kfunc.c
> new file mode 100644
> index 000000000000..eb895906811a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/memmem_kfunc.c
> @@ -0,0 +1,299 @@
[ ... ]
> +static char periodic_buf[] = "abababac";
> +static char periodic_needle[] = "ababac";
[ ... ]
> +SEC("syscall")
> +__success __retval(2)
> +int test_memmem_periodic_pattern(void *ctx)
> +{
> + return bpf_memmem(periodic_buf, sizeof(periodic_buf) - 1,
> + periodic_needle, sizeof(periodic_needle) - 1, 0);
> +}
This isn't a bug, but is test_memmem_periodic_pattern() (and likewise
test_dynptr_memmem_periodic_pattern()) meant to exercise the periodic
branch of __bpf_memmem()?
As written, "ababac" takes the non-periodic branch: bpf_max_suffix() gives
split_idx = 5 with local period 1, and memcmp(n, n + 1, 5) ("ababa"
against "babac") differs, so the search returns 2 from the "Case 2:
Non-periodic needle" loop. Only needle_null ({0x00, 0xff, 0x00}: split 1,
period 2) reaches "Case 1: Periodic needle", and it matches on its first
full right-half comparison. So no test runs the
"h_idx += period; memory = needle_sz - period;" step or the
"n_idx = max(split_idx, memory)" restart with a nonzero memory.
Would a truly periodic needle that also forces a period shift, for example
"abab" searched in "bbababab" (expected 2), cover the memory logic of that
branch?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45034767598