VirtualBox

Changeset 51342 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
May 22, 2014 10:24:53 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
93828
Message:

Main,DrvVD: Interface to pass the keys to the disk encryption module from Main

Location:
trunk/src/VBox/Devices/Storage
Files:
4 edited

Legend:

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

    r51340 r51342  
    57405740        return true;
    57415741    }
     5742    if (rc == VERR_VD_DEK_MISSING)
     5743    {
     5744        /* Error message already set. */
     5745        ASMAtomicCmpXchgBool(&pAhciPort->fRedo, true, false);
     5746        return true;
     5747    }
     5748
    57425749    return false;
    57435750}
  • trunk/src/VBox/Devices/Storage/DevATA.cpp

    r50283 r51342  
    15411541        return true;
    15421542    }
     1543    if (rc == VERR_VD_DEK_MISSING)
     1544    {
     1545        /* Error message already set. */
     1546        pCtl->fRedoIdle = true;
     1547        return true;
     1548    }
     1549
    15431550    return false;
    15441551}
  • trunk/src/VBox/Devices/Storage/DrvSCSI.cpp

    r50089 r51342  
    123123        || rc == VERR_FILE_TOO_BIG
    124124        || rc == VERR_BROKEN_PIPE
    125         || rc == VERR_NET_CONNECTION_REFUSED)
     125        || rc == VERR_NET_CONNECTION_REFUSED
     126        || rc == VERR_VD_DEK_MISSING)
    126127        return true;
    127128
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r51103 r51342  
    186186    /** The block cache handle if configured. */
    187187    PPDMBLKCACHE             pBlkCache;
     188
     189    /** Cryptographic support
     190     * @{ */
     191    /** Used algorithm, NULL means no encryption. */
     192    char                    *pszEncryptionAlgorithm;
     193    /** Config interface for the encryption filter. */
     194    VDINTERFACECONFIG        VDIfCfg;
     195    /** Flag whether the DEK was provided. */
     196    bool                     fDekProvided;
     197    /** Pointer to the key material - temporary. */
     198    const uint8_t           *pbKey;
     199    /** Size of the key material in bytes. */
     200    size_t                   cbKey;
     201    /** @} */
    188202} VBOXDISK, *PVBOXDISK;
    189203
     
    621635}
    622636
     637
     638/*******************************************************************************
     639*   VD Configuration interface implementation for the encryption support       *
     640*******************************************************************************/
     641
     642static bool drvvdCfgEncAreKeysValid(void *pvUser, const char *pszValid)
     643{
     644    return true;
     645}
     646
     647static int drvvdCfgEncQuerySize(void *pvUser, const char *pszName, size_t *pcb)
     648{
     649    PVBOXDISK pThis = (PVBOXDISK)pvUser;
     650    int rc = VINF_SUCCESS;
     651
     652    if (!strcmp(pszName, "Algorithm"))
     653        *pcb = strlen(pThis->pszEncryptionAlgorithm) + 1;
     654    else if (!strcmp(pszName, "Key"))
     655        *pcb = pThis->cbKey;
     656    else
     657        rc = VERR_NOT_SUPPORTED;
     658
     659    return rc;
     660}
     661
     662static int drvvdCfgEncQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString)
     663{
     664    PVBOXDISK pThis = (PVBOXDISK)pvUser;
     665    int rc = VINF_SUCCESS;
     666
     667    if (!strcmp(pszName, "Algorithm"))
     668        rc = RTStrCopy(pszString, cchString, pThis->pszEncryptionAlgorithm);
     669    else
     670        rc = VERR_NOT_SUPPORTED;
     671
     672    return rc;
     673}
     674
     675static int drvvdCfgEncQueryBytes(void *pvUser, const char *pszName, void *pvData, size_t cbData)
     676{
     677    PVBOXDISK pThis = (PVBOXDISK)pvUser;
     678    int rc = VINF_SUCCESS;
     679
     680    if (!strcmp(pszName, "Key"))
     681        if (pThis->cbKey > cbData)
     682            rc = VERR_BUFFER_OVERFLOW;
     683        else
     684            memcpy(pvData, pThis->pbKey, pThis->cbKey);
     685    else
     686        rc = VERR_NOT_SUPPORTED;
     687
     688    return rc;
     689   
     690}
    623691
    624692#ifdef VBOX_WITH_INIP
     
    15051573    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    15061574
     1575    if (   pThis->pszEncryptionAlgorithm
     1576        && !pThis->fDekProvided)
     1577    {
     1578        rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
     1579                                        N_("VD: The DEK for this disk is missing"));
     1580        AssertRC(rc);
     1581        return VERR_VD_DEK_MISSING;
     1582    }
     1583
    15071584    if (!pThis->fBootAccelActive)
    15081585        rc = VDRead(pThis->pDisk, off, pvBuf, cbRead);
     
    15551632    Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d\n%.*Rhxd\n", __FUNCTION__,
    15561633          off, pvBuf, cbWrite, cbWrite, pvBuf));
     1634
     1635    if (   pThis->pszEncryptionAlgorithm
     1636        && !pThis->fDekProvided)
     1637    {
     1638        int rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
     1639                                            N_("VD: The DEK for this disk is missing"));
     1640        AssertRC(rc);
     1641        return VERR_VD_DEK_MISSING;
     1642    }
    15571643
    15581644    /* Invalidate any buffer if boot acceleration is enabled. */
     
    16131699}
    16141700
     1701/** @copydoc PDMIMEDIA::pfnSetKey */
     1702static DECLCALLBACK(int) drvvdSetKey(PPDMIMEDIA pInterface, const uint8_t *pbKey,
     1703                                     size_t cbKey)
     1704{
     1705    LogFlowFunc(("\n"));
     1706    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     1707    int rc = VINF_SUCCESS;
     1708
     1709    if (pThis->pszEncryptionAlgorithm)
     1710    {
     1711        PVDINTERFACE pVDIfFilter = NULL;
     1712
     1713        pThis->pbKey = pbKey;
     1714        pThis->cbKey = cbKey;
     1715
     1716        rc = VDInterfaceAdd(&pThis->VDIfCfg.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
     1717                            pThis, sizeof(VDINTERFACECONFIG), &pVDIfFilter);
     1718        AssertRC(rc);
     1719
     1720        /* Load the crypt filter plugin. */
     1721        rc = VDFilterAdd(pThis->pDisk, "CRYPT", pVDIfFilter);
     1722        if (RT_SUCCESS(rc))
     1723            pThis->fDekProvided = true;
     1724
     1725        pThis->pbKey = NULL;
     1726        pThis->cbKey = 0;
     1727    }
     1728    else
     1729        rc = VERR_NOT_SUPPORTED;
     1730
     1731    LogFlowFunc(("returns %Rrc\n", rc));
     1732    return rc;
     1733}
     1734
    16151735/** @copydoc PDMIMEDIA::pfnGetSize */
    16161736static DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
     
    17741894    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
    17751895
     1896    if (   pThis->pszEncryptionAlgorithm
     1897        && !pThis->fDekProvided)
     1898    {
     1899        rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
     1900                                        N_("VD: The DEK for this disk is missing"));
     1901        AssertRC(rc);
     1902        return VERR_VD_DEK_MISSING;
     1903    }
     1904
    17761905    pThis->fBootAccelActive = false;
    17771906
     
    18031932    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
    18041933
     1934    if (   pThis->pszEncryptionAlgorithm
     1935        && !pThis->fDekProvided)
     1936    {
     1937        rc = PDMDrvHlpVMSetRuntimeError(pThis->pDrvIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DrvVD_DEKMISSING",
     1938                                        N_("VD: The DEK for this disk is missing"));
     1939        AssertRC(rc);
     1940        return VERR_VD_DEK_MISSING;
     1941    }
     1942
    18051943    pThis->fBootAccelActive = false;
    18061944
     
    18862024    int rc = VINF_SUCCESS;
    18872025    PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
     2026
     2027    Assert (!pThis->pszEncryptionAlgorithm);
    18882028
    18892029    switch (enmXferDir)
     
    21732313        pThis->pszBwGroup = NULL;
    21742314    }
     2315    if (pThis->pszEncryptionAlgorithm)
     2316    {
     2317        MMR3HeapFree(pThis->pszEncryptionAlgorithm);
     2318        pThis->pszBwGroup = NULL;
     2319    }
    21752320}
    21762321
     
    22082353    pThis->uMergeSource                 = VD_LAST_IMAGE;
    22092354    pThis->uMergeTarget                 = VD_LAST_IMAGE;
     2355    pThis->pszEncryptionAlgorithm       = NULL;
     2356    pThis->fDekProvided                 = false;
    22102357
    22112358    /* IMedia */
     
    22142361    pThis->IMedia.pfnFlush              = drvvdFlush;
    22152362    pThis->IMedia.pfnMerge              = drvvdMerge;
     2363    pThis->IMedia.pfnSetKey             = drvvdSetKey;
    22162364    pThis->IMedia.pfnGetSize            = drvvdGetSize;
    22172365    pThis->IMedia.pfnGetSectorSize      = drvvdGetSectorSize;
     
    26122760                            pCfgVDConfig, sizeof(VDINTERFACECONFIG), &pImage->pVDIfsImage);
    26132761        AssertRC(rc);
     2762
     2763        /* Check VDConfig for encryption config. */
     2764        if (pCfgVDConfig)
     2765        {
     2766            rc = CFGMR3QueryStringAlloc(pCfgVDConfig, "EncryptionAlgorithm", &pThis->pszEncryptionAlgorithm);
     2767            if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
     2768            {
     2769                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     2770                                      N_("DrvVD: Configuration error: Querying \"EncryptionAlgorithm\" as string failed"));
     2771                break;
     2772            }
     2773            else
     2774                rc = VINF_SUCCESS;
     2775        }
     2776
     2777        if (pThis->pszEncryptionAlgorithm)
     2778        {
     2779            /* Setup VDConfig interface for disk encryption support. */
     2780            pThis->VDIfCfg.pfnAreKeysValid = drvvdCfgEncAreKeysValid;
     2781            pThis->VDIfCfg.pfnQuerySize    = drvvdCfgEncQuerySize;
     2782            pThis->VDIfCfg.pfnQuery        = drvvdCfgEncQuery;
     2783            pThis->VDIfCfg.pfnQueryBytes   = drvvdCfgEncQueryBytes;
     2784        }
    26142785
    26152786        /* Unconditionally insert the TCPNET interface, don't bother to check
     
    28503021        && !pThis->fShareable
    28513022        && !fDiscard
     3023        && !pThis->pszEncryptionAlgorithm /* Disk encryption disables the block cache for security reasons */
    28523024        && RT_SUCCESS(rc))
    28533025    {
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