ip6_gre: check tunnel info before xmit in ip6gre_tunnel_xmit
Subsystems (3)
PATCH 1/1 ip6_gre: check tunnel info before xmit in ip6gre_tunnel_xmit
Shuangpeng Bai reported a KASAN slab-use-after-free in ip6gre_tunnel_xmit().
The precise KASAN bug was caused by ip6_tnl_xmit() consuming the skb during headroom expansion and returning an error, while ip6gre_tunnel_xmit() still held the stale pointer and called skb_tunnel_info_txcheck(skb) at tx_err. That specific bug was fixed by commit 87f21b59ddc6 ("ip6_tunnel: use skb_cow_head() in ip6_tnl_xmit()").
However, calling skb_tunnel_info_txcheck(skb) at the tx_err label after the transmission attempt remains problematic:
Downstream helpers like ip6_tnl_xmit() call skb_scrub_packet(), which drops the skb's metadata_dst before transmission. If an error occurs later during transmit, inspecting skb at tx_err sees a scrubbed dst and misclassifies tx_errors vs tx_dropped.
Commit e5f7e211b6aa ("ip6gre: avoid tx_error when sending MLD/DAD on external tunnels") already handled this correctly in ip6erspan_tunnel_xmit() by checking and caching tun_info before transmit.
Align ip6gre_tunnel_xmit() with ip6erspan_tunnel_xmit() by caching tun_info before xmit and checking it at tx_err.
--- net/ipv6/ip6_gre.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/ipv6/ip6_gre.c +5 -1
@@ -878,6 +878,7 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)static netdev_tx_t ip6gre_tunnel_xmit (struct sk_buff *skb,struct net_device *dev) { +struct ip_tunnel_info *tun_info =NULL ;struct ip6_tnl *t =netdev_priv (dev);__be16 payload_protocol;int ret;
@@ -888,6 +889,9 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,if (!ip6_tnl_xmit_ctl (t, &t->parms.laddr, &t->parms.raddr)) goto tx_err; +if (t->parms.collect_md) + tun_info =skb_tunnel_info_txcheck (skb); + payload_protocol =skb_protocol (skb, true);switch (payload_protocol) {case htons (ETH_P_IP ):
@@ -907,7 +911,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; tx_err: -if (!t->parms.collect_md || !IS_ERR (skb_tunnel_info_txcheck (skb))) +if (!IS_ERR (tun_info))DEV_STATS_INC (dev, tx_errors);DEV_STATS_INC (dev, tx_dropped);kfree_skb (skb);
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Quoted 22 lines · Eric Dumazet
Shuangpeng Bai reported a KASAN slab-use-after-free in
ip6gre_tunnel_xmit().The precise KASAN bug was caused by
ip6_tnl_xmit()consuming the skb during headroom expansion and returning an error, whileip6gre_tunnel_xmit()still held the stale pointer and calledskb_tunnel_info_txcheck(skb)attx_err. That specific bug was fixed by commit87f21b59ddc6("ip6_tunnel: useskb_cow_head()inip6_tnl_xmit()").However, calling
skb_tunnel_info_txcheck(skb)at thetx_errlabel after the transmission attempt remains problematic:Downstream helpers like
ip6_tnl_xmit()callskb_scrub_packet(), which drops the skb'smetadata_dstbefore transmission. If an error occurs later during transmit, inspecting skb attx_errsees a scrubbed dst and misclassifiestx_errorsvstx_dropped.Commit
e5f7e211b6aa("ip6gre: avoidtx_errorwhen sending MLD/DAD on external tunnels") already handled this correctly inip6erspan_tunnel_xmit()by checking and cachingtun_infobefore transmit.
Quoted 8 lines
Align
ip6gre_tunnel_xmit()withip6erspan_tunnel_xmit()by cachingtun_infobefore xmit and checking it attx_err.Fixes e5f7e211b6aa ("ip6gre: avoid tx_error when sending MLD/DAD on external tunnels")Reported-by Shuangpeng Bai <[email protected]>Cc Davide Caratti <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 28 Aug 2026 10:37:31 +0000 you wrote:
Shuangpeng Bai reported a KASAN slab-use-after-free in
ip6gre_tunnel_xmit().The precise KASAN bug was caused by
ip6_tnl_xmit()consuming the skb during headroom expansion and returning an error, whileip6gre_tunnel_xmit()still held the stale pointer and calledskb_tunnel_info_txcheck(skb)attx_err. That specific bug was fixed by commit87f21b59ddc6("ip6_tunnel: useskb_cow_head()inip6_tnl_xmit()").[...]
Here is the summary with links:
- [net] ip6_gre: check tunnel info before xmit in ip6gre_tunnel_xmit
https://git.kernel.org/netdev/net/c/97cc84dad1d7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html