VirtualBox

Changeset 37083 in vbox


Ignore:
Timestamp:
May 13, 2011 7:24:39 PM (14 years ago)
Author:
vboxsync
Message:

usb: prevent the monitor from being unload, when unhook fails

Location:
trunk/src/VBox/HostDrivers/VBoxUSB/win/mon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbHook.cpp

    r37042 r37083  
    5151    if (pfnOldVal != pHook->pfnHook)
    5252    {
    53         AssertFailed();
     53        AssertMsgFailed(("unhook failed!!!\n"));
    5454        /* this is bad! this could happen if someone else has chained another hook,
    55          * return the failure and don't do anything else */
     55         * or (which is even worse) restored the "initial" entry value it saved when doing a hooking before us
     56         * return the failure and don't do anything else
     57         * the best thing to do if this happens is to leave everything as is
     58         * and to prevent the driver from being unloaded to ensure no one references our unloaded hook routine */
    5659        KeReleaseSpinLock(&pHook->Lock, Irql);
    5760        return STATUS_UNSUCCESSFUL;
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp

    r37042 r37083  
    5454{
    5555    VBOXUSBHOOK_ENTRY Hook;
     56    bool fUninitFailed;
    5657} VBOXUSBHUB_PNPHOOK, *PVBOXUSBHUB_PNPHOOK;
    5758
     
    6869    IO_REMOVE_LOCK RmLock;
    6970    uint32_t cOpens;
     71    volatile LONG ulPreventUnloadOn;
     72    PFILE_OBJECT pPreventUnloadFileObj;
    7073} VBOXUSBMONGLOBALS, *PVBOXUSBMONGLOBALS;
    7174
     
    657660    return STATUS_SUCCESS;
    658661#else
     662    if (g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed)
     663    {
     664        AssertMsgFailed(("trying to hook usbhub pnp after the unhook failed, do nothing & pretend success..\n"));
     665        return STATUS_SUCCESS;
     666    }
    659667    return VBoxUsbHookInstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook);
    660668#endif
     
    666674    return STATUS_SUCCESS;
    667675#else
    668     return VBoxUsbHookUninstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook);
     676    NTSTATUS Status = VBoxUsbHookUninstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook);
     677    if (!NT_SUCCESS(Status))
     678    {
     679        AssertMsgFailed(("usbhub pnp unhook failed, setting the fUninitFailed flag, the current value of fUninitFailed (%d)\n", g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed));
     680        g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed = true;
     681    }
     682    return Status;
    669683#endif
    670684}
     
    677691            FALSE, /* BOOLEAN Alertable */
    678692            NULL /* IN PLARGE_INTEGER Timeout */
    679         );
    680     Assert(Status == STATUS_SUCCESS);
    681     if (Status == STATUS_SUCCESS)
    682     {
    683         do
    684         {
    685             if (--g_VBoxUsbMonGlobals.cOpens)
    686                 break;
    687 
    688             Status = vboxUsbMonHookUninstall();
    689             if (NT_SUCCESS(Status))
    690             {
    691                 Status = VBoxUsbFltTerm();
    692                 if (NT_SUCCESS(Status))
    693                 {
    694                     Status = STATUS_SUCCESS;
    695                     break;
    696                 }
    697                 else
    698                 {
    699                     AssertFailed();
    700                 }
    701             }
    702             else
    703             {
    704                 AssertFailed();
    705             }
    706 
    707             ++g_VBoxUsbMonGlobals.cOpens;
    708             Assert(g_VBoxUsbMonGlobals.cOpens == 1);
    709         } while (0);
    710 
    711         KeSetEvent(&g_VBoxUsbMonGlobals.OpenSynchEvent, 0, FALSE);
    712     }
     693            );
     694    AssertRelease(Status == STATUS_SUCCESS);
     695
     696    do
     697    {
     698        if (--g_VBoxUsbMonGlobals.cOpens)
     699            break;
     700
     701        Status = vboxUsbMonHookUninstall();
     702
     703        NTSTATUS tmpStatus = VBoxUsbFltTerm();
     704        if (!NT_SUCCESS(tmpStatus))
     705        {
     706            /* this means a driver state is screwed up, KeBugCheckEx here ? */
     707            AssertReleaseFailed();
     708        }
     709    } while (0);
     710
     711    KeSetEvent(&g_VBoxUsbMonGlobals.OpenSynchEvent, 0, FALSE);
     712
    713713    return Status;
    714714}
     
    818818    NTSTATUS Status = vboxUsbMonContextClose(pCtx);
    819819    Assert(Status == STATUS_SUCCESS);
     820    if (Status != STATUS_SUCCESS)
     821    {
     822        AssertMsgFailed(("close failed with Status 0x%x, prefent unload\n", Status));
     823        if (!InterlockedExchange(&g_VBoxUsbMonGlobals.ulPreventUnloadOn, 1))
     824        {
     825            LogRel(("ulPreventUnloadOn not set, preventing unload\n"));
     826            UNICODE_STRING UniName;
     827            PDEVICE_OBJECT pTmpDevObj;
     828            RtlInitUnicodeString(&UniName, USBMON_DEVICE_NAME_NT);
     829            NTSTATUS tmpStatus = IoGetDeviceObjectPointer(&UniName, FILE_ALL_ACCESS, &g_VBoxUsbMonGlobals.pPreventUnloadFileObj, &pTmpDevObj);
     830            AssertRelease(NT_SUCCESS(tmpStatus));
     831            AssertRelease(pTmpDevObj == pDevObj);
     832        }
     833        else
     834        {
     835            AssertMsgFailed(("ulPreventUnloadOn already set\n"));
     836        }
     837        Status = STATUS_SUCCESS;
     838    }
    820839    pFileObj->FsContext = NULL;
    821840    pIrp->IoStatus.Status = Status;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette