mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: david@kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, akpm@linux-foundation.org,
	kas@kernel.org, songliubraving@fb.com, hannes@cmpxchg.org,
	riel@surriel.com, willy@infradead.org, ncardwell@google.com,
	kuniyu@google.com, pfalcato@suse.de, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net 4/4] net: skbuff: limit folio refcount when splicing from sockets
Date: Sun, 22 Nov 2026 09:19:40 +0000	[thread overview]
Message-ID: <179533918041.3135.8460911693239501161@kernel.org> (raw)
In-Reply-To: <20261118-skb_refcount_overflow-v1-4-5551b4954c3f@kernel.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new comment above skb_splice_bits()
  (net/core/skbuff.c:3295-3300) says the function "Returns the number of…

Pre-existing issues:
- [Medium] skb_splice_bits() still returns 0, which callers report as
  EOF, when nothing was spliced because linear_to_page() failed to…

--

net: skbuff: limit folio refcount when splicing from sockets

This patch uses try_get_page() in spd_fill_page() so that splicing from
sockets into pipes cannot push a folio refcount past its limit. On
failure it returns -EFAULT, and the error is propagated as an int
through __splice_segment() and __skb_splice_bits(). skb_splice_bits()
returns the error when nothing was spliced, so the callers don't report
EOF.

> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index c937d74eed6ac..b73fef7a1b460 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c

[ ... ]

> @@ -3284,7 +3294,9 @@ static bool __skb_splice_bits(struct sk_buff *skb, struct pipe_inode_info *pipe,
>  
>  /*
>   * Map data from the skb to a pipe. Should handle both the linear part,
> - * the fragments, and the frag list.
> + * the fragments, and the frag list. Returns the number of bytes spliced,
> + * or an error if we could not splice anything because we could not take
> + * a page reference.
>   */

[Severity: Low]
This isn't a bug, but is this return description complete?

When spd.nr_pages is non-zero, skb_splice_bits() returns whatever
splice_to_pipe() returns. splice_to_pipe() in fs/splice.c can fail for
reasons that have nothing to do with page references:

	if (unlikely(!pipe->readers)) {
		send_sig(SIGPIPE, current, 0);
		ret = -EPIPE;
		goto out;
	}
	...
	if (!ret)
		ret = -EAGAIN;

The reverse case also exists. If linear_to_page() fails in
spd_fill_page(), nothing gets spliced, yet skb_splice_bits() returns 0
and not an error.

Could the comment also mention the -EPIPE and -EAGAIN cases that come
from splice_to_pipe()?

>  int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
>  		    struct pipe_inode_info *pipe, unsigned int tlen,
> @@ -3299,14 +3311,14 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
>  		.ops = &default_pipe_buf_ops,
>  		.spd_release = sock_spd_release,
>  	};
> -	int ret = 0;
> +	int ret;
>  
> -	__skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
> +	ret = __skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
>  
>  	if (spd.nr_pages)
> -		ret = splice_to_pipe(pipe, &spd);
> -
> -	return ret;
> +		return splice_to_pipe(pipe, &spd);
> +	/* Returning 0 would make callers report EOF. */
> +	return ret < 0 ? ret : 0;

[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch. Can the
spurious EOF that this new comment describes still happen when
linear_to_page() fails?

When skb_head_is_locked() is true (a kmalloc'ed head or a cloned skb),
spd_fill_page() goes through linear_to_page(). An allocation failure
there returns a positive value, not a negative errno:

net/core/skbuff.c:linear_to_page() {
	...
	if (!sk_page_frag_refill(sk, pfrag))
		return NULL;
	...
}

net/core/skbuff.c:spd_fill_page() {
	...
	if (linear) {
		page = linear_to_page(page, len, &offset, sk);
		if (!page)
			return true;
	}
	...
}

That 1 is passed up through __splice_segment() and __skb_splice_bits().
With spd.nr_pages == 0, skb_splice_bits() then returns 0 here.

The callers treat the 0 as end of stream even though data is still
queued:

  - unix_stream_read_generic() adds a chunk of 0, breaks because
    unix_skb_len(skb) is non-zero, and returns 0.
  - tcp_splice_read() breaks with ret 0 although the receive queue is
    not empty.
  - kcm_splice_read() and tls_sw_splice_read() return 0 directly.

The old code also returned 0 in this case. Hitting it needs severe
memory pressure, where sk_page_frag_refill() fails both the high-order
and the order-0 allocation.

Would it make sense for spd_fill_page() to return a negative errno such
as -ENOMEM when linear_to_page() fails? That would send it down the same
error path as the try_get_page() failure.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-skb_refcount_overflow-v1-0-5551b4954c3f%40kernel.org

      reply	other threads:[~2026-11-22  9:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:32 [PATCH net 0/4] net: skbuff: limit pagecache folio refcount David Hildenbrand (Arm)
2026-11-18  8:32 ` [PATCH net 1/4] net: skbuff: limit folio refcount when copying skb frag references David Hildenbrand (Arm)
2026-11-19 13:53   ` David Hildenbrand (Arm)
2026-11-20 16:21   ` Stanislav Fomichev
2026-11-20 21:01     ` David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-18  8:32 ` [PATCH net 2/4] net: skbuff: limit folio refcount when rearranging skb frags David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-18  8:32 ` [PATCH net 3/4] net: skbuff: limit folio refcount when splicing pages into skbs David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko
2026-11-18  8:32 ` [PATCH net 4/4] net: skbuff: limit folio refcount when splicing from sockets David Hildenbrand (Arm)
2026-11-22  9:19   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179533918041.3135.8460911693239501161@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=david@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=horms@kernel.org \
    --cc=kas@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=riel@surriel.com \
    --cc=songliubraving@fb.com \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®