BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2] bpf, sockmap: fix use-after-free when the stream parser resizes the skb
Date: Fri, 12 Jun 2026 12:57:52 +0000	[thread overview]
Message-ID: <20260612125753.124221F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612123553.2724240-1-rhkrqnwk98@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] BPF program modifications to the packet payload and the `cb` array are lost for fragmented packets, breaking API contracts and state passing.
- [High] Returning 0 on `skb_clone` allocation failure causes a structural connection stall.
--

commit b299b25e2b7e463fddbfdeb09ab2432fcc43e867
Author: Sechang Lim <rhkrqnwk98@gmail.com>

bpf, sockmap: fix use-after-free when the stream parser resizes the skb

This commit fixes a use-after-free in the stream parser when a BPF program
resizes the skb. It runs the parser on a clone of the skb when the message
spans multiple fragments and the program can modify the packet data.

> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index e1850caf1a71a..97e5bc5f38c35 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -1149,9 +1149,29 @@ static int sk_psock_strp_parse(struct strparser *strp, struct sk_buff *skb)
>  	rcu_read_lock();
>  	prog = READ_ONCE(psock->progs.stream_parser);
>  	if (likely(prog)) {
[ ... ]
> +		if (skb_has_frag_list(skb) && prog->aux->changes_pkt_data) {
> +			parse_skb = skb_clone(skb, GFP_ATOMIC);
> +			if (!parse_skb) {
> +				rcu_read_unlock();
> +				return 0;

[Severity: High]
Does returning 0 here cause a connection stall?

In the strparser framework (__strp_recv), a return value of 0 from parse_msg
explicitly signals that it needs more data to determine the message length.
This causes the parser to consume the current bytes and suspend parsing until
new data arrives.

If the sender has transmitted a complete request and is waiting for a response,
will the connection stall indefinitely since no new data will arrive?

> +			}
> +		}
> +		parse_skb->sk = psock->sk;
> +		ret = bpf_prog_run_pin_on_cpu(prog, parse_skb);
> +		parse_skb->sk = NULL;
> +		if (parse_skb != skb)
> +			consume_skb(parse_skb);

[Severity: High]
If the BPF program modifies the cb array or packet payload on the clone
(parse_skb), do these changes get silently discarded when consume_skb()
is called?

BPF sk_skb programs are explicitly permitted to use the cb array (the first
20 bytes of skb->cb) to pass state between the stream parser and stream
verdict programs.

When the program runs on a transient clone, modifications to the cb array or
the packet payload are lost when the clone is freed. For non-fragmented
packets, the program runs on the original skb and modifications persist.

Could this structural inconsistency break BPF programs that rely on state
passing, or allow attackers to bypass BPF security policies by artificially
fragmenting traffic?

>  	}
>  	rcu_read_unlock();
>  	return ret;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260612123553.2724240-1-rhkrqnwk98@gmail.com?part=1

  reply	other threads:[~2026-06-12 12:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 12:35 [PATCH bpf v2] bpf, sockmap: fix use-after-free when the stream parser resizes the skb Sechang Lim
2026-06-12 12:57 ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-06-12 11:34 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=20260612125753.124221F000E9@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