VirtualBox

Changeset 53407 in vbox for trunk/src


Ignore:
Timestamp:
Nov 28, 2014 9:30:29 AM (10 years ago)
Author:
vboxsync
Message:

Disk encryption: Make sure the DekMissing guest property is set before the state change handler is called when the VM is suspended

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r53148 r53407  
    199199    /** The secret key interface used to retrieve keys. */
    200200    PPDMISECKEY              pIfSecKey;
     201    /** The secret key helper interface used to notify about missing keys. */
     202    PPDMISECKEYHLP           pIfSecKeyHlp;
    201203    /** @} */
    202204} VBOXDISK, *PVBOXDISK;
     
    15371539}
    15381540
     1541/**
     1542 * Checks the prerequisites for encrypted I/O.
     1543 *
     1544 * @returns VBox status code.
     1545 * @param   pThis    The VD driver instance data.
     1546 */
     1547static int drvvdKeyCheckPrereqs(PVBOXDISK pThis)
     1548{
     1549    if (   pThis->pCfgCrypto
     1550        && !pThis->pIfSecKey)
     1551    {
     1552        AssertPtr(pThis->pIfSecKeyHlp);
     1553        pThis->pIfSecKeyHlp->pfnKeyMissingNotify(pThis->pIfSecKeyHlp);
     1554
     1555        int rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
     1556                                            N_("VD: The DEK for this disk is missing"));
     1557        AssertRC(rc);
     1558        return VERR_VD_DEK_MISSING;
     1559    }
     1560
     1561    return VINF_SUCCESS;
     1562}
    15391563
    15401564/*******************************************************************************
     
    15511575    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    15521576
    1553     if (   pThis->pCfgCrypto
    1554         && !pThis->pIfSecKey)
    1555     {
    1556         rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
    1557                                         N_("VD: The DEK for this disk is missing"));
    1558         AssertRC(rc);
    1559         return VERR_VD_DEK_MISSING;
    1560     }
     1577    rc = drvvdKeyCheckPrereqs(pThis);
     1578    if (RT_FAILURE(rc))
     1579        return rc;
    15611580
    15621581    if (!pThis->fBootAccelActive)
     
    16661685          off, pvBuf, cbWrite, cbWrite, pvBuf));
    16671686
    1668     if (   pThis->pCfgCrypto
    1669         && !pThis->pIfSecKey)
    1670     {
    1671         int rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
    1672                                             N_("VD: The DEK for this disk is missing"));
    1673         AssertRC(rc);
    1674         return VERR_VD_DEK_MISSING;
    1675     }
     1687    int rc = drvvdKeyCheckPrereqs(pThis);
     1688    if (RT_FAILURE(rc))
     1689        return rc;
    16761690
    16771691    /* Invalidate any buffer if boot acceleration is enabled. */
     
    16821696    }
    16831697
    1684     int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
     1698    rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
    16851699    LogFlowFunc(("returns %Rrc\n", rc));
    16861700    return rc;
     
    17331747
    17341748/** @copydoc PDMIMEDIA::pfnSetKey */
    1735 static DECLCALLBACK(int) drvvdSetSecKeyIf(PPDMIMEDIA pInterface, PPDMISECKEY pIfSecKey)
     1749static DECLCALLBACK(int) drvvdSetSecKeyIf(PPDMIMEDIA pInterface, PPDMISECKEY pIfSecKey, PPDMISECKEYHLP pIfSecKeyHlp)
    17361750{
    17371751    LogFlowFunc(("\n"));
     
    17421756    {
    17431757        PVDINTERFACE pVDIfFilter = NULL;
     1758
     1759        pThis->pIfSecKeyHlp = pIfSecKeyHlp;
    17441760
    17451761        if (   pThis->pIfSecKey
     
    19872003    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
    19882004
    1989     if (   pThis->pCfgCrypto
    1990         && !pThis->pIfSecKey)
    1991     {
    1992         rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
    1993                                         N_("VD: The DEK for this disk is missing"));
    1994         AssertRC(rc);
    1995         return VERR_VD_DEK_MISSING;
    1996     }
     2005    rc = drvvdKeyCheckPrereqs(pThis);
     2006    if (RT_FAILURE(rc))
     2007        return rc;
    19972008
    19982009    pThis->fBootAccelActive = false;
     
    20252036    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
    20262037
    2027     if (   pThis->pCfgCrypto
    2028         && !pThis->pIfSecKey)
    2029     {
    2030         rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
    2031                                         N_("VD: The DEK for this disk is missing"));
    2032         AssertRC(rc);
    2033         return VERR_VD_DEK_MISSING;
    2034     }
     2038    rc = drvvdKeyCheckPrereqs(pThis);
     2039    if (RT_FAILURE(rc))
     2040        return rc;
    20352041
    20362042    pThis->fBootAccelActive = false;
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r53062 r53407  
    806806    static DECLCALLBACK(int)    i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
    807807
     808    static DECLCALLBACK(int)    i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
     809
    808810    int mcAudioRefs;
    809811    volatile uint32_t mcVRDPClients;
     
    981983    } *mpIfSecKey;
    982984
     985    /** Pointer to the key helpers -> provider (that's us) callbacks. */
     986    struct MYPDMISECKEYHLP : public PDMISECKEYHLP
     987    {
     988        Console *pConsole;
     989    } *mpIfSecKeyHlp;
     990
    983991/* Note: FreeBSD needs this whether netflt is used or not. */
    984992#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r53066 r53407  
    423423    , mBusMgr(NULL)
    424424    , mpIfSecKey(NULL)
     425    , mpIfSecKeyHlp(NULL)
    425426    , mVMStateChangeCallbackDisabled(false)
    426427    , mfUseHostClipboard(true)
     
    467468    pIfSecKey->pConsole                 = this;
    468469    mpIfSecKey = pIfSecKey;
     470
     471    MYPDMISECKEYHLP *pIfSecKeyHlp = (MYPDMISECKEYHLP *)RTMemAllocZ(sizeof(*mpIfSecKeyHlp) + sizeof(Console *));
     472    if (!pIfSecKeyHlp)
     473        return E_OUTOFMEMORY;
     474    pIfSecKeyHlp->pfnKeyMissingNotify   = Console::i_pdmIfSecKeyHlp_KeyMissingNotify;
     475    pIfSecKeyHlp->pConsole              = this;
     476    mpIfSecKeyHlp = pIfSecKeyHlp;
    469477
    470478    return BaseFinalConstruct();
     
    701709        RTMemFree((void *)mpIfSecKey);
    702710        mpIfSecKey = NULL;
     711    }
     712
     713    if (mpIfSecKeyHlp)
     714    {
     715        RTMemFree((void *)mpIfSecKeyHlp);
     716        mpIfSecKeyHlp = NULL;
    703717    }
    704718
     
    44574471                if (pIMedium)
    44584472                {
    4459                     rc = pIMedium->pfnSetSecKeyIf(pIMedium, NULL);
     4473                    rc = pIMedium->pfnSetSecKeyIf(pIMedium, NULL, mpIfSecKeyHlp);
    44604474                    Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
    44614475                }
     
    45744588                    else
    45754589                    {
    4576                         rc = pIMedium->pfnSetSecKeyIf(pIMedium, mpIfSecKey);
     4590                        rc = pIMedium->pfnSetSecKeyIf(pIMedium, mpIfSecKey, mpIfSecKeyHlp);
    45774591                        if (RT_FAILURE(rc))
    45784592                            return setError(E_FAIL, tr("Failed to set the encryption key (%Rrc)"), rc);
     
    82248238        }
    82258239
     8240        case VMSTATE_POWERING_ON:
     8241        {
     8242            /*
     8243             * We have to set the secret key helper interface for the VD drivers to
     8244             * get notified about missing keys.
     8245             */
     8246            that->i_clearDiskEncryptionKeysOnAllAttachments();
     8247            break;
     8248        }
     8249
    82268250        default: /* shut up gcc */
    82278251            break;
     
    88938917    LogRel(("Console: VM runtime error: fatal=%RTbool, errorID=%s message=\"%s\"\n",
    88948918            fFatal, pszErrorId, message.c_str()));
    8895 
    8896     /* Set guest property if the reason of the error is a missing DEK for a disk. */
    8897     if (!RTStrCmp(pszErrorId, "DrvVD_DEKMISSING"))
    8898     {
    8899         that->mMachine->DeleteGuestProperty(Bstr("/VirtualBox/HostInfo/DekMissing").raw());
    8900         that->mMachine->SetGuestProperty(Bstr("/VirtualBox/HostInfo/DekMissing").raw(),
    8901                                          Bstr("1").raw(), Bstr("RDONLYGUEST").raw());
    8902         that->mMachine->SaveSettings();
    8903     }
    8904 
    89058919
    89068920    that->i_onRuntimeError(BOOL(fFatal), Bstr(pszErrorId).raw(), Bstr(message).raw());
     
    1025810272}
    1025910273
     10274/**
     10275 * @interface_method_impl{PDMISECKEYHLP,pfnKeyMissingNotify}
     10276 */
     10277/*static*/ DECLCALLBACK(int)
     10278Console::i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface)
     10279{
     10280    Console *pConsole = ((MYPDMISECKEYHLP *)pInterface)->pConsole;
     10281
     10282    /* Set guest property only, the VM is paused in the media driver calling us. */
     10283    pConsole->mMachine->DeleteGuestProperty(Bstr("/VirtualBox/HostInfo/DekMissing").raw());
     10284    pConsole->mMachine->SetGuestProperty(Bstr("/VirtualBox/HostInfo/DekMissing").raw(),
     10285                                         Bstr("1").raw(), Bstr("RDONLYGUEST").raw());
     10286    pConsole->mMachine->SaveSettings();
     10287
     10288    return VINF_SUCCESS;
     10289}
    1026010290
    1026110291
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r53330 r53407  
    39683968            AssertRCReturn(rc, rc);
    39693969
     3970            /*
     3971             * Make the secret key helper interface known to the VD driver if it is attached,
     3972             * so we can get notified about missing keys.
     3973             */
     3974            PPDMIBASE pIBase = NULL;
     3975            rc = PDMR3QueryDriverOnLun(pUVM, pcszDevice, uInstance, uLUN, "VD", &pIBase);
     3976            if (RT_SUCCESS(rc) && pIBase)
     3977            {
     3978                PPDMIMEDIA pIMedium = (PPDMIMEDIA)pIBase->pfnQueryInterface(pIBase, PDMIMEDIA_IID);
     3979                if (pIMedium)
     3980                {
     3981                    rc = pIMedium->pfnSetSecKeyIf(pIMedium, NULL, mpIfSecKeyHlp);
     3982                    Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED);
     3983                }
     3984            }
     3985
    39703986            /* There is no need to handle removable medium mounting, as we
    39713987             * unconditionally replace everthing including the block driver level.
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