From 0f189d410e5e0d75b4f129b1e120efb73934d625 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 5 Jun 2025 22:01:31 +0300 Subject: [PATCH] Kernel: Fix unix socket recv from If connection on unix socket was closed and other end tries to recvfrom, the thread would enter a fucked up state where it held the socket's spinlock when returning to userspace. --- kernel/kernel/Networking/UNIX/Socket.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/kernel/Networking/UNIX/Socket.cpp b/kernel/kernel/Networking/UNIX/Socket.cpp index c21b0181..221911b6 100644 --- a/kernel/kernel/Networking/UNIX/Socket.cpp +++ b/kernel/kernel/Networking/UNIX/Socket.cpp @@ -394,9 +394,15 @@ namespace Kernel auto& connection_info = m_info.get(); bool expected = true; if (connection_info.target_closed.compare_exchange(expected, false)) + { + m_packet_lock.unlock(state); return 0; + } if (!connection_info.connection) + { + m_packet_lock.unlock(state); return BAN::Error::from_errno(ENOTCONN); + } } m_packet_lock.unlock(state);