Bitdefender Hypervisor Memory Introspection
exceptions_kern.c File Reference

Kernel mode exceptions. More...

#include "exceptions.h"
#include "guests.h"
#include "lixstack.h"
#include "winpe.h"
#include "winstack.h"
#include "lixksym.h"

Go to the source code of this file.

Functions

static int IntExceptPrintLixKmDrvInfo (KERNEL_DRIVER *Driver, char *Header, char *Line, int MaxLength, DWORD NameAlignment)
 Print the information about the provided KERNEL_DRIVER (Linux guest). More...
 
int IntExceptPrintWinKmModInfo (KERNEL_DRIVER *Module, char *Header, char *Line, int MaxLength, DWORD NameAlignment)
 Print the information about the provided KERNEL_DRIVER (windows guest). More...
 
static int IntExceptPrintMsrInfo (EXCEPTION_VICTIM_ZONE *Victim, char *Header, char *Line, int MaxLength)
 Print the information about the modified MSR. More...
 
static int IntExceptPrintCrInfo (EXCEPTION_VICTIM_ZONE *Victim, char *Header, char *Line, int MaxLength)
 Print the information about the modified CR. More...
 
static int IntExceptPrintIdtInfo (EXCEPTION_VICTIM_ZONE *Victim, char *Header, char *Line, int MaxLength)
 Print the information about the modified IDT entry. More...
 
static int IntExceptPrintDtrInfo (EXCEPTION_VICTIM_ZONE *Victim, char *Header, char *Line, int MaxLength)
 Print the information about the modified IDTR/GDTR. More...
 
static void IntExceptKernelLogLinuxInformation (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_KM_ORIGINATOR *Originator, INTRO_ACTION Action, INTRO_ACTION_REASON Reason)
 Print the information about a kernel-mode violation (Linux guest). More...
 
static int IntExceptPrintDrvObjInfo (WIN_DRIVER_OBJECT *DrvObj, char *Header, char *Line, int MaxLength)
 Print the information about the WIN_DRIVER_OBJECT. More...
 
static void IntExceptKernelLogWindowsInformation (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_KM_ORIGINATOR *Originator, INTRO_ACTION Action, INTRO_ACTION_REASON Reason)
 Print the information about a kernel-mode violation (windows guest). More...
 
void IntExceptKernelLogInformation (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_KM_ORIGINATOR *Originator, INTRO_ACTION Action, INTRO_ACTION_REASON Reason)
 Print the information about a kernel-mode violation and dumps the code-blocks. More...
 
static BOOLEAN IntExceptLixKernelIsMemoryFunc (QWORD Rip)
 This function is used to check if the write has been made using any of "memcpy","__memcpy", "memset", "__memset", "memmove" function. More...
 
static INTSTATUS IntExceptLixKernelGetOriginator (EXCEPTION_KM_ORIGINATOR *Originator)
 This function is used to get the information about the kernel-mode originator (Linux guest). More...
 
static INTSTATUS IntExceptWinKernelGetOriginator (EXCEPTION_KM_ORIGINATOR *Originator, DWORD Options)
 This function is used to get the information about the kernel-mode originator (windows guest). More...
 
INTSTATUS IntExceptKernelGetOriginator (EXCEPTION_KM_ORIGINATOR *Originator, DWORD Options)
 This function is used to get the information about the kernel-mode originator. More...
 
INTSTATUS IntExceptGetOriginatorFromModification (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_KM_ORIGINATOR *Originator)
 This function is used for integrity violations to get the information about the kernel-mode originator. More...
 
INTSTATUS IntExceptGetVictimDtr (DTR *NewValue, DTR *OldValue, INTRO_OBJECT_TYPE Type, EXCEPTION_VICTIM_ZONE *Victim)
 This function is used to get the information about the DTR victim. More...
 
INTSTATUS IntExceptGetVictimMsr (QWORD NewValue, QWORD OldValue, DWORD Msr, EXCEPTION_VICTIM_ZONE *Victim)
 This function is used to get the information about the MSR victim. More...
 
