1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 01:05:08 +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

@ -78,6 +78,8 @@ ErrorOr<void> Socket::queue_connection_from(NonnullRefPtr<Socket> peer)
ErrorOr<void> Socket::setsockopt(int level, int option, Userspace<const void*> user_value, socklen_t user_value_size)
{
MutexLocker locker(mutex());
if (level != SOL_SOCKET)
return ENOPROTOOPT;
VERIFY(level == SOL_SOCKET);
@ -133,6 +135,8 @@ ErrorOr<void> Socket::setsockopt(int level, int option, Userspace<const void*> u
ErrorOr<void> Socket::getsockopt(OpenFileDescription&, int level, int option, Userspace<void*> value, Userspace<socklen_t*> value_size)
{
MutexLocker locker(mutex());
socklen_t size;
TRY(copy_from_user(&size, value_size.unsafe_userspace_ptr()));