1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:17:45 +00:00

Kernel: Propagate overflow errors from Memory::page_round_up

Fixes #11402.
This commit is contained in:
Guilherme Goncalves 2021-12-24 11:22:11 -03:00 committed by Andreas Kling
parent 11599a3342
commit 33b78915d3
31 changed files with 112 additions and 100 deletions

View file

@ -59,7 +59,17 @@ UNMAP_AFTER_INIT bool Access::search_pci_domains_from_acpi_mcfg_table(PhysicalAd
dbgln("PCI: MCFG, length: {}, revision: {}", length, revision);
auto mcfg_region_or_error = MM.allocate_kernel_region(mcfg_table.page_base(), Memory::page_round_up(length) + PAGE_SIZE, "PCI Parsing MCFG", Memory::Region::Access::ReadWrite);
if (Checked<size_t>::addition_would_overflow(length, PAGE_SIZE)) {
dbgln("Overflow when adding extra page to allocation of length {}", length);
return false;
}
length += PAGE_SIZE;
auto region_size_or_error = Memory::page_round_up(length);
if (region_size_or_error.is_error()) {
dbgln("Failed to round up length of {} to pages", length);
return false;
}
auto mcfg_region_or_error = MM.allocate_kernel_region(mcfg_table.page_base(), region_size_or_error.value(), "PCI Parsing MCFG", Memory::Region::Access::ReadWrite);
if (mcfg_region_or_error.is_error())
return false;
auto& mcfg = *(ACPI::Structures::MCFG*)mcfg_region_or_error.value()->vaddr().offset(mcfg_table.offset_in_page()).as_ptr();

View file

@ -131,7 +131,12 @@ UNMAP_AFTER_INIT void Device::initialize()
auto& mapping = m_mmio[cfg.bar];
mapping.size = PCI::get_BAR_space_size(pci_address(), cfg.bar);
if (!mapping.base && mapping.size) {
auto region_or_error = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR(pci_address(), cfg.bar))), Memory::page_round_up(mapping.size), "VirtIO MMIO", Memory::Region::Access::ReadWrite, Memory::Region::Cacheable::No);
auto region_size_or_error = Memory::page_round_up(mapping.size);
if (region_size_or_error.is_error()) {
dbgln_if(VIRTIO_DEBUG, "{}: Failed to round up size={} to pages", m_class_name, mapping.size);
continue;
}
auto region_or_error = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR(pci_address(), cfg.bar))), region_size_or_error.value(), "VirtIO MMIO", Memory::Region::Access::ReadWrite, Memory::Region::Cacheable::No);
if (region_or_error.is_error()) {
dbgln_if(VIRTIO_DEBUG, "{}: Failed to map bar {} - (size={}) {}", m_class_name, cfg.bar, mapping.size, region_or_error.error());
} else {

View file

@ -17,7 +17,7 @@ Queue::Queue(u16 queue_size, u16 notify_offset)
size_t size_of_descriptors = sizeof(QueueDescriptor) * queue_size;
size_t size_of_driver = sizeof(QueueDriver) + queue_size * sizeof(u16);
size_t size_of_device = sizeof(QueueDevice) + queue_size * sizeof(QueueDeviceItem);
auto queue_region_size = Memory::page_round_up(size_of_descriptors + size_of_driver + size_of_device);
auto queue_region_size = Memory::page_round_up(size_of_descriptors + size_of_driver + size_of_device).release_value_but_fixme_should_propagate_errors();
if (queue_region_size <= PAGE_SIZE)
m_queue_region = MM.allocate_kernel_region(queue_region_size, "VirtIO Queue", Memory::Region::Access::ReadWrite).release_value();
else