VirtualBox

Changeset 51868 in vbox


Ignore:
Timestamp:
Jul 4, 2014 1:35:22 PM (11 years ago)
Author:
vboxsync
Message:

Page hash fixes. Somehow using the wrong algorithm for determining how much to read from disk.

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r51857 r51868  
    289289        $(VBOX_PATH_RUNTIME_SRC)/common/misc/RTAssertMsg2Weak.cpp \
    290290        $(VBOX_PATH_RUNTIME_SRC)/common/misc/RTAssertMsg2WeakV.cpp \
     291        $(VBOX_PATH_RUNTIME_SRC)/common/misc/zero.asm \
    291292        $(VBOX_PATH_RUNTIME_SRC)/common/string/memchr.asm \
    292293        $(VBOX_PATH_RUNTIME_SRC)/common/string/memcmp.asm \
  • trunk/src/VBox/Runtime/Makefile.kmk

    r51862 r51868  
    433433        common/misc/term.cpp \
    434434        common/misc/uri.cpp \
     435        common/misc/zero.asm \
    435436        common/net/netaddrstr2.cpp \
    436437        common/net/macstr.cpp \
     
    20562057        common/path/RTPathChangeToUnixSlashes.cpp \
    20572058        common/math/bignum.cpp \
     2059        common/misc/zero.asm \
    20582060        common/string/RTStrPrintHexBytes.cpp \
    20592061        common/string/RTUtf16Copy.cpp \
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r51862 r51868  
    4343#include <iprt/string.h>
    4444#ifndef IPRT_WITHOUT_LDR_VERIFY
     45#include <iprt/zero.h>
    4546# include <iprt/crypto/pkcs7.h>
    4647# include <iprt/crypto/spc.h>
     
    21532154    if (cPages * (cbHash + 4) != pAttrib->u.pPageHashes->RawData.Asn1Core.cb)
    21542155        return RTErrInfoSetF(pErrInfo, VERR_LDRVI_PAGE_HASH_TAB_SIZE_OVERFLOW,
    2155                              "Page Hashes V2 size issue: cb=%#x cbHash=%#x",
     2156                             "Page hashes size issue: cb=%#x cbHash=%#x",
    21562157                             pAttrib->u.pPageHashes->RawData.Asn1Core.cb, cbHash);
    21572158
     
    21642165
    21652166    uint32_t        offPrev    = 0;
     2167#ifdef COMPLICATED_AND_WRONG
    21662168    uint32_t        offSectEnd = pModPe->cbHeaders;
    21672169    uint32_t        iSh        = UINT32_MAX;
     2170#endif
    21682171    uint8_t const  *pbHashTab  = pAttrib->u.pPageHashes->RawData.Asn1Core.uData.pu8;
    21692172    for (uint32_t iPage = 0; iPage < cPages; iPage++)
    21702173    {
    21712174        /* Decode the page offset. */
    2172         uint32_t const offFile = RT_MAKE_U32_FROM_U8(pbHashTab[0], pbHashTab[1], pbHashTab[2], pbHashTab[3]);
    2173         if (offFile >= SpecialPlaces.cbToHash)
     2175        uint32_t const offPageInFile = RT_MAKE_U32_FROM_U8(pbHashTab[0], pbHashTab[1], pbHashTab[2], pbHashTab[3]);
     2176        if (offPageInFile >= SpecialPlaces.cbToHash)
    21742177        {
    21752178            /* The last entry is zero. */
    2176             if (   offFile  == SpecialPlaces.cbToHash
     2179            if (   offPageInFile == SpecialPlaces.cbToHash
    21772180                && iPage + 1 == cPages
    21782181                && ASMMemIsAll8(pbHashTab + 4, cbHash, 0) == NULL)
     
    21802183            return RTErrInfoSetF(pErrInfo, VERR_LDRVI_PAGE_HASH_TAB_TOO_LONG,
    21812184                                 "Page hash entry #%u is beyond the signature table start: %#x, %#x",
    2182                                  iPage, offFile, SpecialPlaces.cbToHash);
    2183         }
    2184         if (offFile < offPrev)
     2185                                 iPage, offPageInFile, SpecialPlaces.cbToHash);
     2186        }
     2187        if (offPageInFile < offPrev)
    21852188            return RTErrInfoSetF(pErrInfo, VERR_LDRVI_PAGE_HASH_TAB_NOT_STRICTLY_SORTED,
    21862189                                 "Page hash table is not strictly sorted: entry #%u @%#x, previous @%#x\n",
    2187                                  iPage, offFile, offPrev);
    2188 
     2190                                 iPage, offPageInFile, offPrev);
     2191
     2192#ifdef COMPLICATED_AND_WRONG
    21892193        /* Figure out how much to read and how much to zero.  Need keep track
    21902194           of the on-disk section boundraries. */
    2191         if (offFile >= offSectEnd)
     2195        if (offPageInFile >= offSectEnd)
    21922196        {
    21932197            iSh++;
    21942198            if (   iSh < pModPe->cSections
    2195                 && offFile - pModPe->paSections[iSh].PointerToRawData < pModPe->paSections[iSh].SizeOfRawData)
     2199                && offPageInFile - pModPe->paSections[iSh].PointerToRawData < pModPe->paSections[iSh].SizeOfRawData)
    21962200                offSectEnd = pModPe->paSections[iSh].PointerToRawData + pModPe->paSections[iSh].SizeOfRawData;
    21972201            else
     
    21992203                iSh = 0;
    22002204                while (   iSh < pModPe->cSections
    2201                        && offFile - pModPe->paSections[iSh].PointerToRawData >= pModPe->paSections[iSh].SizeOfRawData)
     2205                       && offPageInFile - pModPe->paSections[iSh].PointerToRawData >= pModPe->paSections[iSh].SizeOfRawData)
    22022206                    iSh++;
    22032207                if (iSh < pModPe->cSections)
     
    22052209                else
    22062210                    return RTErrInfoSetF(pErrInfo, VERR_PAGE_HASH_TAB_HASHES_NON_SECTION_DATA,
    2207                                          "Page hash entry #%u isn't in any section: %#x", iPage, offFile);
    2208             }
    2209         }
    2210 
    2211         uint32_t cbRead = _4K;
    2212         if (offFile + cbRead > offSectEnd)
    2213             cbRead = offSectEnd - offFile;
    2214 
    2215         if (offFile + cbRead > SpecialPlaces.cbToHash)
    2216             cbRead = SpecialPlaces.cbToHash - offFile;
     2211                                         "Page hash entry #%u isn't in any section: %#x", iPage, offPageInFile);
     2212            }
     2213        }
     2214
     2215#else
     2216        /* Figure out how much to read and how much take as zero.  Use the next
     2217           page offset and the signature as upper boundraries.  */
     2218#endif
     2219        uint32_t cbPageInFile = _4K;
     2220#ifdef COMPLICATED_AND_WRONG
     2221        if (offPageInFile + cbPageInFile > offSectEnd)
     2222            cbPageInFile = offSectEnd - offPageInFile;
     2223#else
     2224        if (iPage + 1 < cPages)
     2225        {
     2226            uint32_t offNextPage = RT_MAKE_U32_FROM_U8(pbHashTab[0 + 4 + cbHash], pbHashTab[1 + 4 + cbHash],
     2227                                                       pbHashTab[2 + 4 + cbHash], pbHashTab[3 + 4 + cbHash]);
     2228            if (offNextPage - offPageInFile < cbPageInFile)
     2229                cbPageInFile = offNextPage - offPageInFile;
     2230        }
     2231#endif
     2232
     2233        if (offPageInFile + cbPageInFile > SpecialPlaces.cbToHash)
     2234            cbPageInFile = SpecialPlaces.cbToHash - offPageInFile;
    22172235
    22182236        /* Did we get a cache hit? */
    22192237        uint8_t *pbCur = (uint8_t *)pvScratch;
    2220         if (   offFile + cbRead <= offScratchRead + cbScratchRead
    2221             && offFile          >= offScratchRead)
    2222             pbCur += offFile - offScratchRead;
     2238        if (   offPageInFile + cbPageInFile <= offScratchRead + cbScratchRead
     2239            && offPageInFile          >= offScratchRead)
     2240            pbCur += offPageInFile - offScratchRead;
    22232241        /* Missed, read more. */
    22242242        else
    22252243        {
    2226             offScratchRead = offFile;
    2227             cbScratchRead  = offSectEnd - offFile;
     2244            offScratchRead = offPageInFile;
     2245#ifdef COMPLICATED_AND_WRONG
     2246            cbScratchRead  = offSectEnd - offPageInFile;
     2247#else
     2248            cbScratchRead  = SpecialPlaces.cbToHash - offPageInFile;
     2249#endif
    22282250            if (cbScratchRead > cbScratchReadMax)
    22292251                cbScratchRead = cbScratchReadMax;
     
    22352257        }
    22362258
    2237         /* Zero any additional bytes in the page. */
    2238         if (cbRead != _4K)
    2239             memset(pbCur + cbRead, 0, _4K - cbRead);
    2240 
    22412259        /*
    22422260         * Hash it.
     
    22472265
    22482266        /* Deal with special places. */
    2249         uint32_t       cbLeft = _4K;
    2250         if (offFile < SpecialPlaces.offEndSpecial)
    2251         {
    2252             uint32_t off = offFile;
     2267        uint32_t       cbLeft = cbPageInFile;
     2268        if (offPageInFile < SpecialPlaces.offEndSpecial)
     2269        {
     2270            uint32_t off = offPageInFile;
    22532271            if (off < SpecialPlaces.offCksum)
    22542272            {
     
    22912309
    22922310        rtLdrPE_HashUpdate(&HashCtx, enmDigest, pbCur, cbLeft);
     2311        if (cbPageInFile < _4K)
     2312            rtLdrPE_HashUpdate(&HashCtx, enmDigest, &g_abRTZero4K[cbPageInFile], _4K - cbPageInFile);
    22932313
    22942314        /*
     
    23012321        if (memcmp(pbHashTab, &HashRes, cbHash) != 0)
    23022322            return RTErrInfoSetF(pErrInfo, VERR_LDRVI_PAGE_HASH_MISMATCH,
    2303                                  "Page hash v2 failed for page #%u, @%#x, %#x bytes: %.*Rhxs != %.*Rhxs",
    2304                                  iPage, offFile, cbRead, (size_t)cbHash, pbHashTab, (size_t)cbHash, &HashRes);
     2323                                 "Page hash failed for page #%u, @%#x, %#x bytes: %.*Rhxs != %.*Rhxs",
     2324                                 iPage, offPageInFile, cbPageInFile, (size_t)cbHash, pbHashTab, (size_t)cbHash, &HashRes);
    23052325        pbHashTab += cbHash;
    2306         offPrev = offFile;
     2326        offPrev = offPageInFile;
    23072327    }
    23082328
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