Repository navigation
ktls: Build the OCF software backend into the kernel (fixes #667) - #672
Conversation
This removes support for loadable software backends. The KTLS OCF support is now always included in kernels with KERN_TLS and the ktls_ocf.ko module has been removed. The software encryption routines now take an mbuf directly and use the TLS mbuf as the crypto buffer when possible. Our KTLS code matched FreeBSD stable/13, which never merged this change, so it was ported by hand on top of the later stable/13 work already in the tree. Kept as in stable/13: the split encrypt and decrypt counters, synchronous OCF dispatch, TLS 1.3 receive, the TLS 1.0 sequential record handling, the minimum AEAD record length check and the vm_page_alloc_noobj() page allocation for sendfile records. The 16k buffer zone that FreeBSD head used in ktls_encrypt() is not imported. The __FreeBSD_version bump is not applied. With the backend list gone, errors from ktls_ocf_try() now reach the caller. Enabling receive for AES-CBC fails with EPROTONOSUPPORT instead of EOPNOTSUPP, which is what tests/sys/kern/ktls_test expects. Fixes: #667 Obtained from: FreeBSD 21e3c1fbe246 AI-Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
This avoids creating a duplicate copy on the stack just to append the trailer. Obtained from: FreeBSD 6b313a3a6045 AI-Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
KTLS no longer supports multiple software backends. Instead, it always uses OCF for software crypto. In particular, the ktls_ocf.ko module no longer exists. The OCF bits for KTLS are compiled into the kernel instead. Obtained from: FreeBSD 7ffc9b15ba9c AI-Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
AI-Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
Reviewer's GuideData structuresUpdate the KTLS session interface for direct OCF use, replacing the pluggable-backend fields and callback signature with the mbuf-based software-encryption interface.
ImplementationReplace backend selection and lifecycle management with direct OCF calls, and adapt transmit encryption to pass TLS mbufs and construct separate output pages when needed.
Convert OCF TLS encryption routines to operate on TLS mbufs, use in-place crypto where possible, and include the trailer in the separate-output iovec.
ConfigurationBuild the OCF KTLS backend into kernels with KERN_TLS and remove the standalone ktls_ocf module from the module build.
DocumentationUpdate the KTLS manual and release notes to describe software encryption through crypto(9) and the removal of the loadable OCF backend.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Fixes #667.
Ports FreeBSD 21e3c1fbe246 ("Assume OCF is the only KTLS software backend"). KTLS no longer supports loadable software backends. The OCF backend is built into every kernel with
options KERN_TLS, andktls_ocf.kois removed. Both parts of #667 are fixed:tests/sys/kern/ktls_testno longer needskldload ktls_ocf.ktls_try_sw()used to replace the backend's error with EOPNOTSUPP whenever no backend accepted the session. It now callsktls_ocf_try()directly and returns its error, so enabling receive for AES-CBC fails with EPROTONOSUPPORT, as the tests expect.Commits
How 21e3c1fbe246 was ported
Our KTLS code matched FreeBSD stable/13, which never merged this commit. stable/13 then picked up a dozen later head changes that had been rewritten for the old backend API. I three-way merged
uipc_ktls.c,ktls_ocf.candktls.h, using FreeBSD's tree just before 21e3c1fbe246 as the base. Each conflict was resolved against head's own post-21e3c1fbe246 version of the same code.ktls_drop()vm_page_alloc_noobj()for sendfile pagesktls_buffer_alloc), which 21e3c1fbe246's version ofktls_encrypt()uses but stable/13 never had.__FreeBSD_version: FreeBSD bumped it for out-of-tree backends. I didn't, because we have none.ktls_ocf.ko, since installkernel replaces/boot/kernel. I didn't either.Testing
KERN_TLS), build.ktls_ocf.ois linked into the kernel and noktls_ocf.kois built. The onlyuipc_ktls.cwarnings are three on arm64 that master also has.ktls_testwithkern.ipc.tls.enable=1and no kldload: 281/281 pass. Master gets 22/281 without loadingktls_ocf.koand 271/281 with it.ocfstats show TLS 1.0–1.3 encrypt and decrypt traffic for GCM, ChaCha20 and CBC.ufs -> devfsat shutdown, shows up on master too.ktls_testnever sends from a file, so the separate-output encrypt path (file pages encrypted into new pages, which 6b313a3a6045 changed) went untested. A guest-only programsendfile()d a 400 KiB file over a KTLS loopback connection. It used 8 offset and length mixes (unaligned starts, 1 byte, 3 bytes, exact and spanning 16 KiB records, multi-record) and covered 10 suites: AES-GCM 128 and 256 for TLS 1.2 and 1.3, ChaCha20-Poly1305 for TLS 1.2 and 1.3, and AES-CBC for TLS 1.0, 1.1 and 1.2 with SHA1, SHA256 and SHA384. The receiver decrypted every record in userspace with OpenSSL, checking tags, MACs and padding, and compared the result with the file. All 80 cases pass.Separate existing bug found while testing
Using KTLS receive on the peer socket instead of OpenSSL, AEAD records of about 4 KiB or more fail with EBADMSG. This also happens with write(2) on the sender, and on unpatched master with
ktls_ocf.koloaded. Records are rejected because our CVE-2026-45257 fix (257e33b) treats mbufs converted for the loopback interface as shared. FreeBSD had the same regression (PR 296498) and fixed it in 0af1065b3a57. Filed as #673, fixed separately in #674.🤖 Generated with Claude Code