ladybird/Kernel
Brian Gianforcaro 6830963321 Kernel: Validate we don't hold s_mm_lock during context switch
Since `s_mm_lock` is a RecursiveSpinlock, if a kernel thread gets
preempted while accidentally hold the lock during switch_context,
another thread running on the same processor could end up manipulating
the state of the memory manager even though they should not be able to.
It will just bump the recursion count and keep going.

This appears to be the root cause of weird bugs like: #7359
Where page protection magically appears to be wrong during execution.

To avoid these cases lets guard this specific unfortunate case and make
sure it can never go unnoticed ever again.

The assert was Tom's idea to help debug this, so I am going to tag him
as co-author of this commit.

Co-Authored-By: Tom <tomut@yahoo.com>
2021-05-25 10:35:41 +02:00
..
ACPI Kernel/ACPI: Map two pages when reading the FADT 2021-05-08 19:15:54 +02:00
API Kernel: Add statvfs & fstatvfs Syscalls 2021-05-19 21:33:29 +02:00
Arch Kernel/CPU: Fix awkward printing early on boot 2021-05-21 22:38:26 +01:00
Devices Kernel: Process request to change virtual console from the IO Work queue 2021-05-21 08:08:33 +02:00
FileSystem Kernel: Remove an allocation from VFS::resolve_path_without_veil (#7287) 2021-05-22 00:12:32 +02:00
Graphics Kernel/Graphics: Indicate initialization failed if no device was found 2021-05-21 17:58:53 +01:00
Heap Kernel: Add support for profiling kmalloc()/kfree() 2021-05-19 22:51:42 +02:00
Interrupts Kernel: Add Processor::is_bootstrap_processor() function, and use it. (#6871) 2021-05-05 18:48:26 +02:00
Modules Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Net Kernel/Net: Make interfaces to have persistent names 2021-05-22 11:19:50 +01:00
PCI Kernel/PCI: Fix support of multiple PCI host controllers enumeration 2021-05-21 17:58:53 +01:00
Storage Kernel: Don't ref-count UsedMemoryRange during iteration 2021-05-16 19:58:33 +02:00
Syscalls Kernel: Disable profiling if setting up the buffer or timer failed 2021-05-24 09:10:50 +02:00
Tasks Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Time Kernel: Fix return value for {enable,disable}_profile_timer() 2021-05-17 21:53:04 +02:00
TTY LibVT: Add Alternate Screen Buffer support 2021-05-24 22:26:54 +04:30
VirtIO Kernel: Reorder VirtIODevice PCI initialization steps 2021-05-15 23:29:03 +01:00
VM Kernel: Release the paging lock while reading from the disk 2021-05-25 10:35:41 +02:00
AddressSanitizer.cpp Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
AddressSanitizer.h Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
Assertions.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CMakeLists.txt Meta: Make generate_state_machine() generate a proper target 2021-05-20 12:11:27 +01:00
CMOS.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CMOS.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CommandLine.cpp Kernel/Commandline: Allow the user to specify an embedded string 2021-05-21 22:38:26 +01:00
CommandLine.h Kernel/Commandline: Allow the user to specify an embedded string 2021-05-21 22:38:26 +01:00
ConsoleDevice.cpp Kernel: Rename Console => ConsoleDevice 2021-05-16 19:58:33 +02:00
ConsoleDevice.h Kernel: Rename Console => ConsoleDevice 2021-05-16 19:58:33 +02:00
CoreDump.cpp Everywhere: Use linusg@serenityos.org for my copyright headers 2021-04-22 22:51:19 +02:00
CoreDump.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Debug.h.in Kernel/Graphics + SystemServer: Support text mode properly 2021-05-16 19:58:33 +02:00
DMI.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
DMI.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
DoubleBuffer.cpp Kernel: Don't update write_pos in DoubleBuffer if userspace copy fails 2021-05-18 16:47:26 +02:00
DoubleBuffer.h Kernel: Implement peek() function for DoubleBuffer 2021-04-29 08:09:53 +02:00
Forward.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
FutexQueue.cpp Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
FutexQueue.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
init.cpp Kernel+LibC: Add support for filtering profiling events 2021-05-19 22:51:42 +02:00
IO.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
KBuffer.h Kernel: Make KBuffer::try_create_with* APIs OOM safe 2021-05-13 16:21:53 +02:00
KBufferBuilder.cpp Kernel: Replace make<T>() with adopt_own_if_nonnull() in KBufferBuilder 2021-05-13 16:21:53 +02:00
KBufferBuilder.h Kernel: Avoid allocations in KBufferBuilder::appendff 2021-05-13 08:27:42 +02:00
kprintf.cpp Kernel: Implement a PCI Serial Device driver 2021-05-17 18:15:25 +02:00
KResult.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
kstdio.h Kernel/Graphics + SystemServer: Support text mode properly 2021-05-16 19:58:33 +02:00
KSyms.cpp Kernel: Check kernel symbol's name length matches searched name 2021-04-28 22:14:32 +02:00
KSyms.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
linker.ld Kernel: Define a KERNEL_VIRTUAL_BASE in the linker script 2021-03-04 18:25:01 +01:00
Lock.cpp Kernel: Utilize AK::SourceLocation for LOCK_DEBUG instrumentation. 2021-04-25 09:38:27 +02:00
Lock.h Kernel: Add ScopedLockRelease to temporarily release a Lock 2021-05-25 10:35:41 +02:00
LockMode.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
mkmap.sh Build: Switch to CMake :^) 2020-05-14 20:15:18 +02:00
Module.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Multiboot.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Panic.cpp Kernel/Graphics + SystemServer: Support text mode properly 2021-05-16 19:58:33 +02:00
Panic.h Kernel/Graphics + SystemServer: Support text mode properly 2021-05-16 19:58:33 +02:00
PerformanceEventBuffer.cpp Kernel: Generate page fault events from the kernel profiler 2021-05-19 22:51:42 +02:00
PerformanceEventBuffer.h Kernel: Add support for profiling kmalloc()/kfree() 2021-05-19 22:51:42 +02:00
PerformanceManager.h Kernel: Make sure we only log profiling events when m_profiling is true 2021-05-23 23:54:30 +01:00
PhysicalAddress.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Process.cpp Kernel: Print a message to debug log after writing a perfcore file 2021-05-22 22:23:52 +02:00
Process.h Kernel: Make sure we only log profiling events when m_profiling is true 2021-05-23 23:54:30 +01:00
ProcessGroup.cpp Revert "Kernel: Avoid allocating under spinlock in ProcessGroup::find_or_create" 2021-05-21 12:36:20 +02:00
ProcessGroup.h Revert "Kernel: Avoid allocating under spinlock in ProcessGroup::find_or_create" 2021-05-21 12:36:20 +02:00
Random.cpp Kernel: Remove the now defunct LOCKER(..) macro. 2021-04-25 09:38:27 +02:00
Random.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
RTC.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
RTC.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Scheduler.cpp Kernel: Validate we don't hold s_mm_lock during context switch 2021-05-25 10:35:41 +02:00
Scheduler.h Kernel: Add support for profiling kmalloc()/kfree() 2021-05-19 22:51:42 +02:00
SpinLock.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
StdLib.cpp Kernel: Enable building the kernel with -flto 2021-04-29 20:26:36 +02:00
StdLib.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Syscall.cpp Kernel: Enable building the kernel with -flto 2021-04-29 20:26:36 +02:00
Thread.cpp Kernel: Close a Thread tid lookup race 2021-05-20 22:08:36 +02:00
Thread.h Kernel: Remove an allocation when blocking a thread 2021-05-20 09:09:10 +02:00
ThreadBlockers.cpp Kernel: Modify TimeManagement::current_time(..) API so it can't fail. (#6869) 2021-05-05 18:51:06 +02:00
ThreadTracer.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ThreadTracer.h Kernel: Make Process::start_tracing_from API OOM safe 2021-05-13 16:21:53 +02:00
TimerQueue.cpp Kernel: Remove an allocation when blocking a thread 2021-05-20 09:09:10 +02:00
TimerQueue.h Kernel: Remove an allocation when blocking a thread 2021-05-20 09:09:10 +02:00
UBSanitizer.cpp Kernel: static vs non-static constexpr variables 2021-05-19 21:21:47 +01:00
UBSanitizer.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
UnixTypes.h Kernel: Generate page fault events from the kernel profiler 2021-05-19 22:51:42 +02:00
UnveilNode.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
UserOrKernelBuffer.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
UserOrKernelBuffer.h Kernel: Make UserOrKernelBuffer R/W helpers return KResultOr<size_t> 2021-05-13 23:28:40 +02:00
VirtualAddress.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
WaitQueue.cpp Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
WaitQueue.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
WorkQueue.cpp Kernel: Use plain Function objects for the WorkQueue 2021-05-19 21:36:57 +02:00
WorkQueue.h Kernel: Use plain Function objects for the WorkQueue 2021-05-19 21:36:57 +02:00