5 ms·
TLS libraries like OpenSSL operate in user space (in-kernel TLS is very a recent addition to Linux). sendfile(2)'s benefit is that it doesn't require transferr
by runlevel1 8y ago
TLS libraries like OpenSSL operate in user space (in-kernel TLS is very a recent addition to Linux).
sendfile(2)'s benefit is that it doesn't require transferring the data back and forth between kernel space and user space. You point it to a file descriptor and a socket, and it simply copies the bytes -- all in kernel space.
- messe 8y ago> in-kernel TLS is very a recent addition to Linux Linux has gotten in-kernel TLS? That's slightly horrifying. Seems like it's hard enough to get right without being allowed to overwrite any user page you'd like.
- philjohn 8y agoDoesn't a lot of that come from the very long development history of OpenSSL (so best practices have developed over its lifetime), and the many, many compatibility hacks they still include in the codebase? It also contains a LOT of different things in there, whereas "just" a TLS stream with limited ciphers should be a lot simpler.
- toast0 8y agoSupporting TLS directly in a kernel is horrifying regardless of the legacy of OpenSSL. Having userspace do the session establishment (where all the weird stuff happens) and letting the kernel do the bulk ciphering is reasonable, especially if you're already using sendfile so the kernel can handle the bulk data sending. If something goes sideways, punt the socket back to userspace. Lots of kernels already have bulk ciphering for encrypted disks or ipsec (which is often very similar, userspace negotiates sessions and kernel handles per packet ciphering)
- ronsor 8y agoAFAIK that's all Linux's TLS implementation does -- ciphering & encryption, not session setup
- runlevel1 8y agoYes, but only the symmetric part. You handshake in userspace, then you pass the negotiated cipher keys/IV to the TCP socket with `setsockopt`. Last I looked, the only cipher supported was AES-128-GCM.
- takeda 8y agoDon't know about Linux implementation, but sendfile would only need AES, and today's CPUs even come with hardware support. I can't talk about security aspect, but it is not like the openssl is implemented in kernel or hardware, just the symmetric encryption and that only transforms the data.