From: Xiang Mei <xmei5@asu.edu>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, co+ff13a35f73bb7891@bugs.sh,
stable@vger.kernel.org, Xiang Mei <xmei5@asu.edu>
Subject: [PATCH net] bpf: lwt: clear stale IP control block after pushing an encap header
Date: Tue, 15 Sep 2026 21:11:02 -0700 [thread overview]
Message-ID: <20260916041102.1914333-1-xmei5@asu.edu> (raw)
bpf_lwt_push_ip_encap() prepends an encapsulation header and calls
skb_reset_network_header(), but leaves the IP control block describing the
inner header. Its offsets are relative to the network header, so they now
point into the encapsulated packet.
On an ingress lwt-bpf encap route a forwarded packet carrying a Record
Route option then reaches __ip_options_echo() with a stale opt->rr. It
takes the option length from the packet and copies up to 255 bytes into the
fixed-size option storage on the __icmp_send() stack. ip_forward_options()
writes at a packet-controlled offset for the same reason.
Clear the stale state once the outer header is in place, as the tunnel
encapsulators do and as seg6_local.c was taught to do in commit
f967455fb2a5 ("seg6: reset IP6CB after IPv6 decapsulation") and commit
44930446dde4 ("ipv6: seg6: clear IPv4 control block on IPIP
decapsulation").
BUG: KASAN: stack-out-of-bounds in __ip_options_echo (net/ipv4/ip_options.c:96)
Write of size 255 at addr ffff8880bee08930 by task exploit/150
Call Trace:
<IRQ>
__asan_memcpy (mm/kasan/shadow.c:106)
__ip_options_echo (net/ipv4/ip_options.c:96)
__icmp_send (net/ipv4/icmp.c:949)
ip_forward (./include/net/icmp.h:43 net/ipv4/ip_forward.c:176)
lwtunnel_input (net/core/lwtunnel.c:465)
ip_rcv (net/ipv4/ip_input.c:612)
__netif_receive_skb_one_core (net/core/dev.c:6264)
process_backlog (net/core/dev.c:6728)
__napi_poll (net/core/dev.c:7787)
net_rx_action (net/core/dev.c:8007)
handle_softirqs (kernel/softirq.c:645)
do_softirq.part.0 (kernel/softirq.c:546)
</IRQ>
__local_bh_enable_ip (kernel/softirq.c:473)
__dev_queue_xmit (net/core/dev.c:4961)
packet_sendmsg (net/packet/af_packet.c:3143)
__sys_sendto (net/socket.c:2281)
__x64_sys_sendto (net/socket.c:2288)
do_syscall_64 (arch/x86/entry/syscall_64.c:84)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Cc: stable@vger.kernel.org
Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap")
Reported-by: <co+ff13a35f73bb7891@bugs.sh>
Assisted-by: LLM
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
net/core/lwt_bpf.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
index da49364ec63d..17be476b5717 100644
--- a/net/core/lwt_bpf.c
+++ b/net/core/lwt_bpf.c
@@ -649,6 +649,18 @@ int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress)
if (ingress)
skb_postpush_rcsum(skb, iph, len);
skb_reset_network_header(skb);
+ if (ipv4) {
+ memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
+ } else {
+ bool l3slave = ipv6_l3mdev_skb(IP6CB(skb)->flags);
+ int iif = IP6CB(skb)->iif;
+
+ memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
+ IP6CB(skb)->iif = iif;
+ IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
+ if (l3slave)
+ IP6CB(skb)->flags |= IP6SKB_L3SLAVE;
+ }
if (is_udp_tunnel) {
size_t iph_sz = ipv4 ? iph->ihl * 4 : sizeof(struct ipv6hdr);
--
2.43.0
next reply other threads:[~2026-09-16 4:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 4:11 Xiang Mei [this message]
2026-09-16 7:32 ` [PATCH net] bpf: lwt: clear stale IP control block after pushing an encap header Xiang Mei
2026-09-16 9:41 ` Eric Dumazet
2026-09-20 4:35 ` netdev-bot+sashiko
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=20260916041102.1914333-1-xmei5@asu.edu \
--to=xmei5@asu.edu \
--cc=bpf@vger.kernel.org \
--cc=co+ff13a35f73bb7891@bugs.sh \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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