diff --git a/reactos/ntoskrnl/mm/ARM3/section.c b/reactos/ntoskrnl/mm/ARM3/section.c index e32ad45d824..7a2f3b5e266 100644 --- a/reactos/ntoskrnl/mm/ARM3/section.c +++ b/reactos/ntoskrnl/mm/ARM3/section.c @@ -3550,14 +3550,40 @@ NtMapViewOfSection(IN HANDLE SectionHandle, } _SEH2_END; - /* Check for invalid zero bits */ - if (ZeroBits && SafeBaseAddress) + /* Check for kernel-mode address */ + if (SafeBaseAddress > MM_HIGHEST_VAD_ADDRESS) { + DPRINT1("Kernel base not allowed\n"); + return STATUS_INVALID_PARAMETER_3; + } + + /* Check for range entering kernel-mode */ + if (((ULONG_PTR)MM_HIGHEST_VAD_ADDRESS - (ULONG_PTR)SafeBaseAddress) < SafeViewSize) + { + DPRINT1("Overflowing into kernel base not allowed\n"); + return STATUS_INVALID_PARAMETER_3; + } + + /* Check for invalid zero bits */ + if (ZeroBits) + { + if (ZeroBits > MI_MAX_ZERO_BITS) + { + DPRINT1("Invalid zero bits\n"); + return STATUS_INVALID_PARAMETER_4; + } + if ((((ULONG_PTR)SafeBaseAddress << ZeroBits) >> ZeroBits) != (ULONG_PTR)SafeBaseAddress) { DPRINT1("Invalid zero bits\n"); return STATUS_INVALID_PARAMETER_4; } + + if (((((ULONG_PTR)SafeBaseAddress + SafeViewSize) << ZeroBits) >> ZeroBits) != ((ULONG_PTR)SafeBaseAddress + SafeViewSize)) + { + DPRINT1("Invalid zero bits\n"); + return STATUS_INVALID_PARAMETER_4; + } } if (!(AllocationType & MEM_DOS_LIM)) @@ -3577,27 +3603,6 @@ NtMapViewOfSection(IN HANDLE SectionHandle, } } - /* Check for kernel-mode address */ - if (SafeBaseAddress > MM_HIGHEST_VAD_ADDRESS) - { - DPRINT1("Kernel base not allowed\n"); - return STATUS_INVALID_PARAMETER_3; - } - - /* Check for range entering kernel-mode */ - if (((ULONG_PTR)MM_HIGHEST_VAD_ADDRESS - (ULONG_PTR)SafeBaseAddress) < SafeViewSize) - { - DPRINT1("Overflowing into kernel base not allowed\n"); - return STATUS_INVALID_PARAMETER_3; - } - - /* Check for invalid zero bits */ - if (((ULONG_PTR)SafeBaseAddress + SafeViewSize) > (0xFFFFFFFF >> ZeroBits)) // arch? - { - DPRINT1("Invalid zero bits\n"); - return STATUS_INVALID_PARAMETER_4; - } - /* Reference the process */ Status = ObReferenceObjectByHandle(ProcessHandle, PROCESS_VM_OPERATION,