summaryrefslogtreecommitdiff
path: root/Kernel/Net/LocalSocket.cpp
AgeCommit message (Collapse)Author
2022-01-09Kernel: Harden Socket::pseudo_path(..) implementations against OOMBrian Gianforcaro
Use the try variants of AK::StringBuilder append APIs to harden these functions against OOM.
2021-12-30Kernel+AK: Eliminate a couple of temporary String allocationsDaniel Bertalan
2021-12-28Kernel: Lock socket mutex across {get,set}sockopt() and SO_ERROR updatesAndreas Kling
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.
2021-12-16Kernel+LibC: Move errno definitions to Kernel/API/POSIXsin-ack
This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
2021-12-05Kernel: Return EINVAL on unsupported LocalSocket ioctlIdan Horowitz
ENOTTY is used to signify that no ioctl interface is provided at all, but LocalSockets do support the FIONREAD ioctl.
2021-11-16Kernel: Use static_ptr_cast to convert between Userspace<T*> typesAndrew Kaster
Some calls of copy_to_user were converting Userspace<T*> to Userspace<U*> via the implicit conversion to FlatPtr. Change them to use the static_ptr_cast overload that is designed to express this conversion
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-10-31Kernel: Clarify ambiguous {File,Description}::absolute_pathBen Wiederhake
Found due to smelly code in InodeFile::absolute_path. In particular, this replaces the following misleading methods: File::absolute_path This method *never* returns an actual path, and if called on an InodeFile (which is impossible), it would VERIFY_NOT_REACHED(). OpenFileDescription::try_serialize_absolute_path OpenFileDescription::absolute_path These methods do not guarantee to return an actual path (just like the other method), and just like Custody::absolute_path they do not guarantee accuracy. In particular, just renaming the method made a TOCTOU bug obvious. The new method signatures use KResultOr, just like try_serialize_absolute_path() already did.
2021-10-08Kernel: Fix -Wunreachable-code warnings from clangNico Weber
2021-09-16Kernel: Weakly hold on to the file in LocalSocketsin-ack
Because we were holding a strong ref to the OpenFileDescription in LocalSocket and a strong ref to the LocalSocket in Inode, we were creating a reference cycle in the event of the socket being cleaned up after the file description did (i.e. unlinking the file before closing the socket), because the file description never got destructed.
2021-09-15Kernel: Use move semantics in sys$sendfd()Andreas Kling
Avoid an unnecessary NonnullRefPtr<OpenFileDescription> copy.
2021-09-07Kernel/Net: Add a special SOCKET_TRY() and use it in socket codeAndreas Kling
Sockets remember their last error code in the SO_ERROR field, so we need to take special care to remember this when returning an error. This patch adds a SOCKET_TRY() that works like TRY() but also calls set_so_error() on the failure path. There's probably a lot more code that should be using this, but that's outside the scope of this patch.
2021-09-07Kernel: Make DoubleBuffer::try() return KResultOrAndreas Kling
This tidies up error propagation in a number of places.
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-06Kernel: Use TRY() once more in LocalSocket::try_create_connected_pair()Andreas Kling
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
There are a number of places that don't have an error propagation path right now, so I've added FIXME's about that.
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 LocalSocketAndreas Kling
2021-08-31Kernel: Don't VERIFY_NOT_REACHED in LocalSocket::has_attached_peer()Owen Smith
Invoking sendmsg on a listening socket triggers this assertion as sendto calls has_attached_peer before checking the result of send_buffer_for.
2021-08-29Kernel: Rename Socket::lock() => Socket::mutex()Andreas Kling
"lock" is ambiguous (verb vs noun) while "mutex" is not.
2021-08-29Kernel: Add Socket::set_role() and use it everywhereAndreas Kling
Instead of having Socket subclasses write their role into Socket::m_role directly, add a setter to do this.
2021-08-29Kernel: Store LocalSocket address as a KString internallyAndreas Kling
Just because we deal with sockaddr_un at the userspace API layer doesn't mean we have to store an awkward C type internally. :^)
2021-08-29Kernel: Rename LocalSocket::create_connected_pair() => try_*()Andreas Kling
2021-08-29Kernel: Encapsulate assignment of socket origin/acceptor credentialsAndreas Kling
2021-08-29Kernel: Rename LocalSocket factory to try_create() & tighten return typeAndreas Kling
Also tighten the return type to KResultOr<NonnullRefPtr<LocalSocket>> since it cannot return any other socket type.
2021-08-29Kernel: Strongly typed user & group ID'sAndreas Kling
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`. This made it easy to use them interchangeably. Let's not allow that. This patch adds UserID and GroupID using the AK::DistinctNumeric mechanism we've already been employing for pid_t/ProcessID.
2021-08-29Kernel: Rename FileDescription::create() => try_create()Andreas Kling
2021-08-22Kernel: Return ENOTSUP instead of panicking on invalid sockoptPeter Elliott
X11 handles this gracefully, and it makes more sense than panicking.
2021-08-22Kernel+LibC: Implement FIONREAD ioctlPeter Elliott
FIONREAD gets the number of bytes availible to read from a file descriptor without blocking. I only implemented it for regular files and sockets
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-19Kernel: Make Process::current() return a Process& instead of Process*Idan Horowitz
This has several benefits: 1) We no longer just blindly derefence a null pointer in various places 2) We will get nicer runtime error messages if the current process does turn out to be null in the call location 3) GCC no longer complains about possible nullptr dereferences when compiling without KUBSAN
2021-08-14Kernel: Stop allowing implicit conversion from KResult to intAndreas Kling
This patch removes KResult::operator int() and deals with the fallout. This forces a lot of code to be more explicit in its handling of errors, greatly improving readability.
2021-08-10Kernel: Properly implement SO_ERROR optionbrapru
This fixes the placeholder stub for the SO_ERROR via getsockopt. It leverages the m_so_error value that each socket maintains. The SO_ERROR option obtains and then clears this field, which is useful when checking for errors that occur between socket calls. This uses an integer value to return the SO_ERROR status. Resolves #146
2021-08-10Kernel: Add so_error to keep track of the socket's error statebrapru
This sets the m_so_error variable every time the socket returns an error.
2021-08-08Everywhere: Replace AK::Singleton => SingletonAndreas Kling
2021-08-07Kernel: Migrate local socket table locking to ProtectedValueJean-Baptiste Boric
2021-08-07Kernel: Move Lockable into its own headerJean-Baptiste Boric
2021-08-03Kernel: Handle OOM from DoubleBuffer usage in Net/LocalSocketBrian Gianforcaro
LocalSockets keep a DoubleBuffer for both client and server usage. This change converts the usage from using the default constructor which is unable to observe OOM, to the new try_create factory and plumb the result through the constructor.
2021-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-17Kernel: Rename Lock to MutexAndreas Kling
Let's be explicit about what kind of lock this is meant to be.
2021-07-11Kernel: Rename VFS => VirtualFileSystemAndreas Kling
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-16Kernel: Use KResultOr<size_t> for the DoubleBuffer classGunnar Beutner
2021-05-26Kernel: Switch LocalSocket to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-13Kernel: Make LocalSocket factory APIs OOM safeBrian Gianforcaro
2021-05-01Kernel: Harden LocalSocket Vector usage against OOM.Brian Gianforcaro
2021-04-28Kernel+LibC: Implement the socketpair() syscallGunnar Beutner
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)