Re: [PATCH net-next v6 0/6] tls: perform TLS 1.3 KeyUpdate in the kernel
From: Hannes Reinecke
Date: Tue Dec 01 2026 - 08:27:29 EST
Hey Sabrina,
(hope you've recovered now; good to hear that you are back)
On 12/1/26 1:31 PM, Sabrina Dubroca wrote:
2026-11-09, 07:14:01 -0500, Martin Belanger wrote:This 'nothing else' probably refers to the fact that one does _not_ have
Hi Sabrina,
On 11/6/26 16:40, Sabrina Dubroca wrote:
I'm on a medical break so I won't be able to give this a proper review[...]
for another week or two, but since it keeps landing in my inbox, I
want to make a comment.
So this is kind of a "can we slow down until we agree that we
really want that?"
I am sorry to hear that. I hope you feel better soon. There is no
hurry. I will not send a new version before we agree on the
direction.
Thanks. I'm back now, I'm not fully caught up on everything but
getting there.
[...]kTLS does not currently handle TLS 1.3 KeyUpdate. It never sends a
KeyUpdate.
Because it isn't meant to handle any part of the handshake at all,
just the record layer.
So what you're proposing is a very fundamental change to how kTLS
works, I'm not convinced we want to go this way.
KeyUpdate is a handshake message, but it changes only record layer
state: the traffic key and the record sequence number. The new
secret is one HKDF-Expand-Label of the current one. Nothing else from
the handshake is needed.
"nothing else but change the keys" is already significant IMO, even if
recomputing them is quite simple.
to do the full TLS handshake, but can derive the new traffic keys directly.
Ah, how so? This is basically the core design of tls handshake, so ifIf userspace libraries don't do the right thing, we can fix the
libraries.
I agree. The main users of this series are kernel consumers:
NVMe/TCP (host and target) and sunrpc (client and nfsd). They have
no user-space process above the socket. tlshd does the handshake,
hands the keys to the kernel and exits.
Not a TLS expert (beyond what's in the kernel), but that feels wrong.
someone has objections we'd be most interested in having them ...
We could, but it doesn't change the issue.And that can't be handled with the existing handshake subsystem?
Not without new problems:
- A handshake daemon cannot write the KeyUpdate record to a kernel
socket. It has no file descriptor for it.
That sounds like something is missing in net/handshake.
Swap is not the problem. root on NVMe/TCP is the problem.- NVMe/TCP sets sk_set_memalloc() on its sockets so that it can
write out pages under memory pressure. A daemon has no such
guarantee. With root or swap on NVMe/TCP, the daemon can wait for
a page-in from the queue that waits for the daemon. An upcall or a
reconnect every few minutes makes this deadlock possible every few
minutes.
Is swap on NVMe/TCP really a thing? This whole paragraph sounds
bonkers to me.
If we get the KeyUpdate message the root fs is not directly accessible
(we cannot load the daemon from disk if it's swapped out, as this would
require I/O on the connection which we need to reset). So we would need
to mlock() the daemon to avoid that from happening.
And mlock() all libraries. And hope like hell none of these are using
pthreads, as the linux pthreads implementation _cannot_ be mlocked.
(Which we learned the hard way from years of debugging multipathd.)
Yep. Hence the patchset :-)- The traffic secrets must reach the kernel in any design. If each
consumer does the KeyUpdate itself, NVMe/TCP, nvmet-tcp, sunrpc,
nfsd and every future kTLS consumer need the same state machine.
In kTLS it is one implementation, which user-space applications
can use too.
I think almost all of it could be in net/handshake.
Not with 100GigE. You're reaching the limit pretty fast there.the 2^24 limit can be reached in less than 10 minutes in many cases.
My math says that's 28k records/second, it's a lot.
Storage traffic is different from HTTPS. The NVMe/TCP host sends one
TLS record per command, and a 4 KiB read is a 72-byte record. The
record count follows I/O operations, not bytes. 28k operations per
second on one queue is normal for NVMe. I measured one queue reaching
2^24 records in about 80 seconds. Connections stay up as long as the
I know rekeys in 1.3 are pretty lightweight, but this feels kind of
silly.
And storage arrays (or fast NVMe SSDs) can easily do 100k IOPs nowadays.
Because stopping would be a hard stop, ie we have to stop RX/TX whilehost does, so even at 1000 records per second the limit comes after
about 4.7 hours.
Without KeyUpdate, the consumer must reconnect at the limit. For
NVMe/TCP this tears down all queues of the controller, stops the I/O
in flight and repeats every handshake. NVMe/TCP is storage for
critical systems: databases for banking and stock trading, AI
training data, and systems that hold personal data. These systems
cannot reset their storage every few minutes.
I'm not yet convinced this is a strong enough argument to justify
changing the model under which ktls operates
RFC 9846 4.7.3: after a KeyUpdate with update_requested, the receiver
MUST send its own KeyUpdate "prior to sending its next Application
Data record". If a sendmsg() or sendfile() is in progress on another
thread, nothing above kTLS can stop it before its next record. kTLS
checks before each record.
And the next paragraph says "oh well there may be some messages in
flight", so I don't understand what difference it makes to stop a few
records earlier.
"rekey ASAP" sure, anything else makes no sense to me.
doing the upcall.
But that's the thing; we can't.
[answering your new message here, since it arrived as I was finishing this:]
The series is not only for kernel consumers. User-space libraries
benefit as well.
Not much, since they can't rely on the new feature being present. So
they will still have to implement everything needed to handle rekeys
in userspace.
Rekey is transparent by virtue of being asynchronous; you get a rekey
message on the RX side, recompute traffic secret for the TX side, update
keys, and RX is flowing again. _Then_ you send a rekey message on the RX side, recompute the traffic secret, and encrypt the following messages
with the new traffic secret.
This has to be _strictly_ timed, ie there is zero leeway once you receive an rekey or send a rekey; the very next record is using the
new traffic secret.
If you are using upcalls to recompute traffic secrets you _have_ to
stop RX once you receive the rekey message, wait for the upcall to
complete, and start the RX side again. That is inserting stalls in
the RX flow (in a regular basis, mind ...) and is kinda defeating
the purpose of rekeying.
The same goes for the TX side, obviously.
(And my suspicion is that most of the latency is the upcall itself,
not in the TLS handshake, so we'll be better off by just dropping
the connection entirely and let it reconnect. Which, incidentally,
is what we're doing now...)
But most annoyingly we would have to do the upcall from the ULP
(as that is where we're doing the upcall nowadays).
So if we were going with that model we either
- do the upcall from the in-kernel TLS code, resulting in two
independent instances (TLS and ULP code) doing upcalls.
With all the race conditions that entails. Bah.
- do the upcall from the ULP code. But that would require the
ULP code to suddenly have to be aware of protocol-specific
corner case (are we using TLS? Does the upcall support Rekey?).
Equally, bah.
See above. Timing is the key. In order to do that you'll haveA library above kTLS cannot count records
precisely, because the kernel splits and merges the bytes it writes.
Yeah, you're not meant to do that, but you get getsockopt() and get
the recseq back.
It also cannot place a KeyUpdate at an exact point in the record
stream.
Why not?
to stop RX/TX.
I do agree it's putting quite some protocol bits into the TLS code.With the series, GnuTLS or OpenSSL can register the traffic
secrets when they install the kTLS keys. The kernel then handles
KeyUpdate in both directions, also for sendfile() and splice().
Without the secrets, nothing changes.
Stealing handshake messages under a full TLS implementation's feet
doesn't seem right.
If the direction is acceptable, I would like to post v7 before
net-next closes for the 7.5 merge window. v7 drops TLS_TX_KEY_UPDATE
and addresses the Sashiko findings on v6. If you still have doubts,
I will wait for your review and not post v7.
I'm not convinced right now.
But at the same time TLS KeyUpdate is _meant_ to be handled in-line;
unfortunately it's at odds with the current kernel TLS concept of
moving the TLS handshake to userspace.
But thanks for your comments.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@xxxxxxx +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich