From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 1/2] bpf, sockmap: fix use-after-free when the stream parser resizes the skb
Date: Thu, 18 Jun 2026 10:59:47 +0000 [thread overview]
Message-ID: <20260618105947.F36C91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260618102718.2331468-2-rhkrqnwk98@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The patch attempts to fix a slab-use-after-free by rejecting stream parser programs that modify the SKB, relying on `prog->aux->changes_pkt_data`. However, this flag does not account for `bpf_dynptr_write`, which also modifies the SKB and triggers the exact same use-after-free vulnerability.
--
commit aeac0d3c109078049124a26f6151db8a79f11ac5
Author: Sechang Lim <rhkrqnwk98@gmail.com>
bpf, sockmap: fix use-after-free when the stream parser resizes the skb
This patch rejects stream parser programs that modify packet data to
prevent a use-after-free. The issue occurs when skb_ensure_writable() frees
the frag_list that the stream parser continues to track.
> diff --git a/net/core/sock_map.c b/net/core/sock_map.c
> index 99e3789492a09..c60ba6d292f9a 100644
> --- a/net/core/sock_map.c
> +++ b/net/core/sock_map.c
[ ... ]
> @@ -1515,6 +1515,17 @@ static int sock_map_prog_link_lookup(struct bpf_map *map, struct bpf_prog ***ppr
> return 0;
> }
>
> +static int sock_map_prog_attach_check(enum bpf_attach_type attach_type,
> + struct bpf_prog *prog)
> +{
> + /* A stream parser must not modify the skb, only measure it. */
> + if (prog && attach_type == BPF_SK_SKB_STREAM_PARSER &&
> + prog->aux->changes_pkt_data)
[Severity: Critical]
This isn't a bug introduced by this patch, but does this check completely
prevent the vulnerability?
It appears that prog->aux->changes_pkt_data might be bypassed if a program
uses bpf_dynptr_write(). Looking at bpf_helper_changes_pkt_data() in
net/core/filter.c, BPF_FUNC_dynptr_write is missing from the switch
statement.
Consequently, the verifier does not set prog->aux->changes_pkt_data during
CFG construction for programs that write via dynptrs. While the verifier
sets a local changes_data flag in check_helper_call() to clear packet
pointers:
kernel/bpf/verifier.c:check_helper_call() {
...
/* this will trigger clear_all_pkt_pointers(), which will
* invalidate all dynptr slices associated with the skb
*/
changes_data = true;
...
}
It never sets the permanent env->subprog_info[...].changes_pkt_data flag
for this helper.
Could a malicious BPF_PROG_TYPE_SK_SKB program use bpf_dynptr_from_skb() to
get a writable dynptr, and then call bpf_dynptr_write() to invoke
skb_ensure_writable() and free the frag_list? If so, would this trigger the
exact same use-after-free, completely bypassing this attach-time check?
> + return -EINVAL;
> +
> + return 0;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260618102718.2331468-1-rhkrqnwk98@gmail.com?part=1
next prev parent reply other threads:[~2026-06-18 10:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 10:27 [PATCH bpf v3 0/2] bpf, sockmap: reject a packet-modifying SK_SKB stream parser Sechang Lim
2026-06-18 10:27 ` [PATCH bpf v3 1/2] bpf, sockmap: fix use-after-free when the stream parser resizes the skb Sechang Lim
2026-06-18 10:59 ` sashiko-bot [this message]
2026-06-18 11:56 ` Jiayuan Chen
2026-06-18 18:01 ` John Fastabend
2026-06-18 10:27 ` [PATCH bpf v3 2/2] selftests/bpf: test rejection of a packet-modifying SK_SKB stream parser Sechang Lim
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=20260618105947.F36C91F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=rhkrqnwk98@gmail.com \
--cc=sashiko-reviews@lists.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