iptunnel_handle_offloads() records the inner headers when a packet is
encapsulated. For a non-GSO skb without CHECKSUM_PARTIAL, it then clears
skb->encapsulation so that another encapsulation replaces that record.
After nested IPIP packets are decapsulated, iptunnel_pull_offloads()
clears skb->encapsulation but leaves the most recent inner header record
intact. The recorded inner_network_header can then precede skb->data.
If MPLS is pushed, skb_mpls_push() sees inner_protocol still set and
retains the stale offset. OVS fragmentation later uses the negative
network offset as an unsigned copy length:
BUG: KASAN: slab-out-of-bounds in prepare_frag
Read of size 4294967294 at addr ff110000151ab08e by task test/116
Call Trace:
__asan_memcpy
prepare_frag
ovs_fragment
do_execute_actions
ovs_execute_actions
Clear inner_protocol when removing tunnel offload state. This makes the
old offsets inactive until a later encapsulation records current inner
headers. Doing this in iptunnel_pull_offloads() also covers the other
tunnel decapsulation paths which share the helper.
Fixes: 179bc67f69b6 ("net: local checksum offload for encapsulation")
Reported-by: Sashiko <sash…@kernel.org>
Closes: https://lore.kernel.org/netdev/1796…@kernel.org/
Signed-off-by: Kyuwon Cho <kyuw…@gmail.com>
---
Sashiko found this path while reviewing the MPLS fix for the same
ovs_fragment() symptom:
https://lore.kernel.org/netdev/1796…@gmail.com/
That patch clears the stale inner protocol where mpls_forward() pops the
last label; this one fixes the tunnel decapsulation source.
A pending net-next series observes the same stale marker in a separate
XFRM path and handles it at xfrm_output():
https://lore.kernel.org/all/1b35…@bairaktaris.de/
A reproducer is available on request.
Tested with KASAN in KVM on net. The unpatched kernel triggered the
prepare_frag() out-of-bounds read; the patched kernel completed cleanly.
Plain IPIP and GRE traffic passed on both kernels.
include/net/ip_tunnels.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 5cccf4c0e691..1cc0b26556c4 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -670,6 +670,7 @@ static inline int iptunnel_pull_offloads(struct sk_buff *skb)
}
skb->encapsulation = 0;
+ skb->inner_protocol = 0;
return 0;
}
--
2.43.0