VirtualBox

Changeset 52709 in vbox


Ignore:
Timestamp:
Sep 11, 2014 6:12:12 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
96046
Message:

SUP: Improve VBoxDrvStub open error reporting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp

    r52704 r52709  
    39973997
    39983998/**
     3999 * Logs the content of the given object directory.
     4000 *
     4001 * @returns true if it exists, false if not.
     4002 * @param   pszDir             The path of the directory to log (ASCII).
     4003 */
     4004static void supR3HardenedWinLogObjDir(const char *pszDir)
     4005{
     4006    /*
     4007     * Open the driver object directory.
     4008     */
     4009    RTUTF16 wszDir[128];
     4010    int rc = RTUtf16CopyAscii(wszDir, RT_ELEMENTS(wszDir), pszDir);
     4011    if (RT_FAILURE(rc))
     4012    {
     4013        SUP_DPRINTF(("supR3HardenedWinLogObjDir: RTUtf16CopyAscii -> %Rrc on '%s'\n", rc, pszDir));
     4014        return;
     4015    }
     4016
     4017    UNICODE_STRING NtDirName;
     4018    NtDirName.Buffer = (WCHAR *)wszDir;
     4019    NtDirName.Length = (USHORT)(RTUtf16Len(wszDir) * sizeof(WCHAR));
     4020    NtDirName.MaximumLength = NtDirName.Length + sizeof(WCHAR);
     4021
     4022    OBJECT_ATTRIBUTES ObjAttr;
     4023    InitializeObjectAttributes(&ObjAttr, &NtDirName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/);
     4024
     4025    HANDLE hDir;
     4026    NTSTATUS rcNt = NtOpenDirectoryObject(&hDir, DIRECTORY_QUERY | FILE_LIST_DIRECTORY, &ObjAttr);
     4027    SUP_DPRINTF(("supR3HardenedWinLogObjDir: %ls => %#x\n", wszDir, rcNt));
     4028    if (!NT_SUCCESS(rcNt))
     4029        return;
     4030
     4031    /*
     4032     * Enumerate it, looking for the driver.
     4033     */
     4034    ULONG uObjDirCtx = 0;
     4035    for (;;)
     4036    {
     4037        uint32_t    abBuffer[_64K + _1K];
     4038        ULONG       cbActual;
     4039        rcNt = NtQueryDirectoryObject(hDir,
     4040                                      abBuffer,
     4041                                      sizeof(abBuffer) - 4, /* minus four for string terminator space. */
     4042                                      FALSE /*ReturnSingleEntry */,
     4043                                      FALSE /*RestartScan*/,
     4044                                      &uObjDirCtx,
     4045                                      &cbActual);
     4046        if (!NT_SUCCESS(rcNt) || cbActual < sizeof(OBJECT_DIRECTORY_INFORMATION))
     4047        {
     4048            SUP_DPRINTF(("supR3HardenedWinLogObjDir: NtQueryDirectoryObject => rcNt=%#x cbActual=%#x\n", rcNt, cbActual));
     4049            break;
     4050        }
     4051
     4052        POBJECT_DIRECTORY_INFORMATION pObjDir = (POBJECT_DIRECTORY_INFORMATION)abBuffer;
     4053        while (pObjDir->Name.Length != 0)
     4054        {
     4055            WCHAR wcSaved = pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)];
     4056            SUP_DPRINTF(("  %.*ls  %.*ls\n",
     4057                         pObjDir->TypeName.Length / sizeof(WCHAR), pObjDir->TypeName.Buffer,
     4058                         pObjDir->Name.Length / sizeof(WCHAR), pObjDir->Name.Buffer));
     4059
     4060            /* Next directory entry. */
     4061            pObjDir++;
     4062        }
     4063    }
     4064
     4065    /*
     4066     * Clean up and return.
     4067     */
     4068    NtClose(hDir);
     4069}
     4070
     4071
     4072/**
    39994073 * Checks if the driver exists.
    40004074 *
     
    41354209    if (!NT_SUCCESS(rcNt))
    41364210    {
     4211        /*
     4212         * Report trouble (fatal).  For some errors codes we try gather some
     4213         * extra information that goes into VBoxStartup.log so that we stand a
     4214         * better chance resolving the issue.
     4215         */
    41374216        int rc = VERR_OPEN_FAILED;
    41384217        if (SUP_NT_STATUS_IS_VBOX(rcNt)) /* See VBoxDrvNtErr2NtStatus. */
     4218        {
    41394219            rc = SUP_NT_STATUS_TO_VBOX(rcNt);
     4220
     4221            /*
     4222             * \Windows\ApiPort open trouble.  So far only
     4223             * STATUS_OBJECT_TYPE_MISMATCH has been observed.
     4224             */
     4225            if (rc == VERR_SUPDRV_APIPORT_OPEN_ERROR)
     4226            {
     4227                SUP_DPRINTF(("Error opening VBoxDrvStub: VERR_SUPDRV_APIPORT_OPEN_ERROR\n"));
     4228
     4229                uint32_t uSessionId = NtCurrentPeb()->SessionId;
     4230                SUP_DPRINTF(("  SessionID=%#x\n", uSessionId));
     4231                char szDir[64];
     4232                if (uSessionId == 0)
     4233                    RTStrCopy(szDir, sizeof(szDir), "\\Windows");
     4234                else
     4235                {
     4236                    RTStrPrintf(szDir, sizeof(szDir), "\\Sessions\\%u\\Windows", uSessionId);
     4237                    supR3HardenedWinLogObjDir(szDir);
     4238                }
     4239                supR3HardenedWinLogObjDir("\\Windows");
     4240                supR3HardenedWinLogObjDir("\\Sessions");
     4241                supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Misc, rc,
     4242                                      "NtCreateFile(%ls) failed: VERR_SUPDRV_APIPORT_OPEN_ERROR\n"
     4243                                      "\n"
     4244                                      "Error getting %s\\ApiPort in the driver from vboxdrv.\n"
     4245                                      "\n"
     4246                                      "Could be due to security software is redirecting access to it, so please include full "
     4247                                      "details of such software in a bug report. VBoxStartup.log may contain details important "
     4248                                      "to resolving the issue."
     4249                                      , s_wszName, szDir);
     4250            }
     4251
     4252            /*
     4253             * Generic VBox failure message.
     4254             */
     4255            supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, rc,
     4256                                  "NtCreateFile(%ls) failed: %Rrc (rcNt=%#x)\n", s_wszName, rc, rcNt);
     4257        }
    41404258        else
    41414259        {
     
    41494267                default:                            pszDefine = ""; break;
    41504268            }
     4269
     4270            /*
     4271             * Problems opening the device is generally due to driver load/
     4272             * unload issues.  Check whether the driver is loaded and make
     4273             * suggestions accordingly.
     4274             */
     4275            if (   rcNt == STATUS_NO_SUCH_DEVICE
     4276                || rcNt == STATUS_OBJECT_NAME_NOT_FOUND)
     4277            {
     4278                SUP_DPRINTF(("Error opening VBoxDrvStub: %s\n", pszDefine));
     4279                if (supR3HardenedWinDriverExists("VBoxDrv"))
     4280                    supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, VERR_OPEN_FAILED,
     4281                                          "NtCreateFile(%ls) failed: %#x%s (%u retries)\n"
     4282                                          "\n"
     4283                                          "Driver is probably stuck stopping/starting. Try 'sc.exe query vboxdrv' to get more "
     4284                                          "information about its state. Rebooting may actually help.\n"
     4285                                          , s_wszName, rcNt, pszDefine, iTry);
     4286                else
     4287                    supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, VERR_OPEN_FAILED,
     4288                                          "NtCreateFile(%ls) failed: %#x%s (%u retries)\n"
     4289                                          "\n"
     4290                                          "Driver is does not appear to be loaded. Try 'sc.exe start vboxdrv', reinstall "
     4291                                          "VirtualBox or reboot.\n"
     4292                                          , s_wszName, rcNt, pszDefine, iTry);
     4293            }
     4294
     4295            /* Generic NT failure message. */
    41514296            supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, VERR_OPEN_FAILED,
    41524297                                  "NtCreateFile(%ls) failed: %#x%s (%u retries)\n", s_wszName, rcNt, pszDefine, iTry);
    41534298        }
    4154         supR3HardenedFatalMsg("supR3HardenedWinReSpawn", kSupInitOp_Driver, rc,
    4155                               "NtCreateFile(%ls) failed: %Rrc (rcNt=%#x)\n", s_wszName, rc, rcNt);
    41564299    }
    41574300}
Note: See TracChangeset for help on using the changeset viewer.

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