본문 바로가기

My Study/Programming&Theory

Intel VT-x 와 BSOD.. ㅠㅠ

프로젝트 때문에 요새 Intel 가상화 기술인 VT-x를 쫌 보고 있습니다.

그 중에서도 Bluepill Code를 바탕으로 진행하려고 열심히 코드 분석하고 돌려본 결과.. 자꾸 뻑이나는 겁니다.


뻑나는 경우는 다음과 같습니다. 사용한 Virtual Machine은 VMware입니다.


DbgView를 켜논 상태에서 Bluepill 로드 뻑

WinDbg로 커널 디버깅 중 Bluepill 로드 뻑

Bluepill 로드 후 DbgView 킴..이땐 뻑 안남.. DbgView 끄고 Blupill 언로드.. 다시 Bluepill 로드.. 뻑


여기서 드는 생각은 뭔가 Bluepill 코드를 사용할 때 커널에 한번이라도 디버깅 비스무리한 액션이 취해지면 

Bluepill 코드가 로드시 뻑난다는 것입니다.


여기서 왜 뻑이나는지에 대해 덤프파일을 분석해보았습니다.


*******************************************************************************

*                                                                                                                   *

*                        Bugcheck Analysis                                                                *

*                                                                                                                   *

*******************************************************************************


UNEXPECTED_KERNEL_MODE_TRAP (7f)

This means a trap occurred in kernel mode, and it's a trap of a kind

that the kernel isn't allowed to have/catch (bound trap) or that

is always instant death (double fault).  The first number in the

bugcheck params is the number of the trap (8 = double fault, etc)

Consult an Intel x86 family manual to learn more about what these

traps are. Here is a *portion* of those codes:

If kv shows a taskGate

        use .tss on the part before the colon, then kv.

Else if kv shows a trapframe

        use .trap on that value

Else

        .trap on the appropriate frame will show where the trap was taken

        (on x86, this will be the ebp that goes with the procedure KiTrap)

Endif

kb will then show the corrected stack.

Arguments:

Arg1: 0000000d, EXCEPTION_GP_FAULT

Arg2: 00000000

Arg3: 00000000

Arg4: 00000000



Bug check 값은 0x7f이고 파라미터는 0xd( EXCEPTION_GP_FAULT ) 였습니다.

일단 WinDbg 도움말에 있는 내용으로 봐보겠습니다.


  • 0x0000000D — An exception not covered by some other exception; a protection fault that pertains to access violations for applications 

어플리케이션에서 접근 위반에 관련된 protection fault 가 발생 시 이 0x7f_d가 발생한다고 나와있네요.


그 아래 정보입니다.

BUGCHECK_STR:  0x7f_d


DEFAULT_BUCKET_ID:  CODE_CORRUPTION


PROCESS_NAME:  System


CURRENT_IRQL:  2


LAST_CONTROL_TRANSFER:  from 82c61e83 to 82c4629b


STACK_TEXT:  

80e0a964 82c61e83 badb0d00 00000000 852c4798 nt!KiSystemFatalException+0xf

80e0a9e4 83012924 80e0aa2c 00000000 00000006 nt!KiDispatchInterrupt+0x73

80e0aa2c 9d9332f2 badb0d00 00000000 85383d50 hal!HalpDispatchSoftwareInterrupt+0x5e

80e0aad8 82dc5f93 85383d50 853b2000 00000000 myvmm!DriverEntry+0x2f2 [d:\visualstudio\edrivers\vmm\vmm\vmm.c @ 1870]

80e0acbc 82dae344 00000001 00000000 80e0ace4 nt!IopLoadDriver+0x7ed

80e0ad00 82c68043 8de71cd0 00000000 852c4798 nt!IopLoadUnloadDriver+0x70

80e0ad50 82df4d16 00000001 19d2413d 00000000 nt!ExpWorkerThread+0x10d

80e0ad90 82c96159 82c67f36 00000001 00000000 nt!PspSystemThreadStartup+0x9e

00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x19



STACK_COMMAND:  kb


CHKIMG_EXTENSION: !chkimg -lo 50 -d !nt

    82c61fbf - nt!SwapContext_PatchFxb+2

[ 01:21 ]

    82c6220d - nt!EnlightenedSwapContext_PatchFxb+2 (+0x24e)

[ 01:21 ]

2 errors : !nt (82c61fbf-82c6220d)


MODULE_NAME: memory_corruption


IMAGE_NAME:  memory_corruption


FOLLOWUP_NAME:  memory_corruption


DEBUG_FLR_IMAGE_TIMESTAMP:  0


MEMORY_CORRUPTOR:  ONE_BIT_LARGE


FAILURE_BUCKET_ID:  MEMORY_CORRUPTION_ONE_BIT_LARGE


BUCKET_ID:  MEMORY_CORRUPTION_ONE_BIT_LARGE


콜 스택 부분을 보면 myvmm 드라이버가 bluepill 드라이버입니다. 일단 콜스택에 저놈이 있으므로 저 부분의 코드를 봐보도록 하겠습니다.



아래 있는 Log 부분에서 뻑이 났습니다. 하지만 Log 는 DbgPrint 함수를 그냥 define 해논것 뿐이고..

KeGetCurrentProcessorNumber 함수는 내부 코드를 보면 뭐 크리티컬한 명령어를 사용하고 있진 않습니다.


그리고 StartVMX 내부에서 VMLAUNCH를 사용하므로 VMXOFF 를 하기 전까진 빠져나오면 안되는데 빠져나왔군요.


일단 Bugcheck 이 0x7f_d 이므로 제 능력으로 해결하기가 애매하군요..


뭐 지금 당장의 해결 방안은.. 디버깅 하지 않고 DbgPrint로 찍어서 해보면 되긴하는데 뭔가 찝찝하군요.


혹시 이 문제에 대한 해결방안 있으시면 도움 좀 주세요 ㅠ_ㅠ .. DMP(메모리 전체) 파일 필요하시면 드리겠습니다.