Kernel: Make sys$recvfrom() with MSG_DONTWAIT not so racy

Instead of temporary changing the open file description's "blocking"
flag while doing a non-waiting recvfrom, we instead plumb the currently
wanted blocking behavior all the way through to the underlying socket.
This commit is contained in:
Andreas Kling 2022-08-21 16:45:42 +02:00
commit 42435ce5e4
Notes: sideshowbarker 2024-07-17 08:05:36 +09:00
7 changed files with 17 additions and 22 deletions

View file

@ -241,15 +241,10 @@ ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user
if (socket.is_shut_down_for_reading())
return 0;
bool original_blocking = description->is_blocking();
if (flags & MSG_DONTWAIT)
description->set_blocking(false);
auto data_buffer = TRY(UserOrKernelBuffer::for_user_buffer((u8*)iovs[0].iov_base, iovs[0].iov_len));
Time timestamp {};
auto result = socket.recvfrom(*description, data_buffer, iovs[0].iov_len, flags, user_addr, user_addr_length, timestamp);
if (flags & MSG_DONTWAIT)
description->set_blocking(original_blocking);
bool blocking = (flags & MSG_DONTWAIT) ? false : description->is_blocking();
auto result = socket.recvfrom(*description, data_buffer, iovs[0].iov_len, flags, user_addr, user_addr_length, timestamp, blocking);
if (result.is_error())
return result.release_error();