From 864a1bc6ae1012e5a79fb1cc83b2cdd0b60695bd Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Mon, 30 Jan 2012 10:15:29 +0000 Subject: [PATCH] [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. svn path=/trunk/; revision=55323 --- reactos/ntoskrnl/mm/ARM3/section.c | 30 +++++++++++++++++++++++++++ reactos/ntoskrnl/mm/section.c | 33 +++++------------------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/reactos/ntoskrnl/mm/ARM3/section.c b/reactos/ntoskrnl/mm/ARM3/section.c index d5c33291042..c1a6dfe343b 100644 --- a/reactos/ntoskrnl/mm/ARM3/section.c +++ b/reactos/ntoskrnl/mm/ARM3/section.c @@ -29,6 +29,18 @@ ACCESS_MASK MmMakeSectionAccess[8] = 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] = { 0, @@ -73,6 +85,24 @@ MMSESSION MmSession; /* 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) diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index 71eef6cf33f..bde920327c8 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -150,6 +150,7 @@ static ULONG SectionCharacteristicsToProtect[16] = 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, @@ -3011,23 +3012,11 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject, Section->SectionPageProtection = SectionPageProtection; 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(), @@ -3881,23 +3870,11 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject, ULONG i; 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(),