* [PATCH bpf v2] net: skmsg: fix copy cursor when coalescing clones
@ 2026-11-20 21:45 Kyle Zeng
2026-11-20 22:50 ` Jiayuan Chen
0 siblings, 1 reply; 2+ messages in thread
From: Kyle Zeng @ 2026-11-20 21:45 UTC (permalink / raw)
To: bpf
Cc: john.fastabend, jakub, jiayuan.chen, netdev, alexei.starovoitov,
Kyle Zeng, stable
A splice or zero-copy append can leave the destination copy cursor at
sg.end. If sk_msg_clone() subsequently coalesces with the last entry,
sg.end does not advance and the cursor still points at an unused slot.
sk_msg_memcopy_from_iter() can then walk around the ring and write into
older entries, including file pages spliced from a read-only descriptor.
Software TLS can reach this with an ordinary MSG_MORE send after a file
splice and a splice from another TCP socket. Both TCP and the TLS
encrypted-message allocation can use the sending task's page fragment,
so the TCP-sourced plaintext can be contiguous with the next cloned
encrypted-message range.
When coalescing with an exhausted destination, move the copy cursor to
the tail and set copybreak to its old length before extending it. Find
the actual tail on each iteration using the ring iterator, including
when end wraps to zero. Leave an existing copy cursor unchanged and
preserve the normal coalescing, reference counting, and memory charging.
The issue was found by an LLM.
Fixes: fda497e5f5b8 ("Optimize sk_msg_clone() by data merge to end dst sg entry")
Cc: stable@vger.kernel.org
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
v2:
- Rebase onto the BPF fixes tree; no code changes.
v1: https://lore.kernel.org/bpf/20261030042138.73739-1-kylebot@openai.com/
I have a reproducer for this issue and can share via DM
net/core/skmsg.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 8a3b8536c0c2..f47c59ba1ec6 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -103,16 +103,26 @@ int sk_msg_clone(struct sock *sk, struct sk_msg *dst, struct sk_msg *src,
}
while (len) {
+ int last = dst->sg.end;
+
sge_len = sge->length - off;
if (sge_len > len)
sge_len = len;
- if (dst->sg.end)
- sgd = sk_msg_elem(dst, dst->sg.end - 1);
+ sgd = NULL;
+ if (dst->sg.size) {
+ sk_msg_iter_var_prev(last);
+ sgd = sk_msg_elem(dst, last);
+ }
if (sgd &&
(sg_page(sge) == sg_page(sgd)) &&
(sg_virt(sge) + off == sg_virt(sgd) + sgd->length)) {
+ /* Start copying at the newly cloned suffix. */
+ if (dst->sg.curr == dst->sg.end) {
+ dst->sg.curr = last;
+ dst->sg.copybreak = sgd->length;
+ }
sgd->length += sge_len;
dst->sg.size += sge_len;
} else if (!sk_msg_full(dst)) {
base-commit: d5ba86298b45e1a81c578c499e9a222a3b734d5d
--
2.55.0.openai.911.g06873a30d2f3
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH bpf v2] net: skmsg: fix copy cursor when coalescing clones
2026-11-20 21:45 [PATCH bpf v2] net: skmsg: fix copy cursor when coalescing clones Kyle Zeng
@ 2026-11-20 22:50 ` Jiayuan Chen
0 siblings, 0 replies; 2+ messages in thread
From: Jiayuan Chen @ 2026-11-20 22:50 UTC (permalink / raw)
To: Kyle Zeng, bpf; +Cc: john.fastabend, jakub, netdev, alexei.starovoitov, stable
On 11/21/26 5:45 AM, Kyle Zeng wrote:
> A splice or zero-copy append can leave the destination copy cursor at
> sg.end. If sk_msg_clone() subsequently coalesces with the last entry,
> sg.end does not advance and the cursor still points at an unused slot.
> sk_msg_memcopy_from_iter() can then walk around the ring and write into
> older entries, including file pages spliced from a read-only descriptor.
>
> Software TLS can reach this with an ordinary MSG_MORE send after a file
> splice and a splice from another TCP socket. Both TCP and the TLS
> encrypted-message allocation can use the sending task's page fragment,
> so the TCP-sourced plaintext can be contiguous with the next cloned
> encrypted-message range.
>
> When coalescing with an exhausted destination, move the copy cursor to
> the tail and set copybreak to its old length before extending it. Find
> the actual tail on each iteration using the ring iterator, including
> when end wraps to zero. Leave an existing copy cursor unchanged and
> preserve the normal coalescing, reference counting, and memory charging.
>
> The issue was found by an LLM.
>
> Fixes: fda497e5f5b8 ("Optimize sk_msg_clone() by data merge to end dst sg entry")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Zeng <kylebot@openai.com>
Hi Kyle, I also received same issue from somewhere, but I think we should fix the root cause(TLS).
I have a fix patch and will send it shortly.
> ---
> v2:
> - Rebase onto the BPF fixes tree; no code changes.
>
> v1: https://lore.kernel.org/bpf/20261030042138.73739-1-kylebot@openai.com/
>
> I have a reproducer for this issue and can share via DM
>
> net/core/skmsg.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index 8a3b8536c0c2..f47c59ba1ec6 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -103,16 +103,26 @@ int sk_msg_clone(struct sock *sk, struct sk_msg *dst, struct sk_msg *src,
> }
>
> while (len) {
> + int last = dst->sg.end;
> +
> sge_len = sge->length - off;
> if (sge_len > len)
> sge_len = len;
>
> - if (dst->sg.end)
> - sgd = sk_msg_elem(dst, dst->sg.end - 1);
> + sgd = NULL;
> + if (dst->sg.size) {
> + sk_msg_iter_var_prev(last);
> + sgd = sk_msg_elem(dst, last);
> + }
>
> if (sgd &&
> (sg_page(sge) == sg_page(sgd)) &&
> (sg_virt(sge) + off == sg_virt(sgd) + sgd->length)) {
> + /* Start copying at the newly cloned suffix. */
> + if (dst->sg.curr == dst->sg.end) {
> + dst->sg.curr = last;
> + dst->sg.copybreak = sgd->length;
> + }
> sgd->length += sge_len;
> dst->sg.size += sge_len;
> } else if (!sk_msg_full(dst)) {
>
> base-commit: d5ba86298b45e1a81c578c499e9a222a3b734d5d
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 22:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 21:45 [PATCH bpf v2] net: skmsg: fix copy cursor when coalescing clones Kyle Zeng
2026-11-20 22:50 ` Jiayuan Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox