Re: [RFC PATCH bpf-next 1/2] bpf: Add bpf_memmem and bpf_dynptr_memmem kfuncs
From: bot+bpf-ci
Date: Sun Nov 22 2026 - 06:26:18 EST
> bpf: Add bpf_memmem and bpf_dynptr_memmem kfuncs
TL;DR: Nits only: possibly unreachable needle_sz and !ptr checks in the memmem
kfuncs; the empty-needle branch returns offset 0, contradicting the
documentation.
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
[ ... ]
> +static void *__bpf_memmem(const void *haystack, size_t haystack_sz,
> + const void *needle, size_t needle_sz)
> +{
> + const char *h = haystack;
> + const char *n = needle;
> + const char *end;
> +
> + if (needle_sz == 0)
> + return (void *)haystack;
> + if (needle_sz > haystack_sz)
> + return NULL;
this isn't a bug, but are these two needle_sz checks in __bpf_memmem()
reachable?
Both bpf_memmem() and bpf_dynptr_memmem() already reject needle__sz == 0
and needle__sz > haystack size with -EINVAL before calling it. The
empty-needle branch here also returns a match at offset 0, which is the
opposite of what the kfunc documentation says.
[ ... ]
> + if (!ptr || !ptr->data || !needle || needle__sz == 0)
> + return -EINVAL;
Similarly, can !ptr be true in bpf_dynptr_memmem(), given that the verifier
requires an initialized dynptr argument? The neighbouring dynptr kfuncs
such as bpf_dynptr_slice() only test ptr->data.
---
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/45015018001