From: bot+bpf-ci@kernel.org
To: abhishekkhade69@gmail.com,bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,abhishekkhade69@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v3 1/2] bpf: Add bpf_memmem and bpf_dynptr_memmem kfuncs
Date: Sun, 22 Nov 2026 15:17:48 +0000 (UTC) [thread overview]
Message-ID: <9b699575619446beb43aac4209af0de5b6a87be1613b734ce3f009c36a551bae@mail.kernel.org> (raw)
In-Reply-To: <20261122143815.330528-2-abhishekkhade69@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2783 bytes --]
> bpf: Add bpf_memmem and bpf_dynptr_memmem kfuncs
TL;DR: bpf_dynptr_memmem() may return -EINVAL for skb/xdp packets with
non-linear (frag) data, so packet searches can fail even when the needle is
present; the error is also ambiguous.
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
[ ... ]
> +__bpf_kfunc long bpf_dynptr_memmem(const struct bpf_dynptr *haystack,
> + const void *needle, u32 needle__sz,
> + u64 flags)
> +{
[ ... ]
> + size = __bpf_dynptr_size(ptr);
> + if (size > BPF_MEMMEM_MAX_LEN)
> + return -E2BIG;
> + if (size == 0 || needle__sz > size)
> + return -EINVAL;
> +
> + data = __bpf_dynptr_data(ptr, size);
> + if (!data)
> + return -EINVAL;
Can this return -EINVAL for the packet inspection cases the commit message
describes?
__bpf_dynptr_data(ptr, size) is bpf_dynptr_slice(p, 0, NULL, size) with no
bounce buffer. For BPF_DYNPTR_TYPE_SKB that ends up in
skb_pointer_if_linear(), which returns NULL whenever size > skb_headlen(skb).
For BPF_DYNPTR_TYPE_XDP, bpf_xdp_pointer() returns NULL or an ERR_PTR when
the range crosses into frags or is larger than 0xffff. For
BPF_DYNPTR_TYPE_FILE, bpf_file_fetch_bytes() returns -EINVAL for a NULL
buffer, so it always fails.
A TC program calling bpf_dynptr_from_skb(skb, 0, &d) gets a dynptr covering
skb->len, and received skbs commonly keep most of their payload in page
frags. For a typical packet larger than the linear head, such as a TLS
ClientHello, the call fails even though the needle is present.
The neighbouring dynptr kfuncs handle non-linear data explicitly.
bpf_dynptr_memset() falls back to __bpf_dynptr_write() in chunks, and
bpf_dynptr_copy() falls back to __bpf_dynptr_read()/__bpf_dynptr_write().
The kernel-doc lists "non-linear buffer" under -EINVAL, but that code is
shared with invalid flags and invalid parameters (including needle__sz >
size). A program cannot tell "call bpf_skb_pull_data() and retry" from a
real argument error, nor from a packet that is simply shorter than the
needle, which arguably should be -ENOENT (bpf_strnstr() returns -ENOENT in
that case).
Should bpf_dynptr_memmem() search non-linear skb/xdp data, for example by
scanning slices with a needle_sz - 1 overlap, or at least return a distinct
error for the non-linear case? Should the commit message say that TC packet
payloads usually have to be linearized first?
> +
> + match = __bpf_memmem(data, size, needle, needle__sz);
> + if (!match)
> + return -ENOENT;
[ ... ]
---
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
next prev parent reply other threads:[~2026-11-22 15:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 14:38 [PATCH bpf-next v3 0/2] " Abhishek Khade
2026-11-22 14:38 ` [PATCH bpf-next v3 1/2] " Abhishek Khade
2026-11-22 15:17 ` bot+bpf-ci [this message]
2026-11-22 14:38 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add selftests for " Abhishek Khade
2026-11-22 15:17 ` bot+bpf-ci
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9b699575619446beb43aac4209af0de5b6a87be1613b734ce3f009c36a551bae@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=abhishekkhade69@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®