Author: mjmartin Date: Sat May 9 21:00:18 2009 New Revision: 40873 URL: http://svn.reactos.org/svn/reactos?rev=40873&view=rev Log: - NtAllocateVirtualMemory, NtProtectVirtualMemory: Page Protection cannot be any combination of Memory Protection Constants, see MSDN. Add checks to handle non compatible combinations are fail. Fixes 6 more kernel32_winetest for virtual memory.
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c trunk/reactos/ntoskrnl/mm/virtual.c Modified: trunk/reactos/ntoskrnl/mm/anonmem.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/anonmem.c?rev=40873&r1=40872&r2=40873&view=diff ============================================================================== --- trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] Sat May 9 21:00:18 2009 @@ -550,10 +550,7 @@ * AllocationType = Indicates the type of virtual memory you like to * allocated, can be a combination of MEM_COMMIT, * MEM_RESERVE, MEM_RESET, MEM_TOP_DOWN. - * Protect = Indicates the protection type of the pages allocated, can be - * a combination of PAGE_READONLY, PAGE_READWRITE, - * PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_GUARD, - * PAGE_NOACCESS + * Protect = Indicates the protection type of the pages allocated. * RETURNS: Status */ { @@ -567,6 +564,7 @@ ULONG RegionSize; PVOID PBaseAddress; ULONG PRegionSize; + ULONG MemProtection; PHYSICAL_ADDRESS BoundaryAddressMultiple; KPROCESSOR_MODE PreviousMode; @@ -578,7 +576,15 @@ Protect); /* Check for valid protection flags */ - if (!Protect || Protect & ~PAGE_FLAGS_VALID_FROM_USER_MODE) + MemProtection = Protect & ~(PAGE_GUARD|PAGE_NOCACHE); + if (MemProtection != PAGE_NOACCESS && + MemProtection != PAGE_READONLY && + MemProtection != PAGE_READWRITE && + MemProtection != PAGE_WRITECOPY && + MemProtection != PAGE_EXECUTE && + MemProtection != PAGE_EXECUTE_READ && + MemProtection != PAGE_EXECUTE_READWRITE && + MemProtection != PAGE_EXECUTE_WRITECOPY) { DPRINT1("Invalid page protection\n"); return STATUS_INVALID_PAGE_PROTECTION; Modified: trunk/reactos/ntoskrnl/mm/virtual.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/virtual.c?rev=40873&r1=40872&r2=40873&view=diff ============================================================================== --- trunk/reactos/ntoskrnl/mm/virtual.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/virtual.c [iso-8859-1] Sat May 9 21:00:18 2009 @@ -844,10 +844,25 @@ { PEPROCESS Process; ULONG OldAccessProtection; + ULONG Protection; PVOID BaseAddress = NULL; SIZE_T NumberOfBytesToProtect = 0; KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); NTSTATUS Status = STATUS_SUCCESS; + + /* Check for valid protection flags */ + Protection = NewAccessProtection & ~(PAGE_GUARD|PAGE_NOCACHE); + if (Protection != PAGE_NOACCESS && + Protection != PAGE_READONLY && + Protection != PAGE_READWRITE && + Protection != PAGE_WRITECOPY && + Protection != PAGE_EXECUTE && + Protection != PAGE_EXECUTE_READ && + Protection != PAGE_EXECUTE_READWRITE && + Protection != PAGE_EXECUTE_WRITECOPY) + { + return STATUS_INVALID_PAGE_PROTECTION; + } /* Check if we came from user mode */ if (PreviousMode != KernelMode)