summaryrefslogtreecommitdiff
path: root/Kernel/Bus/PCI
diff options
context:
space:
mode:
authorGuilherme Goncalves <guilherme.p.gonc@gmail.com>2021-12-24 11:22:11 -0300
committerAndreas Kling <kling@serenityos.org>2021-12-28 23:08:50 +0100
commit33b78915d377dfb950d93f150b8470aea2c1e66f (patch)
tree0be4e64332e2e7120720496f5db9dd1ffc6704b3 /Kernel/Bus/PCI
parent11599a334232d203c21a21662375ac952e3d7f0a (diff)
downloadserenity-33b78915d377dfb950d93f150b8470aea2c1e66f.zip
Kernel: Propagate overflow errors from Memory::page_round_up
Fixes #11402.
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();