summaryrefslogtreecommitdiff
path: root/Kernel/Bus/PCI
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Bus/PCI')
-rw-r--r--Kernel/Bus/PCI/Access.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp
index 09d5e72a1f..183c52fd5e 100644
--- a/Kernel/Bus/PCI/Access.cpp
+++ b/Kernel/Bus/PCI/Access.cpp
@@ -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();