> xfrm: ipcomp: account full fragment pages in truesize
TL;DR: In ipcomp_post_acomp(), the truesize increase may unbalance the sender's sk_wmem_alloc for skbs arriving via veth and ESP GRO, possibly underflowing it or freeing the socket early; the patch enlarges an existing mismatch.
> diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c > --- a/net/xfrm/xfrm_ipcomp.c > +++ b/net/xfrm/xfrm_ipcomp.c
[ ... ]
> @@ -67,7 +67,7 @@ static int ipcomp_post_acomp(struct sk_buff *skb, int err, int hlen) > > /* Only update truesize on input. */ > if (!hlen) > - skb->truesize += dlen; > + skb->truesize += PAGE_ALIGN(dlen); > skb->data_len = dlen; > skb->len += dlen;
Can this truesize write unbalance sk_wmem_alloc of the sending socket when the skb arrives through the ESP GRO path? The input branch assumes the skb is not charged to any socket. On the ordinary xfrm4_rcv()/xfrm6_rcv() path the skb was already orphaned in ip_rcv_core()/ip6_rcv_core(), so that holds. But a local UDP or raw sender's skb carries the sock_wfree destructor, and the following path keeps it: veth_xmit() veth_skb_is_eligible_for_gro() accepts skb->destructor == sock_wfree __dev_forward_skb() -> skb_scrub_packet() does not orphan veth_xdp_rcv_skb() skb_prepare_for_gro() only orphans when destructor != sock_wfree napi_gro_receive() inet_gro_receive() -> esp4_gro_receive() -> xfrm_input() ipcomp_input() -> ipcomp_decompress() -> ipcomp_input_done2() ipcomp_post_acomp(skb, err, 0) skb->truesize += PAGE_ALIGN(dlen); The skb is still charged to the sender at that point. Later ip_rcv_core() calls skb_orphan(), and sock_wfree() subtracts the inflated skb->truesize from sk_wmem_alloc, which was only charged with the original value. Each such packet over-subtracts PAGE_ALIGN(dlen) from the sender's sk_wmem_alloc, which can underflow the refcount or drop it to zero early and run __sk_free() while the socket is still in use. The same hazard existed with the old "+= dlen", but this patch enlarges the mismatch by up to PAGE_SIZE - 1 per packet (about 64K on 64K-page kernels). pskb_expand_head() guards this kind of change: if (!skb->sk || skb->destructor == sock_edemux) skb->truesize += size - osize; Would gating the input adjustment the same way keep the receive-side fix without touching a sender's wmem charge? --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46652847109