Re: [PATCH net] tls: set the copy cursor before cloning plaintext
From: Juan Agustin Niccolini
Date: Wed Nov 25 2026 - 08:55:12 EST
I don't know if you were the first. There is nothing public from you.
Kyle Zeng first reported it publicly on October 30. I discovered it
independently.
On Wed, Nov 25, 2026 at 4:27 AM Eddy <eddsterxyz@xxxxxxxxx> wrote:
>
> Hello, quick question, was I the first to report this issue or was this something you were already aware of?
>
> On Mon, 23 Nov 2026 at 8:38 Juan Agustin Niccolini <juanagusnicco@xxxxxxxxx> wrote:
>>
>> tls_sw_sendmsg_locked() copies into the open record by cloning space
>> with tls_clone_plaintext_msg() and filling it with
>> sk_msg_memcopy_from_iter(), which starts at sg.curr and sg.copybreak
>> as left by whatever last added to the record. The copy trusts other
>> paths to leave that cursor in the right state, and they have not.
>>
>> Since commit d829e9c4112b ("tls: convert to generic sk_msg interface"),
>> the path that adds the caller's own pages (sendpage, later splice) did
>> not move sg.curr, so the next copy wrote into those pages. Commit
>> c5a595000e26 ("net: tls, update curr on splice as well") fixed that by
>> making the splice path leave sg.curr at sg.end with copybreak 0. That
>> is only correct if the clone adds a new element. sk_msg_clone() instead
>> grows the last element when the cloned range is contiguous with it, so
>> sg.end does not move, and the copy starts at an unused slot, wraps
>> around the ring and writes from sg.start, into the spliced pages again.
>>
>> The spliced pages can be page cache pages of a file the caller opened
>> read-only, so an unprivileged user can change the cached contents of a
>> file it cannot write.
>>
>> The copy path always appends after the data already in the record, so
>> set the cursor there 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, and it covers every path that adds to the
>> record, whatever state it left the cursor in.
>>
>> This is where the cursor should have been set all along. With it set
>> here, the copy never depended on the splice path moving sg.curr, so
>> neither the original bug nor the one introduced by its fix would
>> have existed.
>>
>> I found this bug during an LLM-based audit. Kyle Zeng and Eddy
>> Tsalolikhin independently reported it before and are credited below.
>>
>> Fixes: d829e9c4112b ("tls: convert to generic sk_msg interface")
>> Fixes: c5a595000e26 ("net: tls, update curr on splice as well")
>> Reported-by: Eddy Tsalolikhin <eddsterxyz@xxxxxxxxx>
>> Reported-by: Kyle Zeng <kylebot@xxxxxxxxxx>
>> Closes: https://lore.kernel.org/all/20261030042138.73739-1-kylebot@xxxxxxxxxx/
>> Cc: stable@xxxxxxxxxxxxxxx
>> Signed-off-by: Juan Agustin Niccolini <juanagusnicco@xxxxxxxxx>
>> ---
>> Jiayuan Chen posted "[PATCH net v1] tls: fix ring wrap in
>> sk_msg_memcopy_from_iter() after splice"
>> (https://lore.kernel.org/all/20261120225720.89044-1-jiayuan.chen@xxxxxxxxx/),
>> which sets the same cursor in the splice path. The two patches touch
>> different functions and apply in either order, and this one is still
>> needed even if his goes in: his closes the splice route on mainline,
>> but not tls_sw_do_sendpage() on 6.1, 5.15 and 5.10, where it does not
>> apply, nor the record split on 7.1 and older. This patch removes the
>> copy's dependence on all of them, and applies unchanged to every
>> stable branch, because tls_clone_plaintext_msg() is the same everywhere.
>>
>> I have an exploit that lets an unprivileged process overwrite the page
>> cache of /bin/su to open a root shell. I confirmed it works on mainline
>> and 5 distros. It is available to the maintainers on request.
>>
>> On 6.1, 5.15 and 5.10 the bug is a race, but an unprivileged user
>> won it within a second in my tests. I have another reproducer
>> available for those.
>>
>> I used a fuzzer with a page cache oracle to confirm this patch fixes
>> the issue in QEMU guests on mainline 7e1392a42ea2, and all stable branches:
>> 7.3.5, 7.1.13, 6.18.64, 6.12.118, 6.6.162, 6.1.192, 5.15.225, and 5.10.274.
>>
>> I also confirmed that it fixes the original bug on a kernel
>> without c5a595000e26 applied.
>>
>> net/tls/tls_sw.c | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
>> index 226e0f176fdc..efff7a02aef2 100644
>> --- a/net/tls/tls_sw.c
>> +++ b/net/tls/tls_sw.c
>> @@ -349,6 +349,17 @@ static int tls_clone_plaintext_msg(struct sock *sk, int required)
>> */
>> skip = prot->prepend_size + msg_pl->sg.size;
>>
>> + if (msg_pl->sg.size) {
>> + u32 i = msg_pl->sg.end;
>> +
>> + sk_msg_iter_var_prev(i);
>> + msg_pl->sg.curr = i;
>> + msg_pl->sg.copybreak = msg_pl->sg.data[i].length;
>> + } else {
>> + msg_pl->sg.curr = msg_pl->sg.start;
>> + msg_pl->sg.copybreak = 0;
>> + }
>> +
>> return sk_msg_clone(sk, msg_pl, msg_en, skip, len);
>> }
>>
>>
>> base-commit: af6737b9066832a2017c281159950ba92385ce00
>> --
>> 2.53.0
>>