1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

Kernel: Lock socket mutex across {get,set}sockopt() and SO_ERROR updates

Since a socket can be accessed by multiple threads concurrently, we need
to protect shared data behind the socket mutex.

There's very likely more places where we need to fix this, the purpose
of this patch is to fix a VERIFY() failure in getsockopt() seen on CI.
This commit is contained in:
Andreas Kling 2021-12-28 15:16:57 +01:00
parent 4e1898df99
commit a1be135891
4 changed files with 17 additions and 1 deletions

View file

@ -130,16 +130,22 @@ protected:
Role m_role { Role::None };
ErrorOr<void> so_error() const { return m_so_error; }
ErrorOr<void> so_error() const
{
VERIFY(m_mutex.is_locked_by_current_thread());
return m_so_error;
}
Error set_so_error(ErrnoCode error_code)
{
MutexLocker locker(mutex());
auto error = Error::from_errno(error_code);
m_so_error = error;
return error;
}
Error set_so_error(Error error)
{
MutexLocker locker(mutex());
m_so_error = error;
return error;
}