Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/4] net: skbuff: limit pagecache folio refcount
@ 2026-11-26 21:18 David Hildenbrand (Arm)
  2026-11-26 21:18 ` [PATCH net v2 1/4] net: skbuff: limit folio refcount when copying skb frag references David Hildenbrand (Arm)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-26 21:18 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Stanislav Fomichev, Willem de Bruijn, Simon Horman, Andrew Morton,
	Kiryl Shutsemau, Song Liu, Johannes Weiner, Rik van Riel,
	Matthew Wilcox (Oracle), Neal Cardwell, Kuniyuki Iwashima,
	Pedro Falcato, Chuck Lever, Jeff Layton
  Cc: netdev, linux-kernel, linux-mm, David Hildenbrand (Arm), stable

Hi,

This is v2 of the remaining folio refcount overflow fixes that should go
through the net tree, ideally soon. They address the known cases where
networking can still overflow the folio refcount by taking unbounded
references.

The series is based on Linus' tree, which includes the MM prerequisite
c6c9a4c1c9a16 ("mm: limit pagecache folio refcount when splicing into
pipes") that adds the refcount limit checks to try_get_page().

More details in [1], but in essence:

There are ways to overflow the folio refcount and cause trouble either
by letting it go negative or letting it go all the way back to 0.

This is particularly easy with large pagecache folios, where page table
mappings can "easily" create many references. The MM changes limit
references from page tables, GUP and pipes, and leave some headroom for
races, other bounded refcount users etc.

However, skbs can easily multiply folio references, so any such skb path
that can take unbounded folio references must also obey the new limits: we
must use try_get_page() to obtain an additional folio reference and handle
failures accordingly.

Patch #1 introduces skb_frag_try_ref() and skb_frags_try_ref() and uses
them when copying skb frag references. Patch #2 covers rearranging
frags. Patches #3 and #4 cover splicing pages into skbs and splicing data
from sockets into pipes.

We use existing failure paths where possible. Socket splicing returns
the bytes already spliced, or -EFAULT if no data could be spliced because
try_get_page() failed.

Net paths that take folio references that I don't touch because the
references are either bounded or the paths are not relevant in practice:

 - skb_split(): each reference needs a new socket-charged skb.
 - IP-TFS reassembly: each reference needs a new inner skb.
 - io_uring zerocopy send: each piece is charged >= 4 KiB of TCP memory.
 - kTLS software splicing: only transfers references from the pipe.
 - kTLS device offload: pushing the record fails in skb_append_pagefrags()
   (patch #3), so a socket can exceed the limit by about one record.
 - AF_XDP zerocopy TX, nfsd splice reads, sockmap / sk_msg, espintcp:
   bounded, or require privileges / special setups.
 - Other driver-specific paths: not looked into for now, as I can neither
   test them nor see if they actually trigger unbounded references.
 - page_pool and net_iov frags: not pagecache pages.

The original refcount overflow problem was reported by Anthropic; we
knew that it was possible in theory, but didn't expect to have easy ways
to trigger it. After fixing the splice issue, I used AI to identify
other unbounded folio refcount users, and it flagged various skb-related
paths. I made it actually reproduce unbounded references. These patches
address the paths that were actually reproduced.

I ran tests before and after applying the changes, using a kernel with
reduced folio refcount limits. These tests focused on exercising the new
error paths and checking that the refcount limits were respected.

These tests covered AF_PACKET, nft dup, NFQUEUE, software GSO
segmentation, TCP receive coalescing with dropped ACKs, and socket
splicing.

I also ran the following networking selftests successfully:

 - net:tls
 - net:udp_splice_checksum
 - net:udpgso.sh
 - net:msg_zerocopy.sh

If there are any further tests I can run, please let me know; help with
testing would be appreciated as well, as I only have access to limited
hardware and have limited net experience in general.

[1] https://lore.kernel.org/linux-mm/20261112-refcount_overflow_stable-v4-0-ad3deef0bd23@kernel.org/

Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
Changes in v2:
- "net: skbuff: limit folio refcount when copying skb frag references"
  - Fix skb_zerocopy() kernel-doc indentation
- "net: skbuff: limit folio refcount when splicing pages into skbs"
  - Mention nfsd connection teardown in the description
- "net: skbuff: limit folio refcount when splicing from sockets"
  - Propagate the error through an "err" pointer
  - Document the skb_splice_bits() return value
  - Update the description accordingly
  - Drop Pedro's Ack
- Extend the cover letter
- The GVE issue sashiko reported has already been fixed in commit
  3946899dbeac ("gve: fix RX page refcount overflow from INT_MAX
  pagecnt_bias").
- Link to v1: https://patch.msgid.link/20261118-skb_refcount_overflow-v1-0-5551b4954c3f@kernel.org

---
David Hildenbrand (Arm) (4):
      net: skbuff: limit folio refcount when copying skb frag references
      net: skbuff: limit folio refcount when rearranging skb frags
      net: skbuff: limit folio refcount when splicing pages into skbs
      net: skbuff: limit folio refcount when splicing from sockets

 include/linux/skbuff_ref.h |  53 ++++++++++++++++++++
 net/core/skbuff.c          | 117 +++++++++++++++++++++++++++++----------------
 net/ipv4/tcp_output.c      |   8 ++--
 3 files changed, 134 insertions(+), 44 deletions(-)
---
base-commit: 63fdb511c27afcebce797e3db580b3534ddfa639
change-id: 20261117-skb_refcount_overflow-75a0034e469e

Best regards,
--  
David Hildenbrand (Arm) <david@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26 21:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 21:18 [PATCH net v2 0/4] net: skbuff: limit pagecache folio refcount David Hildenbrand (Arm)
2026-11-26 21:18 ` [PATCH net v2 1/4] net: skbuff: limit folio refcount when copying skb frag references David Hildenbrand (Arm)
2026-11-26 21:18 ` [PATCH net v2 2/4] net: skbuff: limit folio refcount when rearranging skb frags David Hildenbrand (Arm)
2026-11-26 21:18 ` [PATCH net v2 3/4] net: skbuff: limit folio refcount when splicing pages into skbs David Hildenbrand (Arm)
2026-11-26 21:18 ` [PATCH net v2 4/4] net: skbuff: limit folio refcount when splicing from sockets David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox