mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v1] tls: fix ring wrap in sk_msg_memcopy_from_iter() after splice
@ 2026-11-20 22:57 Jiayuan Chen
  2026-11-20 23:03 ` netdev-bot+sinfo
  2026-11-23  6:30 ` Juan Agustin Niccolini
  0 siblings, 2 replies; 3+ messages in thread
From: Jiayuan Chen @ 2026-11-20 22:57 UTC (permalink / raw)
  To: netdev
  Cc: Jiayuan Chen, Eddy Tsalolikhin, Kyle Zeng, John Fastabend,
	Jakub Kicinski, Sabrina Dubroca, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, linux-kernel

tls_sw_sendmsg_splice() forces sg.curr = sg.end after adding the
spliced page.

The following non-splice sk_msg_memcopy_from_iter() is a do-while
loop: it advances i with sk_msg_iter_var_next() and only then tests
i != sg.end, so starting from sg.curr == sg.end it wraps the ring.

Reported-by: Eddy Tsalolikhin <eddsterxyz@gmail.com>
Reported-by: Kyle Zeng <kylebot@openai.com>
Fixes: c5a595000e26 ("net: tls, update curr on splice as well")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
 net/tls/tls_sw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 365c9485bb7c..d3a9b1c41de8 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -764,8 +764,10 @@ static int tls_sw_sendmsg_splice(struct sock *sk, struct msghdr *msg,
 		}
 
 		sk_msg_page_add(msg_pl, page, part, off);
-		msg_pl->sg.copybreak = 0;
+		/* keep sg.curr on the last frag so a later copy won't wrap */
 		msg_pl->sg.curr = msg_pl->sg.end;
+		sk_msg_iter_var_prev(msg_pl->sg.curr);
+		msg_pl->sg.copybreak = sk_msg_elem(msg_pl, msg_pl->sg.curr)->length;
 		sk_mem_charge(sk, part);
 		*copied += part;
 		try_to_copy -= part;
-- 
2.43.0


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

* Re: [PATCH net v1] tls: fix ring wrap in sk_msg_memcopy_from_iter() after splice
  2026-11-20 22:57 [PATCH net v1] tls: fix ring wrap in sk_msg_memcopy_from_iter() after splice Jiayuan Chen
@ 2026-11-20 23:03 ` netdev-bot+sinfo
  2026-11-23  6:30 ` Juan Agustin Niccolini
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-20 23:03 UTC (permalink / raw)
  To: Jiayuan Chen
  Cc: netdev, Eddy Tsalolikhin, Kyle Zeng, John Fastabend,
	Jakub Kicinski, Sabrina Dubroca, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net v1] tls: fix ring wrap in sk_msg_memcopy_from_iter() after splice
  2026-11-20 22:57 [PATCH net v1] tls: fix ring wrap in sk_msg_memcopy_from_iter() after splice Jiayuan Chen
  2026-11-20 23:03 ` netdev-bot+sinfo
@ 2026-11-23  6:30 ` Juan Agustin Niccolini
  1 sibling, 0 replies; 3+ messages in thread
From: Juan Agustin Niccolini @ 2026-11-23  6:30 UTC (permalink / raw)
  To: Jiayuan Chen
  Cc: netdev, Eddy Tsalolikhin, Kyle Zeng, John Fastabend,
	Jakub Kicinski, Sabrina Dubroca, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, linux-kernel

On Sat, 21 Nov 2026 06:57:19 +0800, Jiayuan Chen wrote:
> tls_sw_sendmsg_splice() forces sg.curr = sg.end after adding the
> spliced page.
>
> The following non-splice sk_msg_memcopy_from_iter() is a do-while
> loop: it advances i with sk_msg_iter_var_next() and only then tests
> i != sg.end, so starting from sg.curr == sg.end it wraps the ring.

I don't think this addresses the root cause. The copy path in
tls_sw_sendmsg_locked() starts writing at whatever cursor the last
producer left behind, and this is the second time the splice line has
been fixed because of that: c5a595000e26 made it move sg.curr because
the copy was writing into the spliced page, and that change is what
introduced this bug.

This patch does close the splice route on mainline but doesn't touch
multiple producers that leave the scatterlist cursor in a bad state
for the next copy:

- tls_sw_do_sendpage() on 6.1, 5.15 and 5.10, where this patch does
  not apply. The bug is reachable there too, as a race rather than
  deterministically (won within a second in my tests).
- the record split in tls_push_record() on 7.1 and older.

The copy path always appends after the data already in the record, so
it can set the cursor itself, in tls_clone_plaintext_msg(), before
cloning: on the last element with copybreak at its length, or at
sg.start when the record is empty, as sk_msg_reset_curr() does. That
holds whether the clone grows the last element or adds a new one,
covers every producer, would have made c5a595000e26 unnecessary, and
applies unchanged to every stable branch.

I'll send it as a separate patch that tags d829e9c4112b which caused the
symptom that c5a595000e26 fixed but introduced this bug.

Best,
Agustin

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

end of thread, other threads:[~2026-11-23  6:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 22:57 [PATCH net v1] tls: fix ring wrap in sk_msg_memcopy_from_iter() after splice Jiayuan Chen
2026-11-20 23:03 ` netdev-bot+sinfo
2026-11-23  6:30 ` Juan Agustin Niccolini

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®