[NTOS:MM]
authorThomas Faber <thomas.faber@reactos.org>
Sun, 23 Apr 2017 09:38:45 +0000 (09:38 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sun, 23 Apr 2017 09:38:45 +0000 (09:38 +0000)
- In NtMapViewOfSection, check for address alignment after validating the handles. This fixes the tests from the previous commit, but is also necessary because information about the section object is necessary to avoid the alignment checks for physical memory sections.
CORE-13113

svn path=/trunk/; revision=74391

reactos/ntoskrnl/mm/ARM3/section.c

index 5977fda..4d274ba 100644 (file)
@@ -3661,23 +3661,6 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
         }
     }
 
-    if (!(AllocationType & MEM_DOS_LIM))
-    {
-        /* Check for non-allocation-granularity-aligned BaseAddress */
-        if (SafeBaseAddress != ALIGN_DOWN_POINTER_BY(SafeBaseAddress, MM_VIRTMEM_GRANULARITY))
-        {
-           DPRINT("BaseAddress is not at 64-kilobyte address boundary.");
-           return STATUS_MAPPED_ALIGNMENT;
-        }
-
-        /* Do the same for the section offset */
-        if (SafeSectionOffset.LowPart != ALIGN_DOWN_BY(SafeSectionOffset.LowPart, MM_VIRTMEM_GRANULARITY))
-        {
-           DPRINT("SectionOffset is not at 64-kilobyte address boundary.");
-           return STATUS_MAPPED_ALIGNMENT;
-        }
-    }
-
     /* Reference the process */
     Status = ObReferenceObjectByHandle(ProcessHandle,
                                        PROCESS_VM_OPERATION,
@@ -3700,6 +3683,27 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
         return Status;
     }
 
+    if (!(AllocationType & MEM_DOS_LIM))
+    {
+        /* Check for non-allocation-granularity-aligned BaseAddress */
+        if (SafeBaseAddress != ALIGN_DOWN_POINTER_BY(SafeBaseAddress, MM_VIRTMEM_GRANULARITY))
+        {
+           DPRINT("BaseAddress is not at 64-kilobyte address boundary.");
+           ObDereferenceObject(Section);
+           ObDereferenceObject(Process);
+           return STATUS_MAPPED_ALIGNMENT;
+        }
+
+        /* Do the same for the section offset */
+        if (SafeSectionOffset.LowPart != ALIGN_DOWN_BY(SafeSectionOffset.LowPart, MM_VIRTMEM_GRANULARITY))
+        {
+           DPRINT("SectionOffset is not at 64-kilobyte address boundary.");
+           ObDereferenceObject(Section);
+           ObDereferenceObject(Process);
+           return STATUS_MAPPED_ALIGNMENT;
+        }
+    }
+
     /* Now do the actual mapping */
     Status = MmMapViewOfSection(Section,
                                 Process,