Author: ion
Date: Mon Jan 30 10:15:29 2012
New Revision: 55323

URL: http://svn.reactos.org/svn/reactos?rev=55323&view=rev
Log:
[NTOSKRNL]: Here's another gem. SMSS2 couldn't call LdrVerifyImageCheckSum, nor 
could it create Known DLL sections (of course, magically SMSS could). Turns out 
what Mm expects in terms of file access rights when you map a section has 
almost nothing to do with what it should expect. Added a new function to ARM3 
(which had most of the code there already) so correctly determine which file 
access rights should be needed. One big change is that you can now map sections 
with PAGE_EXECUTE if you only have FILE_EXECUTE (FILE_READ_DATA no longer 
required), as things should be.

Modified:
    trunk/reactos/ntoskrnl/mm/ARM3/section.c
    trunk/reactos/ntoskrnl/mm/section.c

Modified: trunk/reactos/ntoskrnl/mm/ARM3/section.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/section.c?rev=55323&r1=55322&r2=55323&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/section.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/section.c [iso-8859-1] Mon Jan 30 10:15:29 
2012
@@ -27,6 +27,18 @@
     SECTION_MAP_READ,
     SECTION_MAP_EXECUTE | SECTION_MAP_WRITE,
     SECTION_MAP_EXECUTE | SECTION_MAP_READ
+};
+
+ACCESS_MASK MmMakeFileAccess[8] =
+{
+    FILE_READ_DATA,
+    FILE_READ_DATA,
+    FILE_EXECUTE,
+    FILE_EXECUTE | FILE_READ_DATA,
+    FILE_WRITE_DATA | FILE_READ_DATA,
+    FILE_READ_DATA,
+    FILE_EXECUTE | FILE_WRITE_DATA | FILE_READ_DATA,
+    FILE_EXECUTE | FILE_READ_DATA
 };
 
 CHAR MmUserProtectionToMask1[16] =
@@ -73,6 +85,24 @@
 
 /* PRIVATE FUNCTIONS 
**********************************************************/
 
+ACCESS_MASK
+NTAPI
+MiArm3GetCorrectFileAccessMask(IN ACCESS_MASK SectionPageProtection)
+{
+    ULONG ProtectionMask;
+
+    /* Calculate the protection mask and make sure it's valid */
+    ProtectionMask = MiMakeProtectionMask(SectionPageProtection);
+    if (ProtectionMask == MM_INVALID_PROTECTION)
+    {
+        DPRINT1("Invalid protection mask\n");
+        return STATUS_INVALID_PAGE_PROTECTION;
+    }
+
+    /* Now convert it to the required file access */
+    return MmMakeFileAccess[ProtectionMask & 0x7];
+}
+
 ULONG
 NTAPI
 MiMakeProtectionMask(IN ULONG Protect)

Modified: trunk/reactos/ntoskrnl/mm/section.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c?rev=55323&r1=55322&r2=55323&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] Mon Jan 30 10:15:29 2012
@@ -150,6 +150,7 @@
     PAGE_EXECUTE_READWRITE, /* 15 = WRITABLE, READABLE, EXECUTABLE, SHARED */
 };
 
+ACCESS_MASK NTAPI MiArm3GetCorrectFileAccessMask(IN ACCESS_MASK 
SectionPageProtection);
 static GENERIC_MAPPING MmpSectionMapping = {
          STANDARD_RIGHTS_READ | SECTION_MAP_READ | SECTION_QUERY,
          STANDARD_RIGHTS_WRITE | SECTION_MAP_WRITE,
@@ -3012,22 +3013,10 @@
    Section->AllocationAttributes = AllocationAttributes;
 
    /*
-    * Check file access required
-    */
-   if (SectionPageProtection & PAGE_READWRITE ||
-         SectionPageProtection & PAGE_EXECUTE_READWRITE)
-   {
-      FileAccess = FILE_READ_DATA | FILE_WRITE_DATA;
-   }
-   else
-   {
-      FileAccess = FILE_READ_DATA;
-   }
-
-   /*
     * Reference the file handle
     */
-   Status = ObReferenceObjectByHandle(FileHandle,
+    FileAccess = MiArm3GetCorrectFileAccessMask(SectionPageProtection);
+    Status = ObReferenceObjectByHandle(FileHandle,
                                       FileAccess,
                                       IoFileObjectType,
                                       ExGetPreviousMode(),
@@ -3882,22 +3871,10 @@
    ULONG FileAccess = 0;
 
    /*
-    * Check file access required
-    */
-   if (SectionPageProtection & PAGE_READWRITE ||
-         SectionPageProtection & PAGE_EXECUTE_READWRITE)
-   {
-      FileAccess = FILE_READ_DATA | FILE_WRITE_DATA;
-   }
-   else
-   {
-      FileAccess = FILE_READ_DATA;
-   }
-
-   /*
     * Reference the file handle
     */
-   Status = ObReferenceObjectByHandle(FileHandle,
+    FileAccess = MiArm3GetCorrectFileAccessMask(SectionPageProtection);
+    Status = ObReferenceObjectByHandle(FileHandle,
                                       FileAccess,
                                       IoFileObjectType,
                                       ExGetPreviousMode(),


Reply via email to