[NTOS:EX] Improve NtSystemDebugControl

- Add SEH probing for user buffer
- Mark some classes as i386 only
- Explicitly return STATUS_NOT_IMPLEMENTED on disabled classes (must use KdSystemDebugControl instead)
- Explicitly return STATUS_NOT_IMPLEMENTED on not implemented classes
- Return STATUS_INVALID_INFO_CLASS on all other classes
This commit is contained in:
Hervé Poussineau 2024-09-14 08:41:20 +02:00 committed by Hermès Bélusca-Maïto
parent 0f36ef3392
commit 9e7c3770e3
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -214,14 +214,40 @@ NtSystemDebugControl(
_In_ ULONG OutputBufferLength, _In_ ULONG OutputBufferLength,
_Out_opt_ PULONG ReturnLength) _Out_opt_ PULONG ReturnLength)
{ {
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
ULONG Length = 0;
NTSTATUS Status;
_SEH2_TRY
{
if (PreviousMode != KernelMode)
{
if (InputBufferLength)
ProbeForRead(InputBuffer, InputBufferLength, sizeof(ULONG));
if (OutputBufferLength)
ProbeForWrite(OutputBuffer, OutputBufferLength, sizeof(ULONG));
if (ReturnLength)
ProbeForWriteUlong(ReturnLength);
}
switch (Command) switch (Command)
{ {
case SysDbgQueryModuleInformation: case SysDbgQueryModuleInformation:
/* Removed in WinNT4 */
Status = STATUS_INVALID_INFO_CLASS;
break;
#ifdef _M_IX86
case SysDbgQueryTraceInformation: case SysDbgQueryTraceInformation:
case SysDbgSetTracepoint: case SysDbgSetTracepoint:
case SysDbgSetSpecialCall: case SysDbgSetSpecialCall:
case SysDbgClearSpecialCalls: case SysDbgClearSpecialCalls:
case SysDbgQuerySpecialCalls: case SysDbgQuerySpecialCalls:
UNIMPLEMENTED;
Status = STATUS_NOT_IMPLEMENTED;
break;
#endif
case SysDbgQueryVersion: case SysDbgQueryVersion:
case SysDbgReadVirtual: case SysDbgReadVirtual:
case SysDbgWriteVirtual: case SysDbgWriteVirtual:
@ -236,8 +262,10 @@ NtSystemDebugControl(
case SysDbgReadBusData: case SysDbgReadBusData:
case SysDbgWriteBusData: case SysDbgWriteBusData:
case SysDbgCheckLowMemory: case SysDbgCheckLowMemory:
case SysDbgGetTriageDump: /* Those are implemented in KdSystemDebugControl */
return STATUS_NOT_IMPLEMENTED; Status = STATUS_NOT_IMPLEMENTED;
break;
case SysDbgBreakPoint: case SysDbgBreakPoint:
case SysDbgEnableKernelDebugger: case SysDbgEnableKernelDebugger:
case SysDbgDisableKernelDebugger: case SysDbgDisableKernelDebugger:
@ -247,15 +275,26 @@ NtSystemDebugControl(
case SysDbgSetPrintBufferSize: case SysDbgSetPrintBufferSize:
case SysDbgGetKdUmExceptionEnable: case SysDbgGetKdUmExceptionEnable:
case SysDbgSetKdUmExceptionEnable: case SysDbgSetKdUmExceptionEnable:
case SysDbgGetTriageDump:
case SysDbgGetKdBlockEnable: case SysDbgGetKdBlockEnable:
case SysDbgSetKdBlockEnable: case SysDbgSetKdBlockEnable:
return KdSystemDebugControl( UNIMPLEMENTED;
Command, Status = STATUS_NOT_IMPLEMENTED;
InputBuffer, InputBufferLength, break;
OutputBuffer, OutputBufferLength,
ReturnLength, KeGetPreviousMode());
default: default:
return STATUS_INVALID_INFO_CLASS; Status = STATUS_INVALID_INFO_CLASS;
break;
} }
if (ReturnLength)
*ReturnLength = Length;
_SEH2_YIELD(return Status);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
_SEH2_YIELD(return _SEH2_GetExceptionCode());
}
_SEH2_END;
} }