summaryrefslogtreecommitdiff
path: root/Kernel/Net
AgeCommit message (Collapse)Author
2020-12-13Kernel/Net: Socket connected state change should reevaluate blocksAndreas Kling
This fixes an issue where TCP sockets could get into the Established state too quickly and fail to unblock a subsequent sys$select() call. This makes websites load *significantly* faster. :^)
2020-12-12Kernel: Fix some issues related to fixes and block conditionsTom
Fix some problems with join blocks where the joining thread block condition was added twice, which lead to a crash when trying to unblock that condition a second time. Deferred block condition evaluation by File objects were also not properly keeping the File object alive, which lead to some random crashes and corruption problems. Other problems were caused by the fact that the Queued state didn't handle signals/interruptions consistently. To solve these issues we remove this state entirely, along with Thread::wait_on and change the WaitQueue into a BlockCondition instead. Also, deliver signals even if there isn't going to be a context switch to another thread. Fixes #4336 and #4330
2020-11-30Kernel: Move block condition evaluation out of the SchedulerTom
This makes the Scheduler a lot leaner by not having to evaluate block conditions every time it is invoked. Instead evaluate them as the states change, and unblock threads at that point. This also implements some more waitid/waitpid/wait features and behavior. For example, WUNTRACED and WNOWAIT are now supported. And wait will now not return EINTR when SIGCHLD is delivered at the same time.
2020-11-30Kernel: Allow passing a thread argument for new kernel threadsTom
This adds the ability to pass a pointer to kernel thread/process. Also add the ability to use a closure as thread function, which allows passing information to a kernel thread more easily.
2020-11-20MACAddress: AK::Array as member variable instead of C-arrayLenny Maiorani
Problem: - C-style arrays do not automatically provide bounds checking and are less type safe overall. - `__builtin_memcmp` is not a constant expression in the current gcc. Solution: - Change private m_data to be AK::Array. - Eliminate constructor from C-style array. - Change users of the C-style array constructor to use the default constructor. - Change `operator==()` to be a hand-written comparison loop and let the optimizer figure out to use `memcmp`.
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
2020-10-31IPv4: Include IP headers when receiving from a raw socketAndreas Kling
We were stripping the L3 headers from packets received on raw sockets. This didn't match what other systems do, so let's adjust our behavior. Thanks to @SpencerCDixon for noticing this! :^)
2020-10-21IPv4: Take the socket lock more (fixes TCP connection to localhost)Andreas Kling
This fixes an issue where making a TCP connection to localhost didn't work correctly since the loopback interface is currently synchronous. (Sending something to localhost would enqueue a packet on the same interface and then immediately wake the network task to process that packet.) This was preventing the TCP handshake from working correctly with localhost since we'd send out the SYN packet before moving to the SynSent state. The lock is now held long enough for this operation to be atomic.
2020-10-20ICMP: Check that incoming ICMP echo requests are large enoughAndreas Kling
Otherwise, just ignore them.
2020-10-08TCP: Remove unnecessarily defined constructor and destructorLenny Maiorani
Problem: Defining the destructor violates the "rule of 0" and prevents the copy/move constructor/assignment operators from being provided by the compiler. Solution: Change the constructor and destructor to be the default compiler-provided definition.
2020-10-08SinglyLinkedList: Remove unused includesLenny Maiorani
Several files include `AK/SinglyLinkedList.h` without using it. Removing it to simplify.
2020-10-03Everywhere: Fix more typosLinus Groh
2020-09-27Kernel: Make Thread refcountedTom
Similar to Process, we need to make Thread refcounted. This will solve problems that will appear once we schedule threads on more than one processor. This allows us to hold onto threads without necessarily holding the scheduler lock for the entire duration.
2020-09-27Kernel: Return ENOPROTOOPT instead of asserting on unimplemented levels in ↵Luke
getsockopt
2020-09-25Meta+Kernel: Make clang-format-10 cleanBen Wiederhake
2020-09-17Kernel+LibC+UserspaceEmulator: Add SO_TIMESTAMP, and cmsg definitionsNico Weber
When SO_TIMESTAMP is set as an option on a SOCK_DGRAM socket, then recvmsg() will return a SCM_TIMESTAMP control message that contains a struct timeval with the system time that was current when the socket was received.
2020-09-17Kernel: Plumb packet receive timestamp from NetworkAdapter to Socket::recvfromNico Weber
Since the receiving socket isn't yet known at packet receive time, keep timestamps for all packets. This is useful for keeping statistics about in-kernel queue latencies in the future, and it can be used to implement SO_TIMESTAMP.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-09-10IPv4: Truncate raw socket reads past buffer lengthAvery
In addition to being the proper POSIX etiquette, it seems like a bad idea for issues like the one seen in #3428 to result in a kernel crash. This patch replaces the current behavior of failing on insufficient buffer size to truncating SOCK_RAW messages to the buffer size. This will have to change if/when MSG_PEEK is implemented, but for now this behavior is more compliant and logical than just bailing.
2020-09-06Kernel: Make File weakableAndreas Kling
This will be useful for some things. This also removes the need for TCPSocket to be special about this.
2020-09-06Kernel: Virtualize the File::stat() operationAndreas Kling
Instead of FileDescriptor branching on the type of File it's wrapping, add a File::stat() function that can be overridden to provide custom behavior for the stat syscalls.
2020-08-31Kernel: Add more detailed debug output for E1000 {in,out}{8,16,32}Luke
Also adds FIXME for VirtualBox.
2020-08-30Kernel: Unbreak building with extra debug macros, part 2Ben Wiederhake
2020-08-30Kernel: Unbreak building with extra debug macros, part 1Ben Wiederhake
2020-08-25AK: Add Endian.h header to replace NetworkOrdered.h.asynts
2020-08-25Kernel: Switch singletons to use new Singleton classTom
MemoryManager cannot use the Singleton class because MemoryManager::initialize is called before the global constructors are run. That caused the Singleton to be re-initialized, causing it to create another MemoryManager instance. Fixes #3226
2020-08-22Revert "Kernel: Switch singletons to use new Singleton class"Andreas Kling
This reverts commit f48feae0b2a300992479abf0b2ded85e45ac6045.
2020-08-22Revert "Kernel: Move Singleton class to AK"Andreas Kling
This reverts commit f0906250a181c831508a45434b9f645ff98f33e4.
2020-08-22Revert "AK: Get rid of make_singleton function"Andreas Kling
This reverts commit 5a98e329d157a2db8379e0c97c6bdc1328027843.
2020-08-22AK: Get rid of make_singleton functionTom
Just default the InitFunction template argument.
2020-08-22Kernel: Move Singleton class to AKTom
2020-08-21Kernel: Switch singletons to use new Singleton classTom
Fixes #3226
2020-08-19Kernel: Use Userspace<T> for the recvfrom syscall, and Socket implementationBrian Gianforcaro
This fixes a bunch of unchecked kernel reads and writes, seems like they would might exploitable :). Write of sockaddr_in size to any address you please...
2020-08-19Kernel: Use Userspace<T> for the sendto syscall, and Socket implementationBrian Gianforcaro
Note that the data member is of type ImmutableBufferArgument, which has no Userspace<T> usage. I left it alone for now, to be fixed in a future change holistically for all usages.
2020-08-16AK: Rename KB, MB, GB to KiB, MiB, GiBNico Weber
The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9". The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30". Let's use the correct name, at least in code. Only changes the name of the constants, no other behavior change.
2020-08-15AK: Rename span() to bytes() when appropriate.asynts
I originally defined the bytes() method for the String class, because it made it obvious that it's a span of bytes instead of span of characters. This commit makes this more consistent by defining a bytes() method when the type of the span is known to be u8. Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and such.
2020-08-10Kernel: Use Userspace<T> for the bind syscall, and implementationBrian Gianforcaro
2020-08-10Kernel: PID/TID typingBen Wiederhake
This compiles, and contains exactly the same bugs as before. The regex 'FIXME: PID/' should reveal all markers that I left behind, including: - Incomplete conversion - Issues or things that look fishy - Actual bugs that will go wrong during runtime
2020-08-07Kernel: Use Userspace<T> for the getsockopt syscall and Socket interfaceBrian Gianforcaro
The way getsockopt is implemented for socket types requires us to push down Userspace<T> using into those interfaces. This change does so, and utilizes proper copy implementations instead of the kind of haphazard pointer dereferencing that was occurring there before.
2020-08-07Kernel: Use Userspace<T> for the setsockopt syscallBrian Gianforcaro
2020-08-05Kernel: Suppress remaining unobserved KResult return codesBrian Gianforcaro
These are all cases where there is no clear and easy fix, I've left FIXME bread crumbs so that these can hopefully be fixed over time.
2020-08-05Kernel: Switch IPv4Socket receive queue to SinglyLinkedListWithCount<T>Brian Gianforcaro
Avoid walking the packet queue, instead use a linked list with a count.
2020-08-04Kernel: Make File::write() and File::read() return KResultOr<size_t>Andreas Kling
Instead of returning a ssize_t where negative values mean error, we now return KResultOr<size_t> and use the error state to report errors exclusively.
2020-08-03Kernel: Consolidate timeout logicTom
Allow passing in an optional timeout to Thread::block and move the timeout check out of Thread::Blocker. This way all Blockers implicitly support timeouts and don't need to implement it themselves. Do however allow them to override timeouts (e.g. for sockets).
2020-07-31Kernel: Remove SmapDisabler in sys$setsockopt()Andreas Kling
2020-07-31Kernel: Remove SmapDisabler in sys$ioctl()Andreas Kling
Use copy_{to,from}_user() in the various File::ioctl() implementations instead of disabling SMAP wholesale in sys$ioctl(). This patch does not port IPv4Socket::ioctl() to those API's since that will be more involved. That function now creates a local SmapDisabler.
2020-07-28Net: Fix IPv4 fragmentation not working for larger payloadsAndreas Kling
We were masking the fragment offset bits incorrectly in the IPv4 header sent out with fragments. This worked up to ~32KB but after that, things would get very confused. :^)
2020-07-28Kernel: Use AK::Span a bunch in the network adapter codeAndreas Kling
2020-07-07Kernel: Fix checking BlockResultTom
We now have BlockResult::WokeNormally and BlockResult::NotBlocked, both of which indicate no error. We can no longer just check for BlockResult::WokeNormally and assume anything else must be an interruption.
2020-07-06Kernel: Require a reason to be passed to Thread::wait_onTom
The Lock class still permits no reason, but for everything else require a reason to be passed to Thread::wait_on. This makes it easier to diagnose why a Thread is in Queued state.