ReactOS  0.4.14-dev-554-g2f8d847
ZwCreateSection.c File Reference
#include <kmt_test.h>
Include dependency graph for ZwCreateSection.c:

Go to the source code of this file.

Macros

#define IGNORE   -999
 
#define NO_HANDLE_CLOSE   -998
 
#define _4mb   4194304
 
#define CREATE_SECTION(Handle, DesiredAccess, Attributes, Size, SectionPageProtection, AllocationAttributes, FileHandle, RetStatus, CloseRetStatus)
 
#define TestMapView(SectionHandle, ProcessHandle, BaseAddress2, ZeroBits, CommitSize, SectionOffset, ViewSize2, InheritDisposition, AllocationType, Win32Protect, MapStatus, UnmapStatus)
 
#define CheckObject(Handle, Pointers, Handles)
 
#define CheckSection(SectionHandle, SectionFlag, SectionSize, RetStatus)
 

Functions

static VOID FileSectionViewPermissionCheck (HANDLE ReadOnlyFile, HANDLE WriteOnlyFile, HANDLE ExecutableFile)
 
static VOID KmtInitTestFiles (PHANDLE ReadOnlyFile, PHANDLE WriteOnlyFile, PHANDLE ExecutableFile)
 
static VOID SimpleErrorChecks (HANDLE FileHandleReadOnly, HANDLE FileHandleWriteOnly, HANDLE FileHandleExecuteOnly)
 
static VOID BasicBehaviorChecks (HANDLE FileHandle)
 
 START_TEST (ZwCreateSection)
 

Variables

const char TestString []
 
const ULONG TestStringSize
 
static UNICODE_STRING FileReadOnlyPath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll")
 
static UNICODE_STRING WritableFilePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\kmtest-MmSection.txt")
 
static UNICODE_STRING CalcImgPath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\calc.exe")
 
static OBJECT_ATTRIBUTES NtdllObject
 
static OBJECT_ATTRIBUTES KmtestFileObject
 
static OBJECT_ATTRIBUTES CalcFileObject
 

Macro Definition Documentation

◆ _4mb

#define _4mb   4194304

Definition at line 12 of file ZwCreateSection.c.

◆ CheckObject

#define CheckObject (   Handle,
  Pointers,
  Handles 
)
Value:
do \
{ \
PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \
Status = ZwQueryObject(Handle, ObjectBasicInformation, \
&ObjectInfo, sizeof ObjectInfo, NULL); \
ok_eq_hex(Status, STATUS_SUCCESS); \
ok_eq_ulong(ObjectInfo.PointerCount, Pointers); \
ok_eq_ulong(ObjectInfo.HandleCount, Handles); \
} while (0)
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938

Definition at line 50 of file ZwCreateSection.c.

◆ CheckSection

#define CheckSection (   SectionHandle,
  SectionFlag,
  SectionSize,
  RetStatus 
)
Value:
do \
{ \
SECTION_BASIC_INFORMATION Sbi; \
NTSTATUS Status; \
Status = ZwQuerySection(SectionHandle, SectionBasicInformation, \
&Sbi, sizeof Sbi, NULL); \
ok_eq_hex(Status, RetStatus); \
if (RetStatus == STATUS_SUCCESS && NT_SUCCESS(Status)) \
{ \
ok_eq_pointer(Sbi.BaseAddress, NULL); \
ok_eq_longlong(Sbi.Size.QuadPart, SectionSize); \
ok_eq_hex(Sbi.Attributes, SectionFlag | SEC_FILE); \
} \
} while (0)
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI ZwQuerySection(_In_ HANDLE SectionHandle, _In_ SECTION_INFORMATION_CLASS SectionInformationClass, _Out_ PVOID SectionInformation, _In_ SIZE_T Length, _Out_opt_ PSIZE_T ResultLength)
#define SEC_FILE
Definition: mmtypes.h:95
return STATUS_SUCCESS
Definition: btrfs.c:2938

Definition at line 61 of file ZwCreateSection.c.

◆ CREATE_SECTION

