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.
This commit is contained in:
Bananymous 2025-06-05 22:01:31 +03:00
parent cfeabc4580
commit 0f189d410e
1 changed files with 6 additions and 0 deletions

View File

@ -394,10 +394,16 @@ namespace Kernel
auto& connection_info = m_info.get<ConnectionInfo>(); auto& connection_info = m_info.get<ConnectionInfo>();
bool expected = true; bool expected = true;
if (connection_info.target_closed.compare_exchange(expected, false)) if (connection_info.target_closed.compare_exchange(expected, false))
{
m_packet_lock.unlock(state);
return 0; return 0;
}
if (!connection_info.connection) if (!connection_info.connection)
{
m_packet_lock.unlock(state);
return BAN::Error::from_errno(ENOTCONN); return BAN::Error::from_errno(ENOTCONN);
} }
}
m_packet_lock.unlock(state); m_packet_lock.unlock(state);
TRY(Thread::current().block_or_eintr_indefinite(m_packet_thread_blocker)); TRY(Thread::current().block_or_eintr_indefinite(m_packet_thread_blocker));