Various networking features use MSG_SPLICE_PAGES to add pages to skbs, whereby skb_append_pagefrags() takes a page reference for each fragment it adds. Pages spliced from pipes were already checked when entering the pipe, but in-kernel users like sunrpc pass pagecache pages directly. This allows for exceeding folio refcount limits. This is not specific to large pagecache folios, but with them it is a lot easier to reach the refcount limit, as page table mappings can cheaply create many references. Let's use try_get_page() in skb_append_pagefrags() and fail with -EFAULT. Don't use -EMSGSIZE, as TCP would just retry with a new skb. The only caller, skb_splice_from_iter(), handles that. Fixes: 800d8c63b2e9 ("shmem: add huge pages support") Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS") Fixes: 793917d997df ("mm/readahead: Add large folio readahead") Cc: stable@vger.kernel.org Signed-off-by: David Hildenbrand (Arm) --- net/core/skbuff.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index f473c74956b8b..5e3f910eeea0b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4702,8 +4702,13 @@ int skb_append_pagefrags(struct sk_buff *skb, struct page *page, if (skb_can_coalesce(skb, i, page, offset)) { skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], size); } else if (i < max_frags) { + /* + * Don't use -EMSGSIZE, as callers would just retry with a new + * skb. + */ + if (!try_get_page(page)) + return -EFAULT; skb_zcopy_downgrade_managed(skb); - get_page(page); skb_fill_page_desc_noacc(skb, i, page, offset, size); } else { return -EMSGSIZE; @@ -7575,8 +7580,9 @@ static void skb_splice_csum_page(struct sk_buff *skb, struct page *page, * possible, copying them to fragments if not possible (such as if they're slab * pages). * - * Returns the amount of data spliced/copied or -EMSGSIZE if there's - * insufficient space in the buffer to transfer anything. + * Returns the amount of data spliced/copied, -EMSGSIZE if there's + * insufficient space in the buffer to transfer anything, or -EFAULT if we + * could not take a page reference. */ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, ssize_t maxsize) -- 2.56.0