Skip to content

Commit 25a6fdf

Browse files
SergeGautherietkreuzer
authored andcommitted
[NTOS:MM] Convert some annotations to SAL2 and fix them
And add a specific ASSERT(SectionOffset) in MmMapViewOfSection().
1 parent 54c667c commit 25a6fdf

4 files changed

Lines changed: 75 additions & 63 deletions

File tree

‎ntoskrnl/mm/ARM3/section.c‎

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,17 +1150,18 @@ MiMapViewInSystemSpace(
11501150

11511151
static
11521152
NTSTATUS
1153-
MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
1154-
IN PEPROCESS Process,
1155-
IN PVOID *BaseAddress,
1156-
IN PLARGE_INTEGER SectionOffset,
1157-
IN PSIZE_T ViewSize,
1158-
IN PSECTION Section,
1159-
IN SECTION_INHERIT InheritDisposition,
1160-
IN ULONG ProtectionMask,
1161-
IN SIZE_T CommitSize,
1162-
IN ULONG_PTR ZeroBits,
1163-
IN ULONG AllocationType)
1153+
MiMapViewOfDataSection(
1154+
_In_ PCONTROL_AREA ControlArea,
1155+
_In_ PEPROCESS Process,
1156+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_opt_valid_ PVOID *BaseAddress,
1157+
_Inout_ PLARGE_INTEGER SectionOffset,
1158+
_Inout_ PSIZE_T ViewSize,
1159+
_In_ PSECTION Section,
1160+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
1161+
_In_ ULONG ProtectionMask,
1162+
_In_ SIZE_T CommitSize,
1163+
_In_ ULONG_PTR ZeroBits,
1164+
_In_ ULONG AllocationType)
11641165
{
11651166
PMMVAD_LONG Vad;
11661167
ULONG_PTR StartAddress;
@@ -2530,16 +2531,20 @@ MmCreateArm3Section(OUT PVOID *SectionObject,
25302531
*/
25312532
NTSTATUS
25322533
NTAPI
2533-
MmMapViewOfArm3Section(IN PVOID SectionObject,
2534-
IN PEPROCESS Process,
2535-
IN OUT PVOID *BaseAddress,
2536-
IN ULONG_PTR ZeroBits,
2537-
IN SIZE_T CommitSize,
2538-
IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
2539-
IN OUT PSIZE_T ViewSize,
2540-
IN SECTION_INHERIT InheritDisposition,
2541-
IN ULONG AllocationType,
2542-
IN ULONG Protect)
2534+
MmMapViewOfArm3Section(
2535+
_In_ PVOID SectionObject,
2536+
_In_ PEPROCESS Process,
2537+
_Outptr_result_bytebuffer_(*ViewSize)
2538+
_When_(*ViewSize != 0, _Pre_opt_valid_)
2539+
_When_(*ViewSize == 0, _Pre_valid_)
2540+
PVOID *BaseAddress,
2541+
_In_ ULONG_PTR ZeroBits,
2542+
_In_ SIZE_T CommitSize,
2543+
_Inout_ PLARGE_INTEGER SectionOffset,
2544+
_Inout_ PSIZE_T ViewSize,
2545+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
2546+
_In_ ULONG AllocationType,
2547+
_In_ ULONG Protect)
25432548
{
25442549
KAPC_STATE ApcState;
25452550
BOOLEAN Attached = FALSE;
@@ -3256,16 +3261,17 @@ NtOpenSection(OUT PHANDLE SectionHandle,
32563261

32573262
NTSTATUS
32583263
NTAPI
3259-
NtMapViewOfSection(IN HANDLE SectionHandle,
3260-
IN HANDLE ProcessHandle,
3261-
IN OUT PVOID* BaseAddress,
3262-
IN ULONG_PTR ZeroBits,
3263-
IN SIZE_T CommitSize,
3264-
IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
3265-
IN OUT PSIZE_T ViewSize,
3266-
IN SECTION_INHERIT InheritDisposition,
3267-
IN ULONG AllocationType,
3268-
IN ULONG Protect)
3264+
NtMapViewOfSection(
3265+
_In_ HANDLE SectionHandle,
3266+
_In_ HANDLE ProcessHandle,
3267+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_valid_ PVOID *BaseAddress,
3268+
_In_ ULONG_PTR ZeroBits,
3269+
_In_ SIZE_T CommitSize,
3270+
_Inout_opt_ PLARGE_INTEGER SectionOffset,
3271+
_Inout_ PSIZE_T ViewSize,
3272+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
3273+
_In_ ULONG AllocationType,
3274+
_In_ ULONG Win32Protect)
32693275
{
32703276
PVOID SafeBaseAddress;
32713277
LARGE_INTEGER SafeSectionOffset;
@@ -3299,7 +3305,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
32993305
}
33003306

33013307
/* Convert the protection mask, and validate it */
3302-
ProtectionMask = MiMakeProtectionMask(Protect);
3308+
ProtectionMask = MiMakeProtectionMask(Win32Protect);
33033309
if (ProtectionMask == MM_INVALID_PROTECTION)
33043310
{
33053311
DPRINT1("Invalid page protection\n");
@@ -3442,7 +3448,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
34423448
&SafeViewSize,
34433449
InheritDisposition,
34443450
AllocationType,
3445-
Protect);
3451+
Win32Protect);
34463452

34473453
/* Return data only on success */
34483454
if (NT_SUCCESS(Status))

‎ntoskrnl/mm/section.c‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,20 @@ MmCreateArm3Section(OUT PVOID *SectionObject,
142142

143143
NTSTATUS
144144
NTAPI
145-
MmMapViewOfArm3Section(IN PVOID SectionObject,
146-
IN PEPROCESS Process,
147-
IN OUT PVOID *BaseAddress,
148-
IN ULONG_PTR ZeroBits,
149-
IN SIZE_T CommitSize,
150-
IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
151-
IN OUT PSIZE_T ViewSize,
152-
IN SECTION_INHERIT InheritDisposition,
153-
IN ULONG AllocationType,
154-
IN ULONG Protect);
145+
MmMapViewOfArm3Section(
146+
_In_ PVOID SectionObject,
147+
_In_ PEPROCESS Process,
148+
_Outptr_result_bytebuffer_(*ViewSize)
149+
_When_(*ViewSize != 0, _Pre_opt_valid_)
150+
_When_(*ViewSize == 0, _Pre_valid_)
151+
PVOID *BaseAddress,
152+
_In_ ULONG_PTR ZeroBits,
153+
_In_ SIZE_T CommitSize,
154+
_Inout_ PLARGE_INTEGER SectionOffset,
155+
_Inout_ PSIZE_T ViewSize,
156+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
157+
_In_ ULONG AllocationType,
158+
_In_ ULONG Protect);
155159

156160
//
157161
// PeFmtCreateSection depends on the following:
@@ -4024,16 +4028,17 @@ NtQuerySection(
40244028
* @implemented
40254029
*/
40264030
NTSTATUS NTAPI
4027-
MmMapViewOfSection(IN PVOID SectionObject,
4028-
IN PEPROCESS Process,
4029-
IN OUT PVOID *BaseAddress,
4030-
IN ULONG_PTR ZeroBits,
4031-
IN SIZE_T CommitSize,
4032-
IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
4033-
IN OUT PSIZE_T ViewSize,
4034-
IN SECTION_INHERIT InheritDisposition,
4035-
IN ULONG AllocationType,
4036-
IN ULONG Protect)
4031+
MmMapViewOfSection(
4032+
_In_ PVOID SectionObject,
4033+
_In_ PEPROCESS Process,
4034+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_opt_valid_ PVOID *BaseAddress,
4035+
_In_ ULONG_PTR ZeroBits,
4036+
_In_ SIZE_T CommitSize,
4037+
_Inout_opt_ PLARGE_INTEGER SectionOffset,
4038+
_Inout_ PSIZE_T ViewSize,
4039+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
4040+
_In_ ULONG AllocationType,
4041+
_In_ ULONG Protect)
40374042
{
40384043
PSECTION Section;
40394044
PMMSUPPORT AddressSpace;
@@ -4045,6 +4050,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
40454050
if (MiIsRosSectionObject(SectionObject) == FALSE)
40464051
{
40474052
DPRINT("Mapping ARM3 section into %s\n", Process->ImageFileName);
4053+
ASSERT(SectionOffset != NULL);
40484054
return MmMapViewOfArm3Section(SectionObject,
40494055
Process,
40504056
BaseAddress,

‎sdk/include/ndk/mmfuncs.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ NTAPI
4848
MmMapViewOfSection(
4949
_In_ PVOID SectionObject,
5050
_In_ PEPROCESS Process,
51-
_Inout_ PVOID *BaseAddress,
51+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_opt_valid_ PVOID *BaseAddress,
5252
_In_ ULONG_PTR ZeroBits,
5353
_In_ SIZE_T CommitSize,
5454
_Inout_opt_ PLARGE_INTEGER SectionOffset,
5555
_Inout_ PSIZE_T ViewSize,
56-
_In_ SECTION_INHERIT InheritDisposition,
56+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
5757
_In_ ULONG AllocationType,
5858
_In_ ULONG Protect
5959
);
@@ -217,14 +217,14 @@ NTAPI
217217
NtMapViewOfSection(
218218
_In_ HANDLE SectionHandle,
219219
_In_ HANDLE ProcessHandle,
220-
_Inout_ PVOID *BaseAddress,
220+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_valid_ PVOID *BaseAddress,
221221
_In_ ULONG_PTR ZeroBits,
222222
_In_ SIZE_T CommitSize,
223223
_Inout_opt_ PLARGE_INTEGER SectionOffset,
224224
_Inout_ PSIZE_T ViewSize,
225-
_In_ SECTION_INHERIT InheritDisposition,
225+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
226226
_In_ ULONG AllocationType,
227-
_In_ ULONG AccessProtection
227+
_In_ ULONG Win32Protect
228228
);
229229

230230
NTSYSCALLAPI
@@ -401,12 +401,12 @@ NTAPI
401401
ZwMapViewOfSection(
402402
_In_ HANDLE SectionHandle,
403403
_In_ HANDLE ProcessHandle,
404-
_Outptr_result_bytebuffer_(*ViewSize) PVOID *BaseAddress,
404+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_valid_ PVOID *BaseAddress,
405405
_In_ ULONG_PTR ZeroBits,
406406
_In_ SIZE_T CommitSize,
407407
_Inout_opt_ PLARGE_INTEGER SectionOffset,
408408
_Inout_ PSIZE_T ViewSize,
409-
_In_ SECTION_INHERIT InheritDisposition,
409+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
410410
_In_ ULONG AllocationType,
411411
_In_ ULONG Win32Protect
412412
);

‎sdk/include/xdk/zwfuncs.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ NTAPI
211211
ZwMapViewOfSection(
212212
_In_ HANDLE SectionHandle,
213213
_In_ HANDLE ProcessHandle,
214-
_Outptr_result_bytebuffer_(*ViewSize) PVOID *BaseAddress,
214+
_Outptr_result_bytebuffer_(*ViewSize) _Pre_valid_ PVOID *BaseAddress,
215215
_In_ ULONG_PTR ZeroBits,
216216
_In_ SIZE_T CommitSize,
217217
_Inout_opt_ PLARGE_INTEGER SectionOffset,
218218
_Inout_ PSIZE_T ViewSize,
219-
_In_ SECTION_INHERIT InheritDisposition,
219+
_In_range_(ViewShare, ViewUnmap) SECTION_INHERIT InheritDisposition,
220220
_In_ ULONG AllocationType,
221-
_In_ ULONG Protect);
221+
_In_ ULONG Win32Protect);
222222

223223
_IRQL_requires_max_(PASSIVE_LEVEL)
224224
NTSYSAPI

0 commit comments

Comments
 (0)