VirtualBox

Changeset 53407 in vbox for trunk/src/VBox/Main/src-client


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/Main/src-client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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