Skip to content

File tree

2 files changed

+91
-32
lines changed

2 files changed

+91
-32
lines changed

ntoskrnl/ex/dbgctrl.c

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -146,54 +146,75 @@ ExpDebuggerWorker(
146146
}
147147
}
148148

149-
/*++
150-
* @name NtSystemDebugControl
151-
* @implemented
149+
/**
150+
* @brief
151+
* Perform various queries to the kernel debugger.
152152
*
153-
* Perform various queries to debugger.
154-
* This API is subject to test-case creation to further evaluate its
155-
* abilities (if needed to at all)
153+
* @param[in] Command
154+
* A SYSDBG_COMMAND value describing the kernel debugger command to perform.
156155
*
157-
* See: http://www.osronline.com/showthread.cfm?link=93915
158-
* http://void.ru/files/Ntexapi.h
159-
* http://www.codeguru.com/code/legacy/system/ntexapi.zip
160-
* http://www.securityfocus.com/bid/9694
156+
* @param[in] InputBuffer
157+
* Pointer to a user-provided input command-specific buffer, whose length
158+
* is given by InputBufferLength.
161159
*
162-
* @param ControlCode
163-
* Description of the parameter. Wrapped to more lines on ~70th
164-
* column.
160+
* @param[in] InputBufferLength
161+
* The size (in bytes) of the buffer pointed by InputBuffer.
165162
*
166-
* @param InputBuffer
167-
* FILLME
163+
* @param[out] OutputBuffer
164+
* Pointer to a user-provided command-specific output buffer, whose length
165+
* is given by OutputBufferLength.
168166
*
169-
* @param InputBufferLength
170-
* FILLME
167+
* @param[in] OutputBufferLength
168+
* The size (in bytes) of the buffer pointed by OutputBuffer.
171169
*
172-
* @param OutputBuffer
173-
* FILLME
170+
* @param[out] ReturnLength
171+
* Optional pointer to a ULONG variable that receives the actual length of
172+
* data written written in the output buffer. It is always zero, except for
173+
* the live dump commands where an actual non-zero length is returned.
174174
*
175-
* @param OutputBufferLength
176-
* FILLME
175+
* @return
176+
* STATUS_SUCCESS in case of success, or a proper error code otherwise.
177177
*
178-
* @param ReturnLength
179-
* FILLME
178+
* @remarks
180179
*
181-
* @return STATUS_SUCCESS in case of success, proper error code otherwise
180+
* - The caller must have SeDebugPrivilege, otherwise the function fails
181+
* with STATUS_ACCESS_DENIED.
182182
*
183-
* @remarks None
183+
* - Only the live dump commands: SysDbgGetTriageDump, and SysDbgGetLiveKernelDump
184+
* (Win8.1+) are available even if the debugger is disabled or absent.
184185
*
185-
*--*/
186+
* - The following system-critical commands are not accessible anymore
187+
* for user-mode usage with this API on NT 5.2+ (Windows 2003 SP1 and later)
188+
* systems:
189+
*
190+
* SysDbgQueryVersion,
191+
* SysDbgReadVirtual and SysDbgWriteVirtual,
192+
* SysDbgReadPhysical and SysDbgWritePhysical,
193+
* SysDbgReadControlSpace and SysDbgWriteControlSpace,
194+
* SysDbgReadIoSpace and SysDbgWriteIoSpace,
195+
* SysDbgReadMsr and SysDbgWriteMsr,
196+
* SysDbgReadBusData and SysDbgWriteBusData,
197+
* SysDbgCheckLowMemory.
198+
*
199+
* For these, NtSystemDebugControl() will return STATUS_NOT_IMPLEMENTED.
200+
* They are now available from kernel-mode only with KdSystemDebugControl().
201+
*
202+
* @note
203+
* See: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2339
204+
*
205+
* @see KdSystemDebugControl()
206+
**/
186207
NTSTATUS
187208
NTAPI
188209
NtSystemDebugControl(
189-
_In_ SYSDBG_COMMAND ControlCode,
210+
_In_ SYSDBG_COMMAND Command,
190211
_In_reads_bytes_(InputBufferLength) PVOID InputBuffer,
191212
_In_ ULONG InputBufferLength,
192213
_Out_writes_bytes_(OutputBufferLength) PVOID OutputBuffer,
193214
_In_ ULONG OutputBufferLength,
194215
_Out_opt_ PULONG ReturnLength)
195216
{
196-
switch (ControlCode)
217+
switch (Command)
197218
{
198219
case SysDbgQueryModuleInformation:
199220
case SysDbgQueryTraceInformation:
@@ -226,10 +247,11 @@ NtSystemDebugControl(
226247
case SysDbgSetPrintBufferSize:
227248
case SysDbgGetKdUmExceptionEnable:
228249
case SysDbgSetKdUmExceptionEnable:
250+
229251
case SysDbgGetKdBlockEnable:
230252
case SysDbgSetKdBlockEnable:
231253
return KdSystemDebugControl(
232-
ControlCode,
254+
Command,
233255
InputBuffer, InputBufferLength,
234256
OutputBuffer, OutputBufferLength,
235257
ReturnLength, KeGetPreviousMode());

ntoskrnl/kd64/kdapi.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,9 +2171,46 @@ KdDisableDebugger(VOID)
21712171
return KdDisableDebuggerWithLock(TRUE);
21722172
}
21732173

2174-
/*
2175-
* @unimplemented
2176-
*/
2174+
/**
2175+
* @brief
2176+
* Perform various queries to the kernel debugger.
2177+
*
2178+
* @param[in] Command
2179+
* A SYSDBG_COMMAND value describing the kernel debugger command to perform.
2180+
*
2181+
* @param[in] InputBuffer
2182+
* Pointer to a user-provided input command-specific buffer, whose length
2183+
* is given by InputBufferLength.
2184+
*
2185+
* @param[in] InputBufferLength
2186+
* The size (in bytes) of the buffer pointed by InputBuffer.
2187+
*
2188+
* @param[out] OutputBuffer
2189+
* Pointer to a user-provided command-specific output buffer, whose length
2190+
* is given by OutputBufferLength.
2191+
*
2192+
* @param[in] OutputBufferLength
2193+
* The size (in bytes) of the buffer pointed by OutputBuffer.
2194+
*
2195+
* @param[out] ReturnLength
2196+
* Optional pointer to a ULONG variable that receives the actual length of
2197+
* data written written in the output buffer. It is always zero, except for
2198+
* the live dump commands where an actual non-zero length is returned.
2199+
*
2200+
* @param[in] PreviousMode
2201+
* The processor mode (KernelMode or UserMode) in which the command is being executed.
2202+
*
2203+
* @return
2204+
* STATUS_SUCCESS in case of success, or a proper error code otherwise.
2205+
*
2206+
* @remarks
2207+
* - This is a kernel-mode function, accessible only by kernel-mode drivers.
2208+
*
2209+
* @note
2210+
* See: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2339
2211+
*
2212+
* @see NtSystemDebugControl()
2213+
**/
21772214
NTSTATUS
21782215
NTAPI
21792216
KdSystemDebugControl(

0 commit comments

Comments
 (0)