Skip to content

Commit 125f94d

Browse files
committed
[NTOS:EX] Check whether the boot-time drivers are safe to use on MP systems (reactos#7744)
Invoke the MmVerifyImageIsOkForMpUse() helper. If the boot-time driver only supports a uniprocessor system, bugcheck with UP_DRIVER_ON_MP_SYSTEM. https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/bug-check-0x92--up-driver-on-mp-system Note that we don't do this check very soon at boot time (e.g. in MiReloadBootLoadedDrivers or MiInitializeLoadedModuleList), but only after loading the drivers' debug symbols (if any). The reason is simply to ease debugging in case we bugcheck: this allows having the debugger set up with the symbols for this driver. For automatic and manual driver loading, MmVerifyImageIsOkForMpUse() is invoked by MmCheckSystemImage() but in this case, there is graceful failure and no bugcheck.
1 parent 4750cbe commit 125f94d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

ntoskrnl/ex/init.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,16 @@ ExpLoadBootSymbols(
863863
LdrEntry->DllBase,
864864
(ULONG_PTR)PsGetCurrentProcessId());
865865
}
866+
867+
#ifdef CONFIG_SMP
868+
/* Check that the image is safe to use if we have more than one CPU */
869+
if (!MmVerifyImageIsOkForMpUse(LdrEntry->DllBase))
870+
{
871+
KeBugCheckEx(UP_DRIVER_ON_MP_SYSTEM,
872+
(ULONG_PTR)LdrEntry->DllBase,
873+
0, 0, 0);
874+
}
875+
#endif // CONFIG_SMP
866876
}
867877
}
868878

ntoskrnl/include/internal/mm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,13 @@ MmUnloadSystemImage(
16491649
IN PVOID ImageHandle
16501650
);
16511651

1652+
#ifdef CONFIG_SMP
1653+
BOOLEAN
1654+
NTAPI
1655+
MmVerifyImageIsOkForMpUse(
1656+
_In_ PVOID BaseAddress);
1657+
#endif // CONFIG_SMP
1658+
16521659
NTSTATUS
16531660
NTAPI
16541661
MmCheckSystemImage(

ntoskrnl/mm/ARM3/sysldr.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,12 +2716,13 @@ MiEnablePagingOfDriver(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
27162716
if (PointerPte) MiSetPagingOfDriver(PointerPte, LastPte);
27172717
}
27182718

2719+
#ifdef CONFIG_SMP
27192720
FORCEINLINE
27202721
BOOLEAN
27212722
MiVerifyImageIsOkForMpUse(
27222723
_In_ PIMAGE_NT_HEADERS NtHeaders)
27232724
{
2724-
/* Fail if we have 2+ CPUs, but the image is only safe for UP */
2725+
/* Fail if we have more than one CPU, but the image is only safe for UP */
27252726
if ((KeNumberProcessors > 1) &&
27262727
(NtHeaders->FileHeader.Characteristics & IMAGE_FILE_UP_SYSTEM_ONLY))
27272728
{
@@ -2731,8 +2732,6 @@ MiVerifyImageIsOkForMpUse(
27312732
return TRUE;
27322733
}
27332734

2734-
// TODO: Use this function to verify that the loaded boot drivers
2735-
// (in ExpLoadBootSymbols) are compatible with MP.
27362735
BOOLEAN
27372736
NTAPI
27382737
MmVerifyImageIsOkForMpUse(
@@ -2741,13 +2740,14 @@ MmVerifyImageIsOkForMpUse(
27412740
PIMAGE_NT_HEADERS NtHeaders;
27422741
PAGED_CODE();
27432742

2744-
/* Get the NT headers. If none, suppose the image
2745-
* is safe to use, otherwise invoke the helper. */
2743+
/* Get the NT headers. If none, suppose the image is safe
2744+
* to use on an MP system, otherwise invoke the helper. */
27462745
NtHeaders = RtlImageNtHeader(BaseAddress);
27472746
if (!NtHeaders)
27482747
return TRUE;
27492748
return MiVerifyImageIsOkForMpUse(NtHeaders);
27502749
}
2750+
#endif // CONFIG_SMP
27512751

27522752
NTSTATUS
27532753
NTAPI
@@ -2847,7 +2847,7 @@ MmCheckSystemImage(
28472847
}
28482848

28492849
#ifdef CONFIG_SMP
2850-
/* Check that it's a valid SMP image if we have more than one CPU */
2850+
/* Check that the image is safe to use if we have more than one CPU */
28512851
if (!MiVerifyImageIsOkForMpUse(NtHeaders))
28522852
{
28532853
/* Otherwise it's not the right image */

0 commit comments

Comments
 (0)