From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: bpf@vger.kernel.org
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
Nathan Malo <nathan.malo@ovhcloud.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>, David Ahern <dsahern@gmail.com>,
netdev@vger.kernel.org
Subject: [PATCH bpf] bpf: Fix stale skb->csum in bpf_redirect_neigh()
Date: Fri, 4 Dec 2026 18:28:11 +0800 [thread overview]
Message-ID: <20261204102812.36739-1-jiayuan.chen@linux.dev> (raw)
Nathan Malo reported a "hw csum failure" splat on a veth peer when a
tc ingress program redirects packets from a NIC with
bpf_redirect_neigh().
A CHECKSUM_COMPLETE skb carries the checksum of the whole packet in
skb->csum, as computed by the NIC. When such a skb is redirected with
bpf_redirect_neigh() from tc ingress, skb->csum ends up wrong:
- __bpf_redirect_neigh() calls bpf_push_mac_rcsum(), which adds the
received L2 header to skb->csum, and then drops that header with a
plain skb_pull(), so it is never subtracted again.
- neigh_output() then pushes the new L2 header without adding it to
skb->csum.
The packet itself is fine, only skb->csum no longer matches it. This
is a transmit path and nobody validates a packet against skb->csum
there, so nothing notices as long as the target is a real NIC.
A veth target is different, the skb is received by the peer as is,
still marked CHECKSUM_COMPLETE. The peer then validates the packet
against the stale skb->csum:
v1: hw csum failure
csum(0x401e814 start=59412 offset=1025 ip_summed=2 complete_sw=0 valid=0 level=0)
Call Trace:
<IRQ>
dump_stack_lvl+0xc1/0xf0
dump_stack+0x10/0x20
netdev_rx_csum_fault+0x6c/0x80
__skb_checksum_complete+0x285/0x2f0
udp_rcv+0x125b/0x2e80
ip_protocol_deliver_rcu+0x23b/0x4a0
ip_local_deliver_finish+0x369/0x5c0
ip_local_deliver+0x165/0x1d0
ip_rcv+0x284/0x320
__netif_receive_skb_one_core+0x16b/0x1c0
__netif_receive_skb+0x21/0x150
process_backlog+0x3ec/0x14d0
__napi_poll.constprop.0+0xa5/0x5e0
net_rx_action+0x4ed/0xeb0
handle_softirqs+0x251/0xa70
__do_softirq+0x10/0x18
do_softirq.part.0+0xab/0x100
</IRQ>
The NIC driver is not at fault here, the value is broken by
bpf_redirect_neigh().
Keeping skb->csum correct is not really an option, the new L2 header
is pushed deep inside neigh_output(). This is a forwarding path, so do
what ip_forward() does and call skb_forward_csum(). skb->csum is not
used after that, so drop the bpf_push_mac_rcsum() call as well.
Fixes: b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")
Reported-by: Nathan Malo <nathan.malo@ovhcloud.com>
Closes: https://lore.kernel.org/netdev/F6F168C5-A1C7-4029-90D3-CD402BC11E33@corp.ovh.com/
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/core/filter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 7f90099ae99c..992dc5c6b594 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2469,13 +2469,13 @@ static int __bpf_redirect_neigh(struct sk_buff *skb, struct net_device *dev,
if (unlikely(skb_network_offset(skb) < ETH_HLEN ||
!pskb_may_pull(skb, ETH_HLEN)))
goto out;
- bpf_push_mac_rcsum(skb);
if (is_multicast_ether_addr(eth_hdr(skb)->h_dest))
goto out;
skb_pull(skb, ETH_HLEN);
skb_unset_mac_header(skb);
skb_reset_network_header(skb);
+ skb_forward_csum(skb);
if (skb->protocol == htons(ETH_P_IP))
return __bpf_redirect_neigh_v4(skb, dev, nh);
--
2.43.0
next reply other threads:[~2026-12-04 10:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:28 Jiayuan Chen [this message]
2026-12-04 13:02 ` [PATCH bpf] bpf: Fix stale skb->csum in bpf_redirect_neigh() Nathan Malo
2026-12-05 3:50 ` patchwork-bot+netdevbpf
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=20261204102812.36739-1-jiayuan.chen@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=nathan.malo@ovhcloud.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=willemb@google.com \
--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 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.