socket: Remove NOFREE from the socket zone
This flag was added during the transition away from the legacy zone
allocator, commit c897b81311
. The old
zone allocator effectively provided _NOFREE semantics, but it seems that
they are not required for sockets. In particular, we use reference
counting to keep sockets live.
One somewhat dangerous case is sonewconn(), which returns a pointer to a
socket with reference count 0. This socket is still effectively owned
by the listening socket. Protocols must therefore be careful to
synchronize sonewconn() calls with their pru_close implementations,
since for listening sockets soclose() will abort the child sockets. For
example, TCP holds the listening socket's PCB read locked across the
sonewconn() call, which blocks tcp_usr_close(), and sofree()
synchronizes with a concurrent soabort() of the nascent socket.
However, _NOFREE semantics are not required here.
Eliminating _NOFREE has several benefits: it enables use-after-free
detection (e.g., by KASAN) and lets the system reclaim memory from the
socket zone under memory pressure. No functional change intended.
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31975
This commit is contained in:
parent
6b288408ca
commit
883761f0a8
@ -309,7 +309,7 @@ socket_init(void *tag)
|
||||
{
|
||||
|
||||
socket_zone = uma_zcreate("socket", sizeof(struct socket), NULL, NULL,
|
||||
NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
|
||||
NULL, NULL, UMA_ALIGN_PTR, 0);
|
||||
maxsockets = uma_zone_set_max(socket_zone, maxsockets);
|
||||
uma_zone_set_warning(socket_zone, "kern.ipc.maxsockets limit reached");
|
||||
EVENTHANDLER_REGISTER(maxsockets_change, socket_zone_change, NULL,
|
||||
|
Loading…
Reference in New Issue
Block a user