Compare commits

...

2 Commits

Author SHA1 Message Date
7a78609a85
kernel: Preserve kernel threads' page directories when they differ from the regular kernel page directory
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-17 00:49:31 +02:00
c2cdb861c9
kernel/ATA: Fix buffer overflow in ATADevice::read() with small sizes and unaligned offsets 2023-06-17 00:48:53 +02:00
2 changed files with 8 additions and 1 deletions

View File

@ -750,12 +750,17 @@ Result<u64> ATADevice::read(u8* buf, usize offset, usize size) const
ScopedKMutexLock<100>(m_drive->channel()->lock());
// FIXME: Don't always allocate this if we don't need it.
auto* temp = TRY(make_array<u8>(block_size));
auto guard = make_scope_guard([temp] { delete[] temp; });
if (offset % block_size)
{
// The size we need to read to round up to a block.
usize extra_size = block_size - (offset % block_size);
// Maybe we don't even want enough to get to the next block?
if (extra_size > size) extra_size = size;
TRY(m_drive->read_lba(offset / block_size, temp, 1));
memcpy(buf, temp + (offset % block_size), extra_size);
offset += extra_size;

View File

@ -233,9 +233,11 @@ namespace Scheduler
{
switch_context(old_thread, new_thread, regs);
if (!old_thread->is_kernel) old_thread->fp_data.save();
if (old_thread->is_kernel && MMU::get_page_directory() != MMU::kernel_page_directory())
old_thread->directory = MMU::get_page_directory();
if (new_thread->directory) MMU::switch_page_directory(new_thread->directory);
if (!new_thread->is_kernel)
{
MMU::switch_page_directory(new_thread->directory);
CPU::switch_kernel_stack(new_thread->kernel_stack.top());
new_thread->fp_data.restore();
}