Re: [PATCH net 4/4] net: skbuff: limit folio refcount when splicing from sockets

From: Paolo Abeni

Date: Thu Nov 26 2026 - 09:18:51 EST


On 11/18/26 09:32, David Hildenbrand (Arm) wrote:
@@ -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;

AFAICS the above introduces a change of behavior:
caller with tlen==0 get 1 as return value, while they
used to get EOF. I think the return code from
`__skb_splice_bits` should be ignored, when not negative.

I think the churn here could be reduced re-using the `len`
ptr argument to store the error code; something alike the
(completely untested) following:

---
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 85d5caa08887..9fd5116f33f3 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3177,6 +3177,10 @@ static bool spd_fill_page(struct splice_pipe_desc *spd, struct page *page,
spd->partial[spd->nr_pages - 1].len += *len;
return false;
}
+ if (!try_get_page(page)) {
+ *len = -EFAULT;
+ return true;
+ }
get_page(page);
spd->pages[spd->nr_pages] = page;
spd->partial[spd->nr_pages].len = *len;
@@ -3299,6 +3303,8 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
int ret = 0;

__skb_splice_bits(skb, pipe, &offset, &tlen, &spd, sk);
+ if (tlen < 0)
+ return tlen;

if (spd.nr_pages)
ret = splice_to_pipe(pipe, &spd);
---

which is arguably ugly but IMHO no more than the tristate
return value in the current version.

Possibly some comment around __skb_splice_bits and/or
spd_fill_page() would make this option more palatable.

/P