Skip to content

Commit 9e7c377

Browse files
hpoussinHBelusca
authored andcommitted
[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
1 parent 0f36ef3 commit 9e7c377

File tree

1 file changed

+80
-41
lines changed

1 file changed

+80
-41
lines changed

ntoskrnl/ex/dbgctrl.c

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -214,48 +214,87 @@ NtSystemDebugControl(
214214
_In_ ULONG OutputBufferLength,
215215
_Out_opt_ PULONG ReturnLength)
216216
{
217-
switch (Command)
217+
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
218+
ULONG Length = 0;
219+
NTSTATUS Status;
220+
221+
_SEH2_TRY
218222
{
219-
case SysDbgQueryModuleInformation:
220-
case SysDbgQueryTraceInformation:
221-
case SysDbgSetTracepoint:
222-
case SysDbgSetSpecialCall:
223-
case SysDbgClearSpecialCalls:
224-
case SysDbgQuerySpecialCalls:
225-
case SysDbgQueryVersion:
226-
case SysDbgReadVirtual:
227-
case SysDbgWriteVirtual:
228-
case SysDbgReadPhysical:
229-
case SysDbgWritePhysical:
230-
case SysDbgReadControlSpace:
231-
case SysDbgWriteControlSpace:
232-
case SysDbgReadIoSpace:
233-
case SysDbgWriteIoSpace:
234-
case SysDbgReadMsr:
235-
case SysDbgWriteMsr:
236-
case SysDbgReadBusData:
237-
case SysDbgWriteBusData:
238-
case SysDbgCheckLowMemory:
239-
case SysDbgGetTriageDump:
240-
return STATUS_NOT_IMPLEMENTED;
241-
case SysDbgBreakPoint:
242-
case SysDbgEnableKernelDebugger:
243-
case SysDbgDisableKernelDebugger:
244-
case SysDbgGetAutoKdEnable:
245-
case SysDbgSetAutoKdEnable:
246-
case SysDbgGetPrintBufferSize:
247-
case SysDbgSetPrintBufferSize:
248-
case SysDbgGetKdUmExceptionEnable:
249-
case SysDbgSetKdUmExceptionEnable:
223+
if (PreviousMode != KernelMode)
224+
{
225+
if (InputBufferLength)
226+
ProbeForRead(InputBuffer, InputBufferLength, sizeof(ULONG));
227+
if (OutputBufferLength)
228+
ProbeForWrite(OutputBuffer, OutputBufferLength, sizeof(ULONG));
229+
if (ReturnLength)
230+
ProbeForWriteUlong(ReturnLength);
231+
}
232+
233+
switch (Command)
234+
{
235+
case SysDbgQueryModuleInformation:
236+
/* Removed in WinNT4 */
237+
Status = STATUS_INVALID_INFO_CLASS;
238+
break;
239+
240+
#ifdef _M_IX86
241+
case SysDbgQueryTraceInformation:
242+
case SysDbgSetTracepoint:
243+
case SysDbgSetSpecialCall:
244+
case SysDbgClearSpecialCalls:
245+
case SysDbgQuerySpecialCalls:
246+
UNIMPLEMENTED;
247+
Status = STATUS_NOT_IMPLEMENTED;
248+
break;
249+
#endif
250+
251+
case SysDbgQueryVersion:
252+
case SysDbgReadVirtual:
253+
case SysDbgWriteVirtual:
254+
case SysDbgReadPhysical:
255+
case SysDbgWritePhysical:
256+
case SysDbgReadControlSpace:
257+
case SysDbgWriteControlSpace:
258+
case SysDbgReadIoSpace:
259+
case SysDbgWriteIoSpace:
260+
case SysDbgReadMsr:
261+
case SysDbgWriteMsr:
262+
case SysDbgReadBusData:
263+
case SysDbgWriteBusData:
264+
case SysDbgCheckLowMemory:
265+
/* Those are implemented in KdSystemDebugControl */
266+
Status = STATUS_NOT_IMPLEMENTED;
267+
break;
268+
269+
case SysDbgBreakPoint:
270+
case SysDbgEnableKernelDebugger:
271+
case SysDbgDisableKernelDebugger:
272+
case SysDbgGetAutoKdEnable:
273+
case SysDbgSetAutoKdEnable:
274+
case SysDbgGetPrintBufferSize:
275+
case SysDbgSetPrintBufferSize:
276+
case SysDbgGetKdUmExceptionEnable:
277+
case SysDbgSetKdUmExceptionEnable:
278+
case SysDbgGetTriageDump:
279+
case SysDbgGetKdBlockEnable:
280+
case SysDbgSetKdBlockEnable:
281+
UNIMPLEMENTED;
282+
Status = STATUS_NOT_IMPLEMENTED;
283+
break;
250284

251-
case SysDbgGetKdBlockEnable:
252-
case SysDbgSetKdBlockEnable:
253-
return KdSystemDebugControl(
254-
Command,
255-
InputBuffer, InputBufferLength,
256-
OutputBuffer, OutputBufferLength,
257-
ReturnLength, KeGetPreviousMode());
258-
default:
259-
return STATUS_INVALID_INFO_CLASS;
285+
default:
286+
Status = STATUS_INVALID_INFO_CLASS;
287+
break;
288+
}
289+
290+
if (ReturnLength)
291+
*ReturnLength = Length;
292+
293+
_SEH2_YIELD(return Status);
294+
}
295+
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
296+
{
297+
_SEH2_YIELD(return _SEH2_GetExceptionCode());
260298
}
299+
_SEH2_END;
261300
}

0 commit comments

Comments
 (0)