#define CREATE_SECTION (   Handle,
  DesiredAccess,
  Attributes,
  Size,
  SectionPageProtection,
  AllocationAttributes,
  FileHandle,
  RetStatus,
  CloseRetStatus 
)
Value:
do \
{ \
ok_eq_hex(Status, RetStatus); \
{ \
if (CloseRetStatus != NO_HANDLE_CLOSE) \
{ \
Status = ZwClose(Handle); \
Handle = NULL; \
if (CloseRetStatus != IGNORE) ok_eq_hex(Status, CloseRetStatus); \
} \
} \
} while (0)
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
Definition: mmfuncs.h:360
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG SectionPageProtection
Definition: mmfuncs.h:360
HANDLE FileHandle
Definition: stats.c:38
smooth NULL
Definition: ftsmooth.c:416
#define IGNORE
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NO_HANDLE_CLOSE
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define ok_eq_hex(value, expected)

Definition at line 22 of file ZwCreateSection.c.

◆ IGNORE

#define IGNORE   -999

Definition at line 10 of file ZwCreateSection.c.

◆ NO_HANDLE_CLOSE

#define NO_HANDLE_CLOSE   -998

Definition at line 11 of file ZwCreateSection.c.

◆ TestMapView

#define TestMapView (   SectionHandle,
  ProcessHandle,
  BaseAddress2,
  ZeroBits,
  CommitSize,
  SectionOffset,
  ViewSize2,
  InheritDisposition,
  AllocationType,
  Win32Protect,
  MapStatus,
  UnmapStatus 
)
Value:
do \
{ \
Status = ZwMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress2, ZeroBits, CommitSize, SectionOffset, ViewSize2, InheritDisposition, AllocationType, Win32Protect); \
ok_eq_hex(Status, MapStatus); \
{ \
Status = ZwUnmapViewOfSection(ProcessHandle, BaseAddress); \
if (UnmapStatus != IGNORE) ok_eq_hex(Status, UnmapStatus); \
*BaseAddress2 = NULL; \
*ViewSize2 = 0; \
} \
} while (0)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT InheritDisposition
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR ZeroBits
Definition: mmfuncs.h:404
smooth NULL
Definition: ftsmooth.c:416
#define IGNORE
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T CommitSize
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Win32Protect
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG AllocationType
Definition: mmfuncs.h:404
Status
Definition: gdiplustypes.h:24
#define ok_eq_hex(value, expected)
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Definition at line 37 of file ZwCreateSection.c.

Function Documentation

◆ BasicBehaviorChecks()

static VOID BasicBehaviorChecks ( HANDLE  FileHandle)
static

Definition at line 454 of file ZwCreateSection.c.

455 {
457  HANDLE Section = NULL;
460  Length.QuadPart = TestStringSize;
461 
462  //mimic lack of section support for a particular file as well.
464  if (!skip(NT_SUCCESS(Status), "Cannot reference object by handle\n"))
465  {
466  PSECTION_OBJECT_POINTERS Pointers = FileObject->SectionObjectPointer;
467 
468  FileObject->SectionObjectPointer = NULL;
470  FileObject->SectionObjectPointer = Pointers;
472  }
473 
474  Length.QuadPart = TestStringSize;
476  CheckObject(Section, 2, 1);
477  CheckSection(Section, SEC_FILE, Length.QuadPart, STATUS_SUCCESS);
478  ZwClose(Section); //manually close it due to NO_HANDLE_CLOSE in CREATE_SECTION
479 
480  //section length should be set to that of file
481  Length.QuadPart = 0;
484  ZwClose(Section);
485 
486  //create a smaller section than file
487  Length.QuadPart = TestStringSize - 100;
490  ZwClose(Section);
491 }
#define CheckSection(SectionHandle, SectionFlag, SectionSize, RetStatus)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
HANDLE FileHandle
Definition: stats.c:38
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define SEC_COMMIT
Definition: mmtypes.h:99
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IGNORE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CREATE_SECTION(Handle, DesiredAccess, Attributes, Size, SectionPageProtection, AllocationAttributes, FileHandle, RetStatus, CloseRetStatus)
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
#define NO_HANDLE_CLOSE
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
const ULONG TestStringSize
Status
Definition: gdiplustypes.h:24
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
#define CheckObject(Handle, Pointers, Handles)
#define PAGE_READONLY
Definition: compat.h:127
#define skip(...)
Definition: atltest.h:64
#define SEC_FILE
Definition: mmtypes.h:95
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by START_TEST().