INTSTATUS IntExceptGetVictimIntegrity (INTEGRITY_REGION *IntegrityRegion, DWORD *Offset, EXCEPTION_VICTIM_ZONE *Victim)
 This function is used to get the information about the modified zone from the integrity region. More...
 
INTSTATUS IntExceptGetVictimCr (QWORD NewValue, QWORD OldValue, DWORD Cr, EXCEPTION_VICTIM_ZONE *Victim)
 This function is used to get the information about the CR victim. More...
 
INTSTATUS IntExceptKernelVerifyExtra (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_UM_ORIGINATOR *Originator, UM_EXCEPTION *Exception)
 This function is used as an extra step in exception mechanism. More...
 
INTSTATUS IntExceptKernelMatchVictim (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_KM_ORIGINATOR *Originator, KM_EXCEPTION *Exception)
 This function checks if the exception matches the originator and the modified zone. More...
 
INTSTATUS IntExceptKernel (EXCEPTION_VICTIM_ZONE *Victim, EXCEPTION_KM_ORIGINATOR *Originator, INTRO_ACTION *Action, INTRO_ACTION_REASON *Reason)
 This function iterates through exception lists and tries to find an exception that matches the originator and the victim. More...
 

Variables

char gExcLogLine [2 *ONE_KILOBYTE]
 The exception log line. More...
 

Detailed Description

Kernel mode exceptions.

Definition in file exceptions_kern.c.

Function Documentation

◆ IntExceptGetOriginatorFromModification()

INTSTATUS IntExceptGetOriginatorFromModification ( EXCEPTION_VICTIM_ZONE Victim,
EXCEPTION_KM_ORIGINATOR Originator 
)

This function is used for integrity violations to get the information about the kernel-mode originator.

The function tries to get the address of the originator driver from the written memory zone (victim->WriteInfo).

Parameters
[in]VictimThe victim object.
[out]OriginatorThe originator object.
Return values
INT_STATUS_SUCCESSOn success.
INT_STATUS_EXCEPTION_BLOCKIf the violation should be blocked.
INT_STATUS_EXCEPTION_ALLOWIf the violation should be allowed.
INT_STATUS_NOT_SUPPORTEDIf the modified object type is not of the following:
  • introObjectTypeDriverObject
  • introObjectTypeFastIoDispatch
  • introObjectTypeHalDispatchTable
  • introObjectTypeKmLoggerContext
  • introObjectTypeIdt

Definition at line 2207 of file exceptions_kern.c.

Referenced by IntWinDrvObjHandleModification(), IntWinHalHandleDispatchTableWrite(), IntWinIdtHandleModification(), and IntWinInfHookIntegrityHandleWrite().

◆ IntExceptGetVictimCr()

INTSTATUS IntExceptGetVictimCr ( QWORD  NewValue,
QWORD  OldValue,
DWORD  Cr,
EXCEPTION_VICTIM_ZONE Victim 
)

This function is used to get the information about the CR victim.

Parameters
[in]NewValueThe new value (written) of the CR.
[in]OldValueThe old value of the CR.
[in]CrThe number of the CR register.
[out]VictimThe victim object.
Return values
INT_STATUS_SUCCESSOn success.
INT_STATUS_NOT_SUPPORTEDIf the provided CR is not CR4.
INT_STATUS_INVALID_PARAMETER_2If the provided DTR object is invalid.
INT_STATUS_INVALID_PARAMETER_4If the provided victim object is invalid.

Definition at line 2620 of file exceptions_kern.c.

Referenced by IntCrLixHandleWrite(), and IntCrWinHandleWrite().

◆ IntExceptGetVictimDtr()

INTSTATUS IntExceptGetVictimDtr ( DTR NewValue,
DTR OldValue,
INTRO_OBJECT_TYPE  Type,
EXCEPTION_VICTIM_ZONE Victim 
)

This function is used to get the information about the DTR victim.

Parameters
[in]NewValueThe new value (written) of the DTR.
[in]OldValueThe old value of the DTR.
[in]TypeAny of the following: introObjectTypeIdtr / introObjectTypeGdtr.
[out]VictimThe victim object.
Return values
INT_STATUS_SUCCESSOn success.
INT_STATUS_INVALID_PARAMETER_1If the provided DTR object is invalid.
INT_STATUS_INVALID_PARAMETER_2If the provided DTR object is invalid.
INT_STATUS_INVALID_PARAMETER_4If the provided victim object is invalid.

