summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/socket.cpp
AgeCommit message (Collapse)Author
2023-06-04Kernel: Move all tasks-related code to the Tasks subdirectoryLiav A
2023-05-24Kernel: Use UnixDateTime wherever applicablekleines Filmröllchen
"Wherever applicable" = most places, actually :^), especially for networking and filesystem timestamps. This includes changes to unzip, which uses DOSPackedTime, since that is changed for the FAT file systems.
2023-05-24AK: Rename Time to Durationkleines Filmröllchen
That's what this class really is; in fact that's what the first line of the comment says it is. This commit does not rename the main files, since those will contain other time-related classes in a little bit.
2023-04-04Kernel: Make the getsockname/getpeername syscall helper a bit nicerAndreas Kling
Instead of templatizing on a bool parameter, use an enum for clarity.
2023-03-24Kernel/Syscalls: Use copy_n_to_user when applicablePankaj Raghav
copy_to_user() with bytes as the last argument could be changed to using copy_n_to_user() with a count.
2023-03-07Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescriptionAndreas Kling
This patch switches away from {Nonnull,}LockRefPtr to the non-locking smart pointers throughout the kernel. I've looked at the handful of places where these were being persisted and I don't see any race situations. Note that the process file descriptor table (Process::m_fds) was already guarded via MutexProtected.
2023-03-06Kernel: Stop using NonnullLockRefPtrVectorAndreas Kling
2023-02-19Kernel: Support sending filedescriptors with sendmsg(2) and SCM_RIGHTSPeter Elliott
This is necessary to support the wayland protocol. I also moved the CMSG_* macros to the kernel API since they are used in both kernel and userspace. this does not break ntpquery/SCM_TIMESTAMP.
2022-10-24Kernel: Add support for MSG_NOSIGNAL and properly send SIGPIPEGunnar Beutner
Previously we didn't send the SIGPIPE signal to processes when sendto()/sendmsg()/etc. returned EPIPE. And now we do. This also adds support for MSG_NOSIGNAL to suppress the signal.
2022-08-23Kernel: Remove big lock from sys$socketJames Bellamy
With the implementation of the credentials object the socket syscall no longer needs the big lock.
2022-08-22Kernel: Use Process::credentials() and remove user ID/group ID helpersAnthony Iacono
Move away from using the group ID/user ID helpers in the process to allow for us to take advantage of the immutable credentials instead.
2022-08-21Kernel: Make sys$recvfrom() with MSG_DONTWAIT not so racyAndreas Kling
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.
2022-08-21Kernel: Make Socket::connect() take credentials as inputAndreas Kling
2022-08-21Kernel: Make Socket::bind() take credentials as inputAndreas Kling
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-08-17Kernel: Require semicolon after VERIFY_{NO_,}PROCESS_BIG_LOCK_ACQUIREDLinus Groh
This matches out general macro use, and specifically other verification macros like VERIFY(), VERIFY_NOT_REACHED(), VERIFY_INTERRUPTS_ENABLED(), and VERIFY_INTERRUPTS_DISABLED().
2022-08-16Kernel: Make sys$socketpair() not take the big lockAndreas Kling
This system call mainly accesses the file descriptor table, and this is already guarded by MutexProtected.
2022-07-21Kernel: Remove the Socket::{protocol,}connect ShouldBlock argumentIdan Horowitz
This argument is always set to description.is_blocking(), but description is also given as a separate argument, so there's no point to piping it through separately.
2022-07-10Kernel: Accept SHUT_RD and SHUT_WR as shutdown() how valuesIdan Horowitz
The previous check for valid how values assumed this field was a bitmap and that SHUT_RDWR was simply a bitwise or of SHUT_RD and SHUT_WR, which is not the case.
2022-04-09Kernel: Remove big lock from sys$setsockoptIdan Horowitz
This syscall doesn't access any unprotected shared data.
2022-04-09Kernel: Remove big lock from sys$getsockoptIdan Horowitz
This syscall doesn't access any unprotected shared data.
2022-04-09Kernel: Remove big lock from sys$shutdownIdan Horowitz
This syscall doesn't access any unprotected shared data.
2022-04-09Kernel: Remove big lock from sys$connectIdan Horowitz
This syscall doesn't access any unprotected shared data.
2022-04-09Kernel: Remove big lock from sys$bindIdan Horowitz
This syscall doesn't access any unprotected shared data.
2022-04-09Kernel: Remove big lock from `sys$accept4`Jelle Raaijmakers
The only thing we needed to check is whether `socket.accept()` returns a socket, and if not, we go back to blocking again.
2022-04-03Kernel: Mark sys$listen() as not needing the big lockAndreas Kling
This syscall already performs the necessary locking and so doesn't need to rely on the process big lock.
2022-04-03Kernel: Don't hog file descriptor table lock in sys$bind()Andreas Kling
We don't need to hold the lock across the entire syscall. Once we've fetched the open file description we're interested in, we can let go.
2022-04-03Kernel: Don't hog file descriptor table lock in sys$listen()Andreas Kling
We don't need to hold the lock across the entire syscall. Once we've fetched the open file description we're interested in, we can let go.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-02-07Kernel: Ensure socket is suitable for writing in sys$sendmsgsin-ack
Previously we would return a bytes written value of 0 if the writing end of the socket was full. Now we either exit with EAGAIN if the socket description is non-blocking, or block until the description can be written to. This is mostly a copy of the conditions in sys$write but with the "total nwritten" parts removed as sys$sendmsg does not have that.
2022-01-29Kernel: Switch process file descriptor table from spinlock to mutexAndreas Kling
There's no reason for this to use a spinlock. Instead, let's allow threads to block if someone else is using the descriptor table.
2022-01-29Kernel: Convert process file descriptor table to a SpinlockProtectedAndreas Kling
Instead of manually locking in the various member functions of Process::OpenFileDescriptions, simply wrap it in a SpinlockProtected.
2021-12-29Kernel: Handle promise violations in the syscall handlerBrian Gianforcaro
Previously we would crash the process immediately when a promise violation was found during a syscall. This is error prone, as we don't unwind the stack. This means that in certain cases we can leak resources, like an OwnPtr / RefPtr tracked on the stack. Or even leak a lock acquired in a ScopeLockLocker. To remedy this situation we move the promise violation handling to the syscall handler, right before we return to user space. This allows the code to follow the normal unwind path, and grantees there is no longer any cleanup that needs to occur. The Process::require_promise() and Process::require_no_promises() functions were modified to return ErrorOr<void> so we enforce that the errors are always propagated by the caller.
2021-12-29Kernel: Use Process::require_promise() instead of REQUIRE_PROMISE()Brian Gianforcaro
This change lays the foundation for making the require_promise return an error hand handling the process abort outside of the syscall implementations, to avoid cases where we would leak resources. It also has the advantage that it makes removes a gs pointer read to look up the current thread, then process for every syscall. We can instead go through the Process this pointer in most cases.
2021-12-29Kernel: Fix info leak from `sockaddr_un` in socket syscallsBrian Gianforcaro
In `sys$accept4()` and `get_sock_or_peer_name()` we were not initializing the padding of the `sockaddr_un` struct, leading to an kernel information leak if the caller looked back at it's contents. Before Fix: 37.766 Clipboard(11:11): accept4 Bytes: 2f746d702f706f7274616c2f636c6970626f61726440eac130e7fbc1e8abbfc 19c10ffc18440eac15485bcc130e7fbc1549feaca6c9deaca549feaca1bb0bc 03efdf62c0e056eac1b402d7acd010ffc14602000001b0bc030100000050bf0 5c24602000001e7fbc1b402d7ac6bdc After Fix: 0.603 Clipboard(11:11): accept4 Bytes: 2f746d702f706f7274616c2f636c6970626f617264000000000000000000000 000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000
2021-12-18Kernel: Use copy_typed_from_user() in more places :^)Andreas Kling
2021-11-21Kernel: Make UserOrKernelBuffer::for_user_buffer() return ErrorOr<T>Andreas Kling
This simplifies EFAULT propagation with TRY(). :^)
2021-11-10AK: Make Vector::try_* functions return ErrorOr<void>Andreas Kling
Instead of signalling allocation failure with a bool return value (false), we now use ErrorOr<void> and return ENOMEM as appropriate. This allows us to use TRY() and MUST() with Vector. :^)
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-09-07Kernel: Rename file_description(fd) => open_file_description(fd)Andreas Kling
To go with the class rename.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-05Kernel: Make file description lookup return KResultOrAndreas Kling
Instead of checking it at every call site (to generate EBADF), we make file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>. This allows us to wrap all the calls in TRY(). :^) The only place that got a little bit messier from this is sys$mount(), and there's a whole bunch of things there in need of cleanup.
2021-09-05Kernel: Use copy_typed_from_user<T> for fetching syscall parametersAndreas Kling
2021-09-05Kernel: Make copy_{from,to}_user() return KResult and use TRY()Andreas Kling
This makes EFAULT propagation flow much more naturally. :^)
2021-09-05Kernel: Use TRY() in sys$socket() and friendsAndreas Kling
2021-08-29Kernel: Rename LocalSocket::create_connected_pair() => try_*()Andreas Kling
2021-08-29Kernel: Rename FileDescription::create() => try_create()Andreas Kling
2021-08-01Kernel: Remove unused header includesBrian Gianforcaro
2021-07-28Kernel: Avoid file descriptor leak in Process::sys$socketpair on errorBrian Gianforcaro
Previously it was possible to leak the file descriptor if we error out after allocating the first descriptor. Now we perform both fd allocations back to back so we can handle the potential error when processing the second fd allocation.
2021-07-28Kernel: Track allocated FileDescriptionAndFlag elements in each ProcessBrian Gianforcaro
The way the Process::FileDescriptions::allocate() API works today means that two callers who allocate back to back without associating a FileDescription with the allocated FD, will receive the same FD and thus one will stomp over the other. Naively tracking which FileDescriptions are allocated and moving onto the next would introduce other bugs however, as now if you "allocate" a fd and then return early further down the control flow of the syscall you would leak that fd. This change modifies this behavior by tracking which descriptions are allocated and then having an RAII type to "deallocate" the fd if the association is not setup the end of it's scope.