Page MenuHomeFreeBSD

ktls: Fix races that can lead to double initialization
ClosedPublic

Authored by markj on Jun 21 2024, 4:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Oct 21, 1:24 AM
Unknown Object (File)
Fri, Oct 17, 10:34 PM
Unknown Object (File)
Tue, Oct 7, 5:50 AM
Unknown Object (File)
Sun, Oct 5, 6:34 AM
Unknown Object (File)
Sep 20 2025, 1:18 PM
Unknown Object (File)
Sep 13 2025, 11:43 PM
Unknown Object (File)
Sep 13 2025, 8:28 AM
Unknown Object (File)
Sep 13 2025, 6:01 AM
Subscribers

Details

Summary

ktls_enable_rx() and ktls_enable_tx() have checks to return EALREADY if
the socket already has KTLS enabled. However, these are done without
any locks held and nothing blocks concurrent attempts to set the socket
option. I believe the worst outcome of the race is leaked memory.

Fix the problem by rechecking under the sockbuf lock. While here,
unify the locking protocol for sb_tls_info: require both the sockbuf and
socket I/O locks in order to enable KTLS. This means that either lock
is sufficient for checking whether KTLS is enabled in a given sockbuf,
which simplifies some refactoring further down the road.

Note that the SOLISTENING() check can go away because
SOCK_IO_RECV_LOCK() atomically locks the socket buffer and checks
whether the socket is a listening socket. This changes the errno value,
so update a test which checks it.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 58283
Build 55171: arc lint + arc unit