linux/net/xfrm
Mina Almasry 1f6f88105e net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref()
Previously, __skb_frag_ref() and skb_frag_ref() unconditionally
incremented the non-pp backing refcount via get_netmem(), while
skb_frag_unref() decremented pp_ref_count whenever skb->pp_recycle was
set. Ref-ing a page_pool fragment into a pp_recycle=1 SKB (or clearing
pp_recycle=0 on an uncloned SKB while clones still held pp_recycle=1)
leaked the backing non-pp refcount and underflowed pp_ref_count across
IP-TFS, skb_split(), skb_shift(), and cloned unclone paths.

Replace __skb_frag_ref() with skb_netmem_ref(netmem, recycle) as the
exact counterpart to skb_netmem_unref(netmem, recycle):

- Keep skb->pp_recycle intact in skb_release_data() so uncloning paths
  (pskb_expand_head() and pskb_carve_inside_{header,nonlinear}()) keep
  trading pp_ref_count references symmetrically across clones.
- Propagate pp_recycle and call skb_frag_ref() on the destination SKB in
  __pskb_copy_fclone(), skb_zerocopy(), skb_split(), skb_shift(), and
  skb_segment().
- Linearize an output segment's existing frags in skb_segment() before
  attaching frags from a frag_list SKB with a different pp_recycle bit,
  since each output segment carries a single pp_recycle bit.
- Use skb_frag_ref() in xfrm_iptfs, chcr_ktls, and cassini, and call
  get_netmem() directly in veth and tls_device_fallback where callers
  explicitly take a raw non-pp reference.

Found by code inspection while reviewing the IP-TFS pp_ref_count fix [1]
and confirmed with the KUnit tests added later in this series; not
observed in production. The xfrm_iptfs, chcr_ktls, cassini, veth, and
tls_device_fallback changes are compile-tested only.

Link: https://lore.kernel.org/netdev/xfrm-iptfs-pp_ref_count-underflow-v4-1-912fa72106f0@secunet.com/ [1]
Cc: Antony Antony <antony.antony@secunet.com>
Cc: Stanislav Fomichev <sdf@fomichev.me>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jesper Dangaard Brouer <hawk@kernel.org>
Cc: bpf@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Mina Almasry <almasrymina@google.com>
Tested-by: Antony Antony <antony.antony@secunet.com>
Link: https://patch.msgid.link/20261014173945.373295-5-almasrymina@google.com
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2026-10-20 11:52:46 +02:00
..
espintcp.c net: xfrm: reject unrepresentable espintcp transport headers 2026-09-01 12:24:11 +02:00
Kconfig pfkey: Deprecate pfkey 2025-10-30 09:03:12 +01:00
Makefile xfrm: iptfs: add new iptfs xfrm mode impl 2024-12-05 10:01:35 +01:00
trace_iptfs.h xfrm: iptfs: add tracepoint functionality 2024-12-05 10:02:36 +01:00
xfrm_algo.c xfrm: Drop support for HMAC-RIPEMD-160 2026-04-07 10:47:58 +02:00
xfrm_compat.c xfrm: add XFRM_MSG_MIGRATE_STATE for single SA migration 2026-06-04 12:22:47 +02:00
xfrm_device.c xfrm: cache the offload ifindex for netlink dumps 2026-07-02 09:12:58 +02:00
xfrm_hash.c
xfrm_hash.h
xfrm_inout.h
xfrm_input.c xfrm: save input state data before secpath resets 2026-09-01 12:24:11 +02:00
xfrm_interface_bpf.c
xfrm_interface_core.c xfrm: xfrm_interface: require CAP_NET_ADMIN in the device netns for changelink 2026-06-17 16:01:53 -07:00
xfrm_ipcomp.c xfrm: ipcomp: Free destination pages on acomp errors 2026-05-11 10:34:35 +02:00
xfrm_iptfs.c net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref() 2026-10-20 11:52:46 +02:00
xfrm_nat_keepalive.c ipsec-2026-08-18 2026-08-20 11:38:14 -07:00
xfrm_output.c ipv4: validate checksum_start before completing checksum 2026-10-08 11:03:47 -07:00
xfrm_policy.c xfrm: Check netif_is_alive() in xfrm_bundle_create() and xfrm_create_dummy_bundle(). 2026-10-06 15:56:16 -07:00
xfrm_proc.c xfrm: snmp: do not use SNMP_MIB_SENTINEL anymore 2025-09-08 18:06:21 -07:00
xfrm_replay.c ipsec-2025-01-27 2025-01-27 15:15:12 -08:00
xfrm_state_bpf.c bpf: xfrm: drop dead NULL check in bpf_xdp_get_xfrm_state() 2026-01-02 12:04:29 -08:00
xfrm_state.c xfrm: use hlist_del_init_rcu for state_cache and state_cache_input 2026-08-24 07:27:48 +02:00
xfrm_sysctl.c net: Const qualify ctl_tables that kmemdup unconditionally 2026-08-13 13:12:24 +02:00
xfrm_user.c xfrm: fix compat ALLOCSPI request use-after-free 2026-08-18 12:16:19 +02:00