From 32bd2dedd92c994efb538bec7fbc31f5dd5b6122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 21 Feb 2013 16:35:37 +0100 Subject: [PATCH] bootloader: Fix an overlooked condition in mmu_allocate() The size variable at this point is actually a page count. The test should never be true anyway though. Maybe we should use a pages variable for clarity? --- src/system/boot/arch/arm/arch_mmu.cpp | 4 ++-- src/system/boot/arch/m68k/mmu.cpp | 3 ++- src/system/boot/platform/amiga_m68k/mmu.cpp | 3 ++- src/system/boot/platform/atari_m68k/mmu.cpp | 3 ++- src/system/boot/platform/bios_ia32/mmu.cpp | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/system/boot/arch/arm/arch_mmu.cpp b/src/system/boot/arch/arm/arch_mmu.cpp index 1183551384..8867f7f753 100644 --- a/src/system/boot/arch/arm/arch_mmu.cpp +++ b/src/system/boot/arch/arm/arch_mmu.cpp @@ -474,8 +474,8 @@ mmu_allocate(void *virtualAddress, size_t size) addr_t address = (addr_t)virtualAddress; // is the address within the valid range? - if (address < KERNEL_BASE - || address + size >= KERNEL_BASE + kMaxKernelSize) { + if (address < KERNEL_BASE || address + size * B_PAGE_SIZE + >= KERNEL_BASE + kMaxKernelSize) { TRACE(("mmu_allocate in illegal range\n address: %" B_PRIx32 " KERNELBASE: %" B_PRIx32 " KERNEL_BASE + kMaxKernelSize: %" B_PRIx32 " address + size : %" B_PRIx32 "\n", (uint32)address, diff --git a/src/system/boot/arch/m68k/mmu.cpp b/src/system/boot/arch/m68k/mmu.cpp index b7c2526d4a..1a447901d5 100644 --- a/src/system/boot/arch/m68k/mmu.cpp +++ b/src/system/boot/arch/m68k/mmu.cpp @@ -338,7 +338,8 @@ mmu_allocate(void *virtualAddress, size_t size) addr_t address = (addr_t)virtualAddress; // is the address within the valid range? - if (address < KERNEL_BASE || address + size >= KERNEL_BASE + kMaxKernelSize) + if (address < KERNEL_BASE || address + size * B_PAGE_SIZE + >= KERNEL_BASE + kMaxKernelSize) return NULL; for (uint32 i = 0; i < size; i++) { diff --git a/src/system/boot/platform/amiga_m68k/mmu.cpp b/src/system/boot/platform/amiga_m68k/mmu.cpp index 03f56b9f4e..1dde414257 100644 --- a/src/system/boot/platform/amiga_m68k/mmu.cpp +++ b/src/system/boot/platform/amiga_m68k/mmu.cpp @@ -338,7 +338,8 @@ mmu_allocate(void *virtualAddress, size_t size) addr_t address = (addr_t)virtualAddress; // is the address within the valid range? - if (address < KERNEL_BASE || address + size >= KERNEL_BASE + kMaxKernelSize) + if (address < KERNEL_BASE || address + size * B_PAGE_SIZE + >= KERNEL_BASE + kMaxKernelSize) return NULL; for (uint32 i = 0; i < size; i++) { diff --git a/src/system/boot/platform/atari_m68k/mmu.cpp b/src/system/boot/platform/atari_m68k/mmu.cpp index 7132119fd2..548d6d5c55 100644 --- a/src/system/boot/platform/atari_m68k/mmu.cpp +++ b/src/system/boot/platform/atari_m68k/mmu.cpp @@ -339,7 +339,8 @@ mmu_allocate(void *virtualAddress, size_t size) addr_t address = (addr_t)virtualAddress; // is the address within the valid range? - if (address < KERNEL_BASE || address + size >= KERNEL_BASE + kMaxKernelSize) + if (address < KERNEL_BASE || address + size * B_PAGE_SIZE + >= KERNEL_BASE + kMaxKernelSize) return NULL; for (uint32 i = 0; i < size; i++) { diff --git a/src/system/boot/platform/bios_ia32/mmu.cpp b/src/system/boot/platform/bios_ia32/mmu.cpp index 4eef5defa5..93eaed5423 100644 --- a/src/system/boot/platform/bios_ia32/mmu.cpp +++ b/src/system/boot/platform/bios_ia32/mmu.cpp @@ -397,8 +397,8 @@ mmu_allocate(void *virtualAddress, size_t size) addr_t address = (addr_t)virtualAddress; // is the address within the valid range? - if (address < KERNEL_LOAD_BASE - || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) + if (address < KERNEL_LOAD_BASE || address + size * B_PAGE_SIZE + >= KERNEL_LOAD_BASE + kMaxKernelSize) return NULL; for (uint32 i = 0; i < size; i++) {