VirtualBox

Changeset 25341 in vbox for trunk/src


Ignore:
Timestamp:
Dec 12, 2009 2:33:26 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55936
Message:

ldrPE.cpp: Added WIN_CERTIFICATE and added very basic verification of it. (IMAGE_DIRECTORY_ENTRY_SECURITY)

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r25340 r25341  
    11181118                Log(("rtldrPEOpen: %s: dir no. %d (SECURITY) VirtualAddress=%#x Size=%#x is not supported!!!\n",
    11191119                     pszLogName, i, pDir->VirtualAddress, pDir->Size));
     1120                if (pDir->Size < sizeof(WIN_CERTIFICATE))
     1121                {
     1122                    Log(("rtldrPEOpen: %s: Security directory is too small: %#x bytes\n", pszLogName, i, pDir->Size));
     1123                    return VERR_LDRPE_MALFORMED_CERT;
     1124                }
     1125                if (pDir->Size >= _1M)
     1126                {
     1127                    Log(("rtldrPEOpen: %s: Security directory is too large: %#x bytes\n", pszLogName, i, pDir->Size));
     1128                    return VERR_LDRPE_MALFORMED_CERT;
     1129                }
     1130                if (pDir->VirtualAddress & 7)
     1131                {
     1132                    Log(("rtldrPEOpen: %s: Security directory is misaligned: %#x\n", pszLogName, i, pDir->VirtualAddress));
     1133                    return VERR_LDRPE_MALFORMED_CERT;
     1134                }
    11201135                break;
    11211136
     
    14131428        }
    14141429    }
     1430
     1431    /*
     1432     * If the image is signed, take a look at the signature.
     1433     */
     1434    Dir = pOptHdr->DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY];
     1435    if (Dir.Size)
     1436    {
     1437        PWIN_CERTIFICATE pFirst = (PWIN_CERTIFICATE)RTMemTmpAlloc(Dir.Size);
     1438        if (!pFirst)
     1439            return VERR_NO_TMP_MEMORY;
     1440        int rc = pModPe->pReader->pfnRead(pModPe->pReader, pFirst, Dir.Size, Dir.VirtualAddress);
     1441        if (RT_SUCCESS(rc))
     1442        {
     1443            uint32_t         off  = 0;
     1444            PWIN_CERTIFICATE pCur = pFirst;
     1445            do
     1446            {
     1447                /* validate the members. */
     1448                uint32_t const cbCur = RT_ALIGN_32(pCur->dwLength, 8);
     1449                if (   cbCur < sizeof(WIN_CERTIFICATE)
     1450                    || cbCur + off > RT_ALIGN_32(Dir.Size, 8))
     1451                {
     1452                    Log(("rtldrPEOpen: %s: cert at %#x/%#x: dwLength=%#x\n", pszLogName, off, Dir.Size, pCur->dwLength));
     1453                    rc = VERR_LDRPE_MALFORMED_CERT;
     1454                    break;
     1455                }
     1456                if (    pCur->wRevision != WIN_CERT_REVISION_2_0
     1457                    &&  pCur->wRevision != WIN_CERT_REVISION_1_0)
     1458                {
     1459                    Log(("rtldrPEOpen: %s: cert at %#x/%#x: wRevision=%#x\n", pszLogName, off, Dir.Size, pCur->wRevision));
     1460                    rc = pCur->wRevision >= WIN_CERT_REVISION_1_0 ? VERR_LDRPE_CERT_UNSUPPORTED : VERR_LDRPE_CERT_MALFORMED;
     1461                    break;
     1462                }
     1463                if (    pCur->wCertificateType != WIN_CERT_TYPE_PKCS_SIGNED_DATA
     1464                    &&  pCur->wCertificateType != WIN_CERT_TYPE_X509
     1465                    /*&&  pCur->wCertificateType != WIN_CERT_TYPE_RESERVED_1*/
     1466                    /*&&  pCur->wCertificateType != WIN_CERT_TYPE_TS_STACK_SIGNED*/
     1467                    &&  pCur->wCertificateType != WIN_CERT_TYPE_EFI_PKCS115
     1468                    &&  pCur->wCertificateType != WIN_CERT_TYPE_EFI_GUID
     1469                   )
     1470                {
     1471                    Log(("rtldrPEOpen: %s: cert at %#x/%#x: wRevision=%#x\n", pszLogName, off, Dir.Size, pCur->wRevision));
     1472                    rc = pCur->wCertificateType ? VERR_LDRPE_CERT_UNSUPPORTED : VERR_LDRPE_CERT_MALFORMED;
     1473                    break;
     1474                }
     1475
     1476                /** @todo Rainy Day: Implement further verfication using openssl. */
     1477
     1478                /* next */
     1479                off += cbCur;
     1480                pCur = (PWIN_CERTIFICATE)((uint8_t *)pCur + cbCur);
     1481            } while (off < Dir.Size);
     1482        }
     1483        RTMemTmpFree(pFirst);
     1484        if (RT_FAILURE(rc))
     1485            return rc;
     1486    }
     1487
     1488
    14151489    return VINF_SUCCESS;
    14161490}
  • trunk/src/VBox/Runtime/include/internal/ldrPE.h

    r24106 r25341  
    196196#define  IMAGE_DEBUG_TYPE_BORLAND  0x9
    197197#define  IMAGE_DEBUG_TYPE_RESERVED10  0x10
     198
     199/* security directory */
     200#define  WIN_CERT_REVISION_1_0  UINT16_C(0x0100)
     201#define  WIN_CERT_REVISION_2_0  UINT16_C(0x0200)
     202
     203#define  WIN_CERT_TYPE_X509  UINT16_C(1)
     204#define  WIN_CERT_TYPE_PKCS_SIGNED_DATA  UINT16_C(2)
     205#define  WIN_CERT_TYPE_RESERVED_1  UINT16_C(3)
     206#define  WIN_CERT_TYPE_TS_STACK_SIGNED  UINT16_C(4)
     207#define  WIN_CERT_TYPE_EFI_PKCS115 UINT16_C(0x0ef0)
     208#define  WIN_CERT_TYPE_EFI_GUID UINT16_C(0x0ef1)
    198209
    199210
     
    468479typedef IMAGE_DEBUG_DIRECTORY *PIMAGE_DEBUG_DIRECTORY;
    469480
     481
     482typedef struct WIN_CERTIFICATE
     483{
     484    uint32_t    dwLength;
     485    uint16_t    wRevision;
     486    uint16_t    wCertificateType;
     487    uint8_t     bCertificate[8];
     488} WIN_CERTIFICATE;
     489typedef WIN_CERTIFICATE *PWIN_CERTIFICATE;
     490
    470491#pragma pack()
    471492
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