◆ FileSectionViewPermissionCheck()

static VOID FileSectionViewPermissionCheck ( HANDLE  ReadOnlyFile,
HANDLE  WriteOnlyFile,
HANDLE  ExecutableFile 
)
static

Definition at line 78 of file ZwCreateSection.c.

79 {
81  HANDLE SectionHandle = NULL;
83  SIZE_T ViewSize = 0;
85 
86  MaximumSize.QuadPart = TestStringSize;
87 
88  //READ-ONLY FILE COMBINATIONS
93  ZwClose(SectionHandle);
94 
99  ZwClose(SectionHandle);
100 
105  ZwClose(SectionHandle);
106 
111  ZwClose(SectionHandle);
112 
117  ZwClose(SectionHandle);
118 
123  ZwClose(SectionHandle);
124 
129  ZwClose(SectionHandle);
130 
135  ZwClose(SectionHandle);
136 
141  ZwClose(SectionHandle);
142 
147  ZwClose(SectionHandle);
148 
153  ZwClose(SectionHandle);
154 
159  ZwClose(SectionHandle);
160 
161  //WRITE-ONLY FILE COMBINATIONS
166  ZwClose(SectionHandle);
167 
172  ZwClose(SectionHandle);
173 
178  ZwClose(SectionHandle);
179 
184  ZwClose(SectionHandle);
185 
190  ZwClose(SectionHandle);
191 
196  ZwClose(SectionHandle);
197 
202  ZwClose(SectionHandle);
203 
208  ZwClose(SectionHandle);
209 
214  ZwClose(SectionHandle);
215 
220  ZwClose(SectionHandle);
221 
226  ZwClose(SectionHandle);
227 
232  ZwClose(SectionHandle);
233 
234  //EXECUTE ONLY FILE
239 
244 
249 }
#define ZwCurrentProcess()
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define TestMapView(SectionHandle, ProcessHandle, BaseAddress2, ZeroBits, CommitSize, SectionOffset, ViewSize2, InheritDisposition, AllocationType, Win32Protect, MapStatus, UnmapStatus)
#define SEC_COMMIT
Definition: mmtypes.h:99
smooth NULL
Definition: ftsmooth.c:416
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define SECTION_MAP_WRITE
Definition: nt_native.h:1288
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define CREATE_SECTION(Handle, DesiredAccess, Attributes, Size, SectionPageProtection, AllocationAttributes, FileHandle, RetStatus, CloseRetStatus)
#define STATUS_SECTION_PROTECTION
Definition: ntstatus.h:300
#define NO_HANDLE_CLOSE
#define SECTION_MAP_READ
Definition: compat.h:128
const ULONG TestStringSize
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1290
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by START_TEST().

◆ KmtInitTestFiles()

static VOID KmtInitTestFiles ( PHANDLE  ReadOnlyFile,
PHANDLE  WriteOnlyFile,
PHANDLE  ExecutableFile 
)
static

Definition at line 253 of file ZwCreateSection.c.

254 {
258 
259  //INIT THE READ-ONLY FILE
262  ok(*ReadOnlyFile != NULL, "Couldn't acquire READONLY handle\n");
263 
264  //INIT THE EXECUTABLE FILE
267  ok(*ExecutableFile != NULL, "Couldn't acquire EXECUTE handle\n");
268 
269  //INIT THE WRITE-ONLY FILE
270  //NB: this file is deleted at the end of basic behavior checks
274  ok(*WriteOnlyFile != NULL, "WriteOnlyFile is NULL\n");
275  if (!skip(*WriteOnlyFile != NULL, "No WriteOnlyFile\n"))
276  {
277  FileOffset.QuadPart = 0;
278  Status = ZwWriteFile(*WriteOnlyFile, NULL, NULL, NULL, &IoStatusBlock, (PVOID)TestString, TestStringSize, &FileOffset, NULL);
279  ok(Status == STATUS_SUCCESS || Status == STATUS_PENDING, "Status = 0x%08lx\n", Status);
280  Status = ZwWaitForSingleObject(*WriteOnlyFile, FALSE, NULL);
283  }
284 }
static OBJECT_ATTRIBUTES NtdllObject
EH_STD::basic_string< char, EH_STD::char_traits< char >, eh_allocator(char) > TestString
Definition: test_string.cpp:30
LONG NTSTATUS
Definition: precomp.h:26
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
static OBJECT_ATTRIBUTES CalcFileObject
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
const ULONG TestStringSize
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define ok(value,...)
Definition: atltest.h:57
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_CREATED
Definition: nt_native.h:770
#define skip(...)
Definition: atltest.h:64
static OBJECT_ATTRIBUTES KmtestFileObject
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define ok_eq_hex(value, expected)
#define GENERIC_EXECUTE
Definition: nt_native.h:91
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by START_TEST().

◆ SimpleErrorChecks()

static VOID SimpleErrorChecks ( HANDLE  FileHandleReadOnly,
HANDLE  FileHandleWriteOnly,
HANDLE  FileHandleExecuteOnly 
)
static

Definition at line 288 of file ZwCreateSection.c.

289 {
291  HANDLE Section = NULL;
292  OBJECT_ATTRIBUTES ObjectAttributesReadOnly;
293  OBJECT_ATTRIBUTES ObjectAttributesWriteOnly;
294  OBJECT_ATTRIBUTES InvalidObjectAttributes;
296  FILE_STANDARD_INFORMATION FileStandardInfo;
298  UNICODE_STRING SectReadOnly = RTL_CONSTANT_STRING(L"\\BaseNamedObjects\\KmtTestReadSect");
299  UNICODE_STRING SectWriteOnly = RTL_CONSTANT_STRING(L"\\BaseNamedObjects\\KmtTestWriteSect");
300  UNICODE_STRING InvalidObjectString = RTL_CONSTANT_STRING(L"THIS/IS/INVALID");
301 
302  MaximumSize.QuadPart = TestStringSize;
303 
304  InitializeObjectAttributes(&ObjectAttributesReadOnly, &SectReadOnly, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
305  InitializeObjectAttributes(&ObjectAttributesWriteOnly, &SectWriteOnly, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
306  InitializeObjectAttributes(&InvalidObjectAttributes, &InvalidObjectString, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
307 
309  //PAGE FILE BACKED SECTION
310  //DESIRED ACCESS TESTS
314 
315  //OBJECT ATTRIBUTES
318 
319  //MAXIMUM SIZE
320  MaximumSize.QuadPart = -1;
322 
323  MaximumSize.QuadPart = 0;
325 
326  //division by zero in ROS
327  if (!skip(SharedUserData->LargePageMinimum > 0, "LargePageMinimum is 0\n"))
328  {
329  MaximumSize.QuadPart = (_4mb / SharedUserData->LargePageMinimum) * SharedUserData->LargePageMinimum; //4mb
331  }
332 
333  MaximumSize.QuadPart = TestStringSize;
334 
335  //SECTION PAGE PROTECTION
345 
346  //ALLOCATION ATTRIBUTES
359 
361  //NORMAL FILE-BACKED SECTION
362 
363  //DESIRED ACCESS TESTS
364  CREATE_SECTION(Section, SECTION_ALL_ACCESS, &ObjectAttributesReadOnly, MaximumSize, PAGE_READONLY, SEC_COMMIT, FileHandleReadOnly, STATUS_SUCCESS, STATUS_SUCCESS);
365  CREATE_SECTION(Section, SECTION_ALL_ACCESS, &ObjectAttributesWriteOnly, MaximumSize, PAGE_WRITECOPY, SEC_COMMIT, FileHandleWriteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
366  CREATE_SECTION(Section, SECTION_MAP_WRITE, &ObjectAttributesReadOnly, MaximumSize, PAGE_READONLY, SEC_COMMIT, FileHandleReadOnly, STATUS_SUCCESS, STATUS_SUCCESS);
367  CREATE_SECTION(Section, SECTION_MAP_READ, &ObjectAttributesWriteOnly, MaximumSize, PAGE_WRITECOPY, SEC_COMMIT, FileHandleWriteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
368 
369  //Object Attributes
371  CREATE_SECTION(Section, SECTION_ALL_ACCESS, &InvalidObjectAttributes, MaximumSize, PAGE_READONLY, SEC_COMMIT, FileHandleReadOnly, STATUS_OBJECT_PATH_SYNTAX_BAD, IGNORE);
372 
373  //MAXIMUM SIZE
374  MaximumSize.QuadPart = TestStringSize - 100;
376 
377  MaximumSize.QuadPart = -1;
379 
380  MaximumSize.QuadPart = TestStringSize + 1;
382 
383  MaximumSize.QuadPart = 0;
385 
386  //SECTION PAGE PROTECTION
396 
397  //allocation type
410 
412  //EXECUTABLE IMAGE
413  CREATE_SECTION(Section, SECTION_MAP_READ, &ObjectAttributesWriteOnly, MaximumSize, PAGE_WRITECOPY, SEC_IMAGE, FileHandleExecuteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
414  CREATE_SECTION(Section, SECTION_MAP_EXECUTE, &ObjectAttributesWriteOnly, MaximumSize, PAGE_WRITECOPY, SEC_IMAGE, FileHandleExecuteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
415 
416  //DESIRED ACCESS TESTS
417  CREATE_SECTION(Section, SECTION_ALL_ACCESS, &ObjectAttributesReadOnly, MaximumSize, PAGE_READONLY, SEC_COMMIT, FileHandleExecuteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
418  CREATE_SECTION(Section, SECTION_ALL_ACCESS, &ObjectAttributesWriteOnly, MaximumSize, PAGE_WRITECOPY, SEC_COMMIT, FileHandleExecuteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
419  CREATE_SECTION(Section, SECTION_MAP_WRITE, &ObjectAttributesReadOnly, MaximumSize, PAGE_READONLY, SEC_COMMIT, FileHandleExecuteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
420  CREATE_SECTION(Section, SECTION_MAP_READ, &ObjectAttributesWriteOnly, MaximumSize, PAGE_WRITECOPY, SEC_COMMIT, FileHandleExecuteOnly, STATUS_SUCCESS, STATUS_SUCCESS);
421 
422  //Object Attributes
424  CREATE_SECTION(Section, SECTION_ALL_ACCESS, &InvalidObjectAttributes, MaximumSize, PAGE_READONLY, SEC_COMMIT, FileHandleExecuteOnly, STATUS_OBJECT_PATH_SYNTAX_BAD, IGNORE);
425 
426  //MaximumSize
427  Status = ZwQueryInformationFile(FileHandleExecuteOnly, &IoStatusBlock, &FileStandardInfo, sizeof(FILE_STANDARD_INFORMATION), FileStandardInformation);
428  if (!skip(NT_SUCCESS(Status), "Cannot query file information\n"))
429  {
430  //as big as file
431  MaximumSize = FileStandardInfo.EndOfFile;
433 
434  //less than file
435  MaximumSize.QuadPart = FileStandardInfo.EndOfFile.QuadPart - 2;
437 
438  //larger than file
439  MaximumSize.QuadPart = FileStandardInfo.EndOfFile.QuadPart + 2;
441 
442  //0
443  MaximumSize.QuadPart = 0;
445 
446  //-1 (very big number)
447  MaximumSize.QuadPart = -1;
449  }
450 }
#define SEC_LARGE_PAGES
Definition: mmtypes.h:102
LONG NTSTATUS
Definition: precomp.h:26
#define SEC_NOCACHE
Definition: mmtypes.h:100
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define SEC_COMMIT
Definition: mmtypes.h:99
#define SEC_RESERVE
Definition: nt_native.h:1323
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:286
smooth NULL
Definition: ftsmooth.c:416
#define IGNORE
#define SECTION_MAP_WRITE
Definition: nt_native.h:1288
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:525
#define _4mb
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CREATE_SECTION(Handle, DesiredAccess, Attributes, Size, SectionPageProtection, AllocationAttributes, FileHandle, RetStatus, CloseRetStatus)
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define SharedUserData
static const WCHAR L[]
Definition: oid.c:1250
#define SECTION_MAP_READ
Definition: compat.h:128
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
const ULONG TestStringSize
Status
Definition: gdiplustypes.h:24
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:466
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define FileStandardInformation
Definition: propsheet.cpp:61
#define skip(...)
Definition: atltest.h:64
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1290
#define SEC_IMAGE
Definition: mmtypes.h:96
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define STATUS_OBJECT_PATH_SYNTAX_BAD
Definition: ntstatus.h:281
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:464
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( ZwCreateSection  )

Definition at line 494 of file ZwCreateSection.c.

495 {
496  HANDLE FileHandleReadOnly = NULL;
497  HANDLE FileHandleWriteOnly = NULL;
498  HANDLE FileHandleExecuteOnly = NULL;
499 
503 
504  KmtInitTestFiles(&FileHandleReadOnly, &FileHandleWriteOnly, &FileHandleExecuteOnly);
505 
506  if (!skip(FileHandleReadOnly && FileHandleWriteOnly && FileHandleExecuteOnly, "Missing one or more file handles\n"))
507  {
508  FileSectionViewPermissionCheck(FileHandleReadOnly, FileHandleWriteOnly, FileHandleExecuteOnly);
509  SimpleErrorChecks(FileHandleReadOnly, FileHandleWriteOnly, FileHandleExecuteOnly);
510  BasicBehaviorChecks(FileHandleWriteOnly);
511  }
512 
513  if (FileHandleReadOnly)
514  ZwClose(FileHandleReadOnly);
515 
516  if (FileHandleWriteOnly)
517  {
518  ZwClose(FileHandleWriteOnly);
520  }
521 
522  if (FileHandleExecuteOnly)
523  ZwClose(FileHandleExecuteOnly);
524 }
static OBJECT_ATTRIBUTES NtdllObject
NTSYSAPI NTSTATUS NTAPI ZwDeleteFile(_In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
static OBJECT_ATTRIBUTES CalcFileObject
static UNICODE_STRING CalcImgPath
static VOID SimpleErrorChecks(HANDLE FileHandleReadOnly, HANDLE FileHandleWriteOnly, HANDLE FileHandleExecuteOnly)
smooth NULL
Definition: ftsmooth.c:416
static VOID BasicBehaviorChecks(HANDLE FileHandle)
static UNICODE_STRING WritableFilePath
static VOID KmtInitTestFiles(PHANDLE ReadOnlyFile, PHANDLE WriteOnlyFile, PHANDLE ExecutableFile)
static VOID FileSectionViewPermissionCheck(HANDLE ReadOnlyFile, HANDLE WriteOnlyFile, HANDLE ExecutableFile)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define skip(...)
Definition: atltest.h:64
static OBJECT_ATTRIBUTES KmtestFileObject
static UNICODE_STRING FileReadOnlyPath
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Variable Documentation

◆ CalcFileObject

OBJECT_ATTRIBUTES CalcFileObject
static

Definition at line 20 of file ZwCreateSection.c.

Referenced by KmtInitTestFiles(), and START_TEST().

◆ CalcImgPath

UNICODE_STRING CalcImgPath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\calc.exe")
static

Definition at line 17 of file ZwCreateSection.c.

Referenced by START_TEST().

◆ FileReadOnlyPath

UNICODE_STRING FileReadOnlyPath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll")
static

Definition at line 15 of file ZwCreateSection.c.

Referenced by START_TEST().

◆ KmtestFileObject

OBJECT_ATTRIBUTES KmtestFileObject
static

Definition at line 19 of file ZwCreateSection.c.

Referenced by DriverEntry(), KmtInitTestFiles(), and START_TEST().

◆ NtdllObject

OBJECT_ATTRIBUTES NtdllObject
static

Definition at line 18 of file ZwCreateSection.c.

Referenced by KmtInitTestFiles(), and START_TEST().

◆ TestString

Definition at line 16 of file ZwAllocateVirtualMemory.c.

◆ TestStringSize

◆ WritableFilePath

UNICODE_STRING WritableFilePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\kmtest-MmSection.txt")
static

Definition at line 16 of file ZwCreateSection.c.

Referenced by START_TEST().