Re: [PATCH v5 5/6] bpf: clear decap tunnel GSO state in skb_adjust_room
From: Martin KaFai Lau
Date: Mon Apr 27 2026 - 18:20:21 EST
On Mon, Apr 20, 2026 at 11:19:31AM +0000, bot+bpf-ci@xxxxxxxxxx wrote:
> > + if ((flags & BPF_F_ADJ_ROOM_DECAP_L4_UDP) &&
> > + (shinfo->gso_type & (SKB_GSO_UDP_TUNNEL |
> > + SKB_GSO_UDP_TUNNEL_CSUM)))
> > + shinfo->gso_type &= ~(SKB_GSO_UDP_TUNNEL |
> > + SKB_GSO_UDP_TUNNEL_CSUM);
> > + if ((flags & BPF_F_ADJ_ROOM_DECAP_L4_GRE) &&
> > + (shinfo->gso_type & (SKB_GSO_GRE | SKB_GSO_GRE_CSUM)))
> > + shinfo->gso_type &= ~(SKB_GSO_GRE |
> > + SKB_GSO_GRE_CSUM);
> > + if ((flags & BPF_F_ADJ_ROOM_DECAP_IPXIP4) &&
> > + (shinfo->gso_type & SKB_GSO_IPXIP4))
> > + shinfo->gso_type &= ~SKB_GSO_IPXIP4;
> > + if ((flags & BPF_F_ADJ_ROOM_DECAP_IPXIP6) &&
> > + (shinfo->gso_type & SKB_GSO_IPXIP6))
> > + shinfo->gso_type &= ~SKB_GSO_IPXIP6;
> > +
> > + /* Clear encapsulation flag only when no tunnel GSO flags remain */
> > + if (flags & (BPF_F_ADJ_ROOM_DECAP_L4_MASK |
> > + BPF_F_ADJ_ROOM_DECAP_IPXIP_MASK)) {
> > + if (!(shinfo->gso_type & (SKB_GSO_UDP_TUNNEL |
> > + SKB_GSO_UDP_TUNNEL_CSUM |
> > + SKB_GSO_GRE |
> > + SKB_GSO_GRE_CSUM |
> > + SKB_GSO_IPXIP4 |
> > + SKB_GSO_IPXIP6 |
> > + SKB_GSO_ESP)))
> > + if (skb->encapsulation)
> > + skb->encapsulation = 0;
> > + }
>
> All of this new GSO flag clearing logic is added inside the if (skb_is_gso(skb))
> block in bpf_skb_net_shrink(). Does this mean non-GSO packets bypass the
> decapsulation state clearing?
>
> BPF programs can call bpf_skb_adjust_room() to decapsulate non-GSO packets
> as well. If a non-GSO packet undergoes decapsulation with the tunnel headers
> stripped, but skb->encapsulation remains set, could this cause downstream
> network stack components to misinterpret the packet as still being
> encapsulated?
It has been asked multiple times by different AI review agents but has been
ignored afaik. Please reply/address it so they won't reiterate. From
a quick look, bpf_skb_net_grow() sets the encapsulation regardless
of skb_is_gso.