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 v4 2/3] bpf, sockmap: reject a packet-modifying SK_SKB stream parser
Date: Fri, 19 Jun 2026 06:51:51 +0000	[thread overview]
Message-ID: <20260619065152.4CDA31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260619062959.3277612-3-rhkrqnwk98@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Incomplete mitigation for a Use-After-Free in the stream parser. The newly added attach-time check can be bypassed using `bpf_dynptr_write()`.
--

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

bpf, sockmap: reject a packet-modifying SK_SKB stream parser

sk_psock_strp_parse() runs the BPF_PROG_TYPE_SK_SKB stream-parser program
to find the length of the next message. strparser assembles a message out
of several received skbs by chaining them onto the head's frag_list and
recording where to append the next one in strp->skb_nextp. A stream parser
is only meant to measure the next message, so this patch rejects a parser
whose program can change packet data at attach time.

> 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: High]
This isn't a bug introduced by this patch, but could this attach-time check be
bypassed by using bpf_dynptr_write()?

Because BPF_FUNC_dynptr_write is missing from the
bpf_helper_changes_pkt_data() switch statement in net/core/filter.c, and
bpf_dynptr_from_skb() is not flagged by bpf_is_kfunc_pkt_changing(), the
verifier never sets changes_pkt_data for programs using dynptrs to modify
the packet.

If a BPF program obtains a writable dynptr to the SKB using the
bpf_dynptr_from_skb() kfunc, it can modify the packet using the
bpf_dynptr_write() helper.

For SKB dynptrs, bpf_dynptr_write() calls __bpf_dynptr_write() in
kernel/bpf/helpers.c:

	case BPF_DYNPTR_TYPE_SKB:
		return __bpf_skb_store_bytes(dst->data, dst->offset + offset, src, len,
					     flags);

This modifies the SKB and triggers skb_ensure_writable(). If the write
exceeds skb_headlen(skb), this invokes __pskb_pull_tail() and unconditionally
frees the frag_list skbs, causing the exact use-after-free in the stream
parser that this patch intends to fix.

> +		return -EINVAL;
> +
> +	return 0;
> +}
> +

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

  parent reply	other threads:[~2026-06-19  6:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19  6:29 [PATCH bpf v4 0/3] bpf, sockmap: reject a packet-modifying SK_SKB stream parser Sechang Lim
2026-06-19  6:29 ` [PATCH bpf v4 1/3] selftests/bpf: don't modify the skb in the strparser parser prog Sechang Lim
2026-06-19  6:35   ` Jiayuan Chen
2026-06-19  7:08   ` bot+bpf-ci
2026-06-19  6:29 ` [PATCH bpf v4 2/3] bpf, sockmap: reject a packet-modifying SK_SKB stream parser Sechang Lim
2026-06-19  6:35   ` Jiayuan Chen
2026-06-19  6:51   ` sashiko-bot [this message]
2026-06-19  6:29 ` [PATCH bpf v4 3/3] selftests/bpf: test rejection of " Sechang Lim
2026-06-19  6:35   ` Jiayuan Chen
2026-06-19  7:08   ` 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=20260619065152.4CDA31F000E9@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