A decap with bpf_skb_adjust_room() corrupts skb->transport_header if an unset skb->inner_transport_header has wrapped around. An unset inner transport header is in front of skb->data, so bpf_skb_net_hdr_pop() resets it. But its offset wraps around if the skb is copied to a buffer with less headroom: tcp4_gro_complete() /* fraglist: inner_transport_header stays 0 */ skb_pp_cow_data() /* 64 bytes less headroom */ skb_headers_offset_update() /* inner_transport_header = 65472 */ bpf_skb_net_shrink() bpf_skb_net_hdr_pop() /* doesn't reset it */ bpf_skb_clear_encap() /* copies it to transport_header */ qdisc_pkt_len_segs_init() /* SKB_DROP_REASON_SKB_BAD_GSO */ The fix used here is to treat a wrapped offset as one in front of skb->data. Fixes: 33be492c2e23 ("bpf: Use the inner transport header after a decap") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason --- net/core/filter.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index ea20fd2be65c0..892e20291283d 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3456,9 +3456,12 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len) /* It was in the removed bytes or before skb->data. */ skb_set_transport_header(skb, off); } - /* Do not leave the inner transport header in front of @off. */ + /* + * Do not leave the inner transport header in front of @off. If + * nobody has set it, its offset can have wrapped. + */ if (skb->encapsulation && - skb_inner_transport_offset(skb) < (int)off) + (s16)skb_inner_transport_offset(skb) < (int)off) skb_set_inner_transport_header(skb, off); }