Definition at line 2342 of file exceptions_kern.c.

Referenced by IntDtrHandleWrite().

◆ IntExceptGetVictimIntegrity()

INTSTATUS IntExceptGetVictimIntegrity ( INTEGRITY_REGION IntegrityRegion,
DWORD Offset,
EXCEPTION_VICTIM_ZONE Victim 
)

This function is used to get the information about the modified zone from the integrity region.

Will get the old value and new value at the modified address aligned down to 64/32 bits (the upper bytes may be the same, so we won't catch them). Returns the found modification offset so we can call it recursively (we start scanning at the given offset).

Parameters
[in]IntegrityRegionThe integrity region object.
[in]OffsetThe offset in the region (not page) form where to search for modifications (for recursive calls).
[out]VictimThe victim object.
Return values
INT_STATUS_SUCCESSOn success.
INT_STATUS_INVALID_PARAMETER_1If the provided integrity-region object is invalid.
INT_STATUS_INVALID_PARAMETER_2If the provided offset pointer is invalid.
INT_STATUS_INVALID_PARAMETER_4If the provided victim object is invalid.
INT_STATUS_NOT_FOUNDIf no modification is found.
INT_STATUS_BUFFER_OVERFLOWIf the provided region modification won't fit the modified object.

Definition at line 2440 of file exceptions_kern.c.

Referenced by IntWinDrvObjHandleModification(), IntWinHalHandleDispatchTableWrite(), IntWinIdtHandleModification(), and IntWinInfHookIntegrityHandleWrite().

◆ IntExceptGetVictimMsr()

INTSTATUS IntExceptGetVictimMsr ( QWORD  NewValue,
QWORD  OldValue,
DWORD  Msr,
EXCEPTION_VICTIM_ZONE Victim 
)

This function is used to get the information about the MSR victim.

Parameters
[in]NewValueThe new value (written) of the MSR.
[in]OldValueThe old value of the MSR.
[in]MsrThe number of the MSR.
[out]VictimThe victim object.
Return values
INT_STATUS_SUCCESSOn success.
INT_STATUS_INVALID_PARAMETER_4If the provided victim object is invalid.

Definition at line 2394 of file exceptions_kern.c.

Referenced by IntLixMsrHandleWrite(), and IntWinMsrHandleWrite().

◆ IntExceptKernel()

INTSTATUS IntExceptKernel ( EXCEPTION_VICTIM_ZONE Victim,
EXCEPTION_KM_ORIGINATOR Originator,
INTRO_ACTION Action,
INTRO_ACTION_REASON Reason 
)

This function iterates through exception lists and tries to find an exception that matches the originator and the victim.

Parameters
[in]VictimThe victim object.
[in]OriginatorThe originator object.
[out]ActionThe action that was taken.
[out]ReasonThe reason for which Action was taken.
Return values
INT_STATUS_INVALID_PARAMETER_1If the victim object is invalid.
INT_STATUS_INVALID_PARAMETER_2If the originator object is invalid.
INT_STATUS_INVALID_PARAMETER_3If the action is invalid.
INT_STATUS_INVALID_PARAMETER_4If the reason is invalid.
INT_STATUS_EXCEPTION_ALLOWIf the violation is allowed.
INT_STATUS_EXCEPTION_NOT_MATCHEDIf the violation is not allowed.

Definition at line 3073 of file exceptions_kern.c.

Referenced by IntExcept().

◆ IntExceptKernelGetOriginator()

◆ IntExceptKernelLogInformation()

◆ IntExceptKernelLogLinuxInformation()

static void IntExceptKernelLogLinuxInformation ( EXCEPTION_VICTIM_ZONE Victim,
EXCEPTION_KM_ORIGINATOR Originator,
INTRO_ACTION  Action,
INTRO_ACTION_REASON  Reason 
)
static

Print the information about a kernel-mode violation (Linux guest).

Parameters
[in]VictimThe victim object.
[in]OriginatorThe originator object.
[in]ActionThe action that was taken.
[in]ReasonThe reason for which Action was taken.

Definition at line 632 of file exceptions_kern.c.

Referenced by IntExceptKernelLogInformation().

◆ IntExceptKernelLogWindowsInformation()

static void IntExceptKernelLogWindowsInformation ( EXCEPTION_VICTIM_ZONE Victim,
EXCEPTION_KM_ORIGINATOR Originator,
INTRO_ACTION  Action,
INTRO_ACTION_REASON  Reason 
)
static

Print the information about a kernel-mode violation (windows guest).

Parameters
[in]VictimThe victim object.
[in]OriginatorThe originator object.
[in]ActionThe action that was taken.
[in]ReasonThe reason for which Action was taken.

Definition at line 1191 of file exceptions_kern.c.

Referenced by IntExceptKernelLogInformation().

◆ IntExceptKernelMatchVictim()

INTSTATUS IntExceptKernelMatchVictim ( EXCEPTION_VICTIM_ZONE Victim,
EXCEPTION_KM_ORIGINATOR Originator,
KM_EXCEPTION Exception 
)

This function checks if the exception matches the originator and the modified zone.

The following are verified:

  • the zone flags
  • the zone type
  • the exception flags
  • the modified name-hash
  • the architecture flags
  • the initialization type
  • the system-process flags
  • the return driver
Parameters
[in]VictimThe victim object.
[in]OriginatorThe originator object.
[in]ExceptionThe current exception object.
Return values
INT_STATUS_EXCEPTION_NOT_MATCHEDIf any check fails.
INT_STATUS_EXCEPTION_ALLOWIf all checks have passed.

Definition at line 2692 of file exceptions_kern.c.

Referenced by IntExceptMatchException().

◆ IntExceptKernelVerifyExtra()

INTSTATUS IntExceptKernelVerifyExtra ( EXCEPTION_VICTIM_ZONE Victim,
EXCEPTION_UM_ORIGINATOR Originator,
UM_EXCEPTION Exception 
)

This function is used as an extra step in exception mechanism.

Parameters
[in]VictimThe victim object.
[in]OriginatorThe originator object.
[in]ExceptionThe current exception object.
Return values
INT_STATUS_EXCEPTION_CHECKS_OKOn success.

Definition at line 2668 of file exceptions_kern.c.

Referenced by IntExceptMatchException().

◆ IntExceptLixKernelGetOriginator()

static INTSTATUS IntExceptLixKernelGetOriginator ( EXCEPTION_KM_ORIGINATOR Originator)
static

This function is used to get the information about the kernel-mode originator (Linux guest).

The stack-trace is parsed in order to fetch the return driver.

Parameters
[out]OriginatorThe originator object.
Return values
INT_STATUS_SUCCESSOn success.

Definition at line 1735 of file exceptions_kern.c.

Referenced by IntExceptKernelGetOriginator().

◆ IntExceptLixKernelIsMemoryFunc()

static BOOLEAN IntExceptLixKernelIsMemoryFunc ( QWORD  Rip)
static

This function is used to check if the write has been made using any of "memcpy","__memcpy", "memset", "__memset", "memmove" function.

Parameters
[in]RipThe rip from which the writing came from.
Return values
Trueif the write has been made using the generic write functions, otherwise, false.

Definition at line 1705 of file exceptions_kern.c.

Referenced by IntExceptLixKernelGetOriginator().

◆ IntExceptPrintCrInfo()

static int IntExceptPrintCrInfo ( EXCEPTION_VICTIM_ZONE Victim,
char *  Header,
char *  Line,
int  MaxLength 
)
static

Print the information about the modified CR.

Parameters
[in]VictimThe victim object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
Return values
Thenumber of written chars.

Definition at line 335 of file exceptions_kern.c.

Referenced by IntExceptKernelLogLinuxInformation(), and IntExceptKernelLogWindowsInformation().

◆ IntExceptPrintDrvObjInfo()

static int IntExceptPrintDrvObjInfo ( WIN_DRIVER_OBJECT DrvObj,
char *  Header,
char *  Line,
int  MaxLength 
)
static

Print the information about the WIN_DRIVER_OBJECT.

Parameters
[in]DrvObjThe WIN_DRIVER_OBJECT object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
Return values
Thenumber of written chars.

Definition at line 1105 of file exceptions_kern.c.

Referenced by IntExceptKernelLogWindowsInformation().

◆ IntExceptPrintDtrInfo()

static int IntExceptPrintDtrInfo ( EXCEPTION_VICTIM_ZONE Victim,
char *  Header,
char *  Line,
int  MaxLength 
)
static

Print the information about the modified IDTR/GDTR.

Parameters
[in]VictimThe victim object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
Return values
Thenumber of written chars.

Definition at line 527 of file exceptions_kern.c.

Referenced by IntExceptKernelLogWindowsInformation().

◆ IntExceptPrintIdtInfo()

static int IntExceptPrintIdtInfo ( EXCEPTION_VICTIM_ZONE Victim,
char *  Header,
char *  Line,
int  MaxLength 
)
static

Print the information about the modified IDT entry.

Parameters
[in]VictimThe victim object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
Return values
Thenumber of written chars.

Definition at line 433 of file exceptions_kern.c.

Referenced by IntExceptKernelLogLinuxInformation(), and IntExceptKernelLogWindowsInformation().

◆ IntExceptPrintLixKmDrvInfo()

static int IntExceptPrintLixKmDrvInfo ( KERNEL_DRIVER Driver,
char *  Header,
char *  Line,
int  MaxLength,
DWORD  NameAlignment 
)
static

Print the information about the provided KERNEL_DRIVER (Linux guest).

Parameters
[in]DriverThe driver object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
[in]NameAlignmentThe alignment of the chars in the buffer.
Return values
Thenumber of written chars.

Definition at line 23 of file exceptions_kern.c.

Referenced by IntExceptKernelLogLinuxInformation(), and IntExceptPrintMsrInfo().

◆ IntExceptPrintMsrInfo()

static int IntExceptPrintMsrInfo ( EXCEPTION_VICTIM_ZONE Victim,
char *  Header,
char *  Line,
int  MaxLength 
)
static

Print the information about the modified MSR.

Parameters
[in]VictimThe victim object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
Return values
Thenumber of written chars.

Definition at line 185 of file exceptions_kern.c.

Referenced by IntExceptKernelLogLinuxInformation(), and IntExceptKernelLogWindowsInformation().

◆ IntExceptPrintWinKmModInfo()

int IntExceptPrintWinKmModInfo ( KERNEL_DRIVER Module,
char *  Header,
char *  Line,
int  MaxLength,
DWORD  NameAlignment 
)

Print the information about the provided KERNEL_DRIVER (windows guest).

Parameters
[in]ModuleThe driver object.
[in]HeaderThe header of the output buffer.
[in]LineThe output buffer.
[in]MaxLengthThe maximum number chars that can be written.
[in]NameAlignmentThe alignment of the chars in the buffer.
Return values
Thenumber of written chars.

Definition at line 90 of file exceptions_kern.c.

Referenced by IntExceptKernelLogWindowsInformation(), IntExceptKernelUserLogWindowsInformation(), and IntExceptPrintMsrInfo().

◆ IntExceptWinKernelGetOriginator()

static INTSTATUS IntExceptWinKernelGetOriginator ( EXCEPTION_KM_ORIGINATOR Originator,
DWORD  Options 
)
static

This function is used to get the information about the kernel-mode originator (windows guest).

The stack-trace is parsed in order to fetch the return driver.

The section for the original and the return driver is parsed in order to check if the violation should be blocked.

Parameters
[out]OriginatorThe originator object.
[out]OptionsIf the violation should be blocked.
Return values
INT_STATUS_SUCCESSOn success.
INT_STATUS_EXCEPTION_BLOCKIf the violation should be blocked.

Definition at line 1856 of file exceptions_kern.c.

Referenced by IntExceptKernelGetOriginator().

Variable Documentation

◆ gExcLogLine

char gExcLogLine[2 *ONE_KILOBYTE]

The exception log line.

Definition at line 40 of file exceptions.c.

Referenced by IntExceptKernelLogLinuxInformation(), and IntExceptKernelLogWindowsInformation().