All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sun Jian" <sun.jian.kdev@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] bpf: Unshare cloned skb before devmap egress XDP program
Date: Tue, 09 Jun 2026 10:17:18 +0000	[thread overview]
Message-ID: <20260609101718.7D5511F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260609100214.337538-1-sun.jian.kdev@gmail.com>

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

Pre-existing issues:
- [High] The patch incompletely fixes shared SKB data corruption in generic XDP devmap redirection. When broadcasting to multiple destinations, the original `skb` is used for the final destination (`last_dst`). If `last_dst` has an egress XDP program, it runs directly on the original `skb` and modifies its packet data in-place without checking if it is shared. If prior destinations lacked an egress XDP program, their clones were not unshared by the new logic in `dev_map_redirect_clone()`. Consequently, they still share the same packet data buffer as the original `skb`, and the final destination's egress program will silently corrupt the packet data of the earlier destinations' clones.
--

commit 280ec1e15889a77555ac8877632a39ede4e76d91
Author: Sun Jian <sun.jian.kdev@gmail.com>

bpf: Unshare cloned skb before devmap egress XDP program

This commit modifies dev_map_redirect_clone() to unshare cloned skbs if the
destination devmap entry has an egress XDP program. This prevents modifications
by the egress XDP program from being observed by other clones sharing the same
packet data.

> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index cc0a43ebab6b9..4ae65d44f9d6e 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -730,6 +730,12 @@ static int dev_map_redirect_clone(struct bpf_dtab_netdev *dst,
>  	if (!nskb)
>  		return -ENOMEM;
>  
> +	if (dst->xdp_prog) {
> +		nskb = skb_unshare(nskb, GFP_ATOMIC);
> +		if (!nskb)
> +			return -ENOMEM;
> +	}
> +

[Severity: High]
This is a pre-existing issue, but does this logic still leave the original skb
vulnerable to data corruption during broadcast?

In dev_map_redirect_multi(), the loop clones the skb for N-1 destinations,
and then calls dev_map_generic_redirect() on the original skb for the final
destination:

kernel/bpf/devmap.c:dev_map_redirect_multi() {
    ...
    /* consume the first skb and return */
    if (last_dst)
        return dev_map_generic_redirect(last_dst, skb, xdp_prog);
    ...
}

If the earlier destinations lack an egress XDP program, dev_map_redirect_clone()
will not unshare their clones. If the final destination (last_dst) does have an
egress XDP program, dev_map_bpf_prog_run_skb() will run directly on the original
skb and modify its packet data in-place without ensuring the buffer is unshared:

kernel/bpf/devmap.c:dev_map_bpf_prog_run_skb() {
    ...
    act = bpf_prog_run_generic_xdp(skb, &xdp, dst->xdp_prog);
    ...
}

Could this silently corrupt or truncate the packet data for the earlier
clones that still share the same buffer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609100214.337538-1-sun.jian.kdev@gmail.com?part=1

  reply	other threads:[~2026-06-09 10:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 10:02 [PATCH] bpf: Unshare cloned skb before devmap egress XDP program Sun Jian
2026-06-09 10:17 ` sashiko-bot [this message]
2026-06-09 11:06 ` Menglong Dong
2026-06-10  0:06   ` Emil Tsalapatis
2026-06-10  1:21     ` Menglong Dong
2026-06-10  1:58       ` sun jian
2026-06-10  5:13         ` Jiayuan Chen

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=20260609101718.7D5511F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sun.jian.kdev@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.