EXCEPTION_DOUBLE_FAULT и исполняемый файл процесса

Тема в разделе "WASM.NT.KERNEL", создана пользователем rttgedt, 7 сен 2011.

  1. rttgedt

    rttgedt Антон

    Публикаций:
    0
    Регистрация:
    12 окт 2010
    Сообщения:
    85
    Пытаюсь узнать имя процесса по PID. В случайном порядке вываливается в БСОД 7F. Уже весь мозг сломал, пытаясь понять в чем дело, похоже, где-то портится стек. Может кто со свежим взглядом найдет ошибку..

    Код (Text):
    1. PVOID GetProcessSectionObject(IN PEPROCESS peproc)
    2. {
    3.     PVOID result = NULL;
    4.     ULONG_PTR PseudoEPROC[300];
    5.     ULONG_PTR offset;
    6.     DWORD32 i;
    7.  
    8.     for (i = 0; i < 300; i++)
    9.         PseudoEPROC[i] = i;
    10.    
    11.     offset = (ULONG_PTR) PsGetProcessSectionBaseAddress((PEPROCESS) &PseudoEPROC);
    12.     offset *= sizeof(ULONG_PTR);
    13.     offset -= sizeof(PVOID);
    14.     result = *((PSECTION_OBJECT*)((ULONG)peproc + offset));
    15.     return result;
    16. }
    17.  
    18. VOID GetProcessEXEName(IN  ULONG pid, OUT PWCHAR ExeName)
    19. {
    20.     NTSTATUS Status;
    21.     PSECTION_OBJECT SectionObj;
    22.     PFILE_OBJECT FileObj;
    23.     PEPROCESS pEproc;
    24.     POBJECT_NAME_INFORMATION ObName = NULL;
    25.  
    26.     Status = PsLookupProcessByProcessId((HANDLE)pid, &pEproc);
    27.     if (NT_SUCCESS(Status)) {
    28.         SectionObj = (PSECTION_OBJECT)GetProcessSectionObject(pEproc);  
    29.         if (SectionObj) {
    30.             if (SectionObj->Segment) {
    31.                 if (((PSEGMENT)SectionObj->Segment)->ControlArea) {
    32.                     FileObj = ((PSEGMENT)SectionObj->Segment)->ControlArea->FilePointer;                
    33.                     if (FileObj)
    34.                     {
    35.                         if (FileObj->FileName.Buffer)
    36.                         {
    37.                             ExAcquireFastMutex(&GlobalData->Mutex);
    38.                             Status = VdoToVolumeLabel(FileObj->DeviceObject->Vpb->RealDevice, ExeName);
    39.                             ExReleaseFastMutex(&GlobalData->Mutex);
    40.                             if (NT_SUCCESS(Status)) RtlStringCchCatNW(ExeName, 260, FileObj->FileName.Buffer, FileObj->FileName.Length);
    41.                             else RtlStringCchCopyNW(ExeName, 260, FileObj->FileName.Buffer, FileObj->FileName.Length);
    42.                         }
    43.                     }
    44.                 }
    45.             }
    46.         }
    47.         ObDereferenceObject(pEproc);
    48.         if (!ExeName[0]) RtlStringCchCopyW(ExeName, 260, L"System");
    49.     }
    50. }
    Код (Text):
    1. !analyze -v
    2.  
    3. UNEXPECTED_KERNEL_MODE_TRAP (7f)
    4. This means a trap occurred in kernel mode, and it's a trap of a kind
    5. that the kernel isn't allowed to have/catch (bound trap) or that
    6. is always instant death (double fault).  The first number in the
    7. bugcheck params is the number of the trap (8 = double fault, etc)
    8. Consult an Intel x86 family manual to learn more about what these
    9. traps are. Here is a *portion* of those codes:
    10. If kv shows a taskGate
    11.         use .tss on the part before the colon, then kv.
    12. Else if kv shows a trapframe
    13.         use .trap on that value
    14. Else
    15.         .trap on the appropriate frame will show where the trap was taken
    16.         (on x86, this will be the ebp that goes with the procedure KiTrap)
    17. Endif
    18. kb will then show the corrected stack.
    19. Arguments:
    20. Arg1: 00000008, EXCEPTION_DOUBLE_FAULT
    21. Arg2: 80042000
    22. Arg3: 00000000
    23. Arg4: 00000000
    24.  
    25. Debugging Details:
    26. ------------------
    27. BUGCHECK_STR:  0x7f_8
    28.  
    29. TSS:  00000028 -- (.tss 0x28)
    30. eax=00000000 ebx=81fcaaf0 ecx=e1000884 edx=81b9f020 esi=81dd0b10 edi=81f2f330
    31. eip=b2401e29 esp=b2905f18 ebp=b29063d8 iopl=0         nv up ei ng nz na pe nc
    32. cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00010286
    33. DiskSpy!GetProcessSectionObject+0x9:
    34. b2401e29 c78540fbffff00000000 mov dword ptr [ebp-4C0h],0 ss:0010:b2905f18=????????
    35. Resetting default scope
    36.  
    37. DEFAULT_BUCKET_ID:  DRIVER_FAULT
    38. PROCESS_NAME:  VMwareUser.exe
    39. LAST_CONTROL_TRANSFER:  from b2401ee1 to b2401e29
    40.  
    41. STACK_TEXT:  
    42. b29063d8 b2401ee1 81b9f020 81b9f020 00000000 DiskSpy!GetProcessSectionObject+0x9 [f:\programming\diskspy\diskspy.cpp @ 908]
    43. b29063f8 b24012c9 00000720 b2906414 00000003 DiskSpy!GetProcessEXEName+0x31 [f:\programming\diskspy\diskspy.cpp @ 933]
    44. b290682c b24053e3 81f2f320 00000000 81e8f648 DiskSpy!StartLogIrp+0x59 [f:\programming\diskspy\diskspy.cpp @ 662]
    45. b2906854 804ee119 81e8f590 81f2f320 81f2f320 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    46. b2906864 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    47. b290689c 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    48. b29068b8 80522bc1 81fcaaf0 00000000 81b62e58 nt!ObpRemoveObjectRoutine+0xe0
    49. b29068dc b240134b 00000003 81e8f648 81b62fd8 nt!ObfDereferenceObject+0x5f
    50. b2906d08 b24053e3 81b62e48 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    51. b2906d30 804ee119 81e8f590 81b62e48 81b62e48 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    52. b2906d40 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    53. b2906d78 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    54. b2906d94 80522bc1 81fcaaf0 00000000 81f47600 nt!ObpRemoveObjectRoutine+0xe0
    55. b2906db8 b240134b 00000003 81e8f648 81f47780 nt!ObfDereferenceObject+0x5f
    56. b29071e4 b24053e3 81f475f0 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    57. b290720c 804ee119 81e8f590 81f475f0 81f475f0 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    58. b290721c 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    59. b2907254 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    60. b2907270 80522bc1 81fcaaf0 00000000 81f2e630 nt!ObpRemoveObjectRoutine+0xe0
    61. b2907294 b240134b 00000003 81e8f648 81f2e7b0 nt!ObfDereferenceObject+0x5f
    62. b29076c0 b24053e3 81f2e620 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    63. b29076e8 804ee119 81e8f590 81f2e620 81f2e620 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    64. b29076f8 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    65. b2907730 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    66. b290774c 80522bc1 81fcaaf0 00000000 81f47e58 nt!ObpRemoveObjectRoutine+0xe0
    67. b2907770 b240134b 00000003 81e8f648 81f47fd8 nt!ObfDereferenceObject+0x5f
    68. b2907b9c b24053e3 81f47e48 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    69. b2907bc4 804ee119 81e8f590 81f47e48 81f47e48 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    70. b2907bd4 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    71. b2907c0c 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    72. b2907c28 80522bc1 81fcaaf0 00000000 81c71a38 nt!ObpRemoveObjectRoutine+0xe0
    73. b2907c4c b240134b 00000003 81e8f648 81c71bb8 nt!ObfDereferenceObject+0x5f
    74. b2908078 b24053e3 81c71a28 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    75. b29080a0 804ee119 81e8f590 81c71a28 81c71a28 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    76. b29080b0 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    77. b29080e8 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    78. b2908104 80522bc1 81fcaaf0 00000000 81f3c388 nt!ObpRemoveObjectRoutine+0xe0
    79. b2908128 b240134b 00000003 81e8f648 81f3c508 nt!ObfDereferenceObject+0x5f
    80. b2908554 b24053e3 81f3c378 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    81. b290857c 804ee119 81e8f590 81f3c378 81f3c378 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    82. b290858c 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    83. b29085c4 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    84. b29085e0 80522bc1 81fcaaf0 00000000 81e68e58 nt!ObpRemoveObjectRoutine+0xe0
    85. b2908604 b240134b 00000003 81e8f648 81e68fd8 nt!ObfDereferenceObject+0x5f
    86. b2908a30 b24053e3 81e68e48 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    87. b2908a58 804ee119 81e8f590 81e68e48 81e68e48 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    88. b2908a68 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    89. b2908aa0 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    90. b2908abc 80522bc1 81fcaaf0 00000000 81b76480 nt!ObpRemoveObjectRoutine+0xe0
    91. b2908ae0 b240134b 00000003 81e8f648 81b76600 nt!ObfDereferenceObject+0x5f
    92. b2908f0c b24053e3 81b76470 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    93. b2908f34 804ee119 81e8f590 81b76470 81b76470 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    94. b2908f44 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    95. b2908f7c 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    96. b2908f98 80522bc1 81fcaaf0 00000000 81cd9018 nt!ObpRemoveObjectRoutine+0xe0
    97. b2908fbc b240134b 00000003 81e8f648 81cd9198 nt!ObfDereferenceObject+0x5f
    98. b29093e8 b24053e3 81cd9008 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    99. b2909410 804ee119 81e8f590 81cd9008 81cd9008 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    100. b2909420 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    101. b2909458 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    102. b2909474 80522bc1 81fcaaf0 00000000 81f44870 nt!ObpRemoveObjectRoutine+0xe0
    103. b2909498 b240134b 00000003 81e8f648 81f449f0 nt!ObfDereferenceObject+0x5f
    104. b29098c4 b24053e3 81f44860 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    105. b29098ec 804ee119 81e8f590 81f44860 81f44860 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    106. b29098fc 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    107. b2909934 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    108. b2909950 80522bc1 81fcaaf0 00000000 81cff8a8 nt!ObpRemoveObjectRoutine+0xe0
    109. b2909974 b240134b 00000003 81e8f648 81cffa28 nt!ObfDereferenceObject+0x5f
    110. b2909da0 b24053e3 81cff898 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    111. b2909dc8 804ee119 81e8f590 81cff898 81cff898 DiskSpy!DispatchMonitoring+0x73 [f:\programming\diskspy\diskspy.cpp @ 124]
    112. b2909dd8 80578eea 81fcaad8 00000000 00000000 nt!IopfCallDriver+0x31
    113. b2909e10 805b0a8a 00fcaaf0 81fcaad8 00000000 nt!IopDeleteFile+0x132
    114. b2909e2c 80522bc1 81fcaaf0 00000000 81f2d988 nt!ObpRemoveObjectRoutine+0xe0
    115. b2909e50 b240134b 00000003 81e8f648 81f2db08 nt!ObfDereferenceObject+0x5f
    116. b290a27c b24053e3 81f2d978 00000000 81e8f648 DiskSpy!StartLogIrp+0xdb [f:\programming\diskspy\diskspy.cpp @ 673]
    117.  
    118.  
    119. STACK_COMMAND:  .tss 0x28 ; kb
    120. FOLLOWUP_IP:
    121. DiskSpy!GetProcessSectionObject+9 [f:\programming\diskspy\diskspy.cpp @ 908]
    122. b2401e29 c78540fbffff00000000 mov dword ptr [ebp-4C0h],0
    123.  
    124. FAULTING_SOURCE_CODE:  
    125.    904:
    126.    905:
    127.    906: PVOID GetProcessSectionObject(IN PEPROCESS peproc)
    128.    907: {
    129. >  908:     PVOID result = NULL;
    130.    909:     ULONG_PTR PseudoEPROC[300];
    131.    910:     ULONG_PTR offset;
    132.    911:     DWORD32 i;
    133.    912:
    134.    913:     for (i = 0; i < 300; i++)
    135.  
    136.  
    137. SYMBOL_STACK_INDEX:  0
    138. SYMBOL_NAME:  DiskSpy!GetProcessSectionObject+9
    139. FOLLOWUP_NAME:  MachineOwner
    140. MODULE_NAME: DiskSpy
    141. IMAGE_NAME:  DiskSpy.sys
    142. DEBUG_FLR_IMAGE_TIMESTAMP:  4e67030a
    143. FAILURE_BUCKET_ID:  0x7f_8_DiskSpy!GetProcessSectionObject+9
    144. BUCKET_ID:  0x7f_8_DiskSpy!GetProcessSectionObject+9
     
  2. h0t

    h0t Member

    Публикаций:
    0
    Регистрация:
    3 апр 2011
    Сообщения:
    735
    #pragma alloc_text(PAGE,GetProcessSectionObject) случайно нет?
     
  3. rttgedt

    rttgedt Антон

    Публикаций:
    0
    Регистрация:
    12 окт 2010
    Сообщения:
    85
    нет, все эти функции в невыгружаемой памяти
     
  4. x64

    x64 New Member

    Публикаций:
    0
    Регистрация:
    29 июл 2008
    Сообщения:
    1.370
    Адрес:
    Россия
    1. На стек вызовов обрати внимание.
    2. Секция в объекте процесса типа SECTION.
    3. Выгружаемость секций кода не играет, здесь обычно irql=0.
     
  5. h0t

    h0t Member

    Публикаций:
    0
    Регистрация:
    3 апр 2011
    Сообщения:
    735
    а можно код, который GetProcessExeName вызывает
     
  6. rttgedt

    rttgedt Антон

    Публикаций:
    0
    Регистрация:
    12 окт 2010
    Сообщения:
    85
    Код (Text):
    1. PLOG_RECORD StartLogIrp(PIRP Irp)
    2. {
    3.     PLOG_RECORD LogRecord;
    4.     PRECORD_IRP RecordIrp;
    5.     WCHAR FilePath[260];
    6.     WCHAR Proc[260];
    7.     POBJECT_NAME_INFORMATION ObInfo = NULL;
    8.     PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
    9.     PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) Stack->DeviceObject->DeviceExtension;
    10.  
    11.     FilePath[0] = L'\0';
    12.     Proc[0] = L'\0';
    13.  
    14.     GetProcessEXEName((ULONG) PsGetCurrentProcessId(), Proc);
    15.     if (Stack->FileObject)
    16.     {
    17.         ObReferenceObject(Stack->FileObject);
    18.         if (Stack->FileObject->FileName.Buffer)
    19.         {
    20.             RtlStringCchCopyNW(FilePath, 260, pdx->VolumeName, 8);
    21.             RtlStringCchCatNW(FilePath, 260, Stack->FileObject->FileName.Buffer, Stack->FileObject->FileName.Length);
    22.         }
    23.         ObDereferenceObject(Stack->FileObject);
    24.     }
    25.  
    26.     if (GlobalData->Filtering)
    27.     {
    28.         if (!wcsstr(FilePath, GlobalData->PathForFiltering))
    29.             return NULL;
    30.     }
    31.    
    32.  
    33.     LogRecord = (PLOG_RECORD) ExAllocatePoolWithTag(NonPagedPool, sizeof(LOG_RECORD), 32);
    34.     if (!LogRecord) return NULL;
    35.     memset(LogRecord, 0, sizeof(LOG_RECORD));
    36.  
    37.     RtlStringCchCopyNW(LogRecord->FilePath, 260, FilePath, 260);
    38.     RtlStringCchCopyNW(LogRecord->ProcessName, 260, Proc, 260);
    39.  
    40.     LogRecord->Type = RECORD_LOG_IRP;
    41.     LogRecord->Next = NULL;
    42.     RecordIrp = &LogRecord->Record.RecordIrp;
    43.     RecordIrp->IrpMj = Stack->MajorFunction;
    44.     RecordIrp->IrpMn = Stack->MinorFunction;
    45.     RecordIrp->IrpFlags = Irp->Flags;
    46.     RecordIrp->ThreadID = (ULONG) PsGetCurrentThreadId();
    47.     return LogRecord;
    48. }
     
  7. x64

    x64 New Member

    Публикаций:
    0
    Регистрация:
    29 июл 2008
    Сообщения:
    1.370
    Адрес:
    Россия
    rttgedt
    Зачем ссылки на файловый объект ставишь? Не нужны они там.
     
  8. TermoSINteZ

    TermoSINteZ Синоби даоса Команда форума

    Публикаций:
    2
    Регистрация:
    11 июн 2004
    Сообщения:
    3.546
    Адрес:
    Russia
    rttgedt
    А зачем так сложно? Неужели вытащить из EPROCESS имя - религия не позволяет?
    Код (Text):
    1. pEproc->ImageFileName
     
  9. rttgedt

    rttgedt Антон

    Публикаций:
    0
    Регистрация:
    12 окт 2010
    Сообщения:
    85
    Вроде сам разобрался, косяк был в другом месте, забыл проверить указатель на нуль ))
     
  10. rttgedt

    rttgedt Антон

    Публикаций:
    0
    Регистрация:
    12 окт 2010
    Сообщения:
    85
    TermoSINteZ, ведь для этого прописывать смещения нужно для структуры EPROCESS для всех возможных версий ОС. А такой вариант без особых хлопот будет (я надеюсь) работать на всех системах от ХР и старше. И в pEproc->ImageFileName храниться только короткое имя без пути, или я ошибаюсь?
     
  11. TermoSINteZ

    TermoSINteZ Синоби даоса Команда форума

    Публикаций:
    2
    Регистрация:
    11 июн 2004
    Сообщения:
    3.546
    Адрес:
    Russia
    rttgedt
    Нет, полного пути там не бывает. Если нужен полный, то тогда конечно этот вариант не подходит.
     
  12. Mika0x65

    Mika0x65 New Member

    Публикаций:
    0
    Регистрация:
    30 июл 2005
    Сообщения:
    1.384
    Для доступа к EPROCESS::ImageFileName не обязательно обращаться к полям структуры напрямую, можно использовать недокументированную ф-ию PsGetProcessImageFileName. В случае rttgedt это немного не то, но может кому-то пригодится. http://www.osronline.com/article.cfm?article=472 -- а это хорошая статья об альтернативном способе (комментарии только прочитайте, там есть не очень приятный момент).