VirtualBox

Changeset 73703 in vbox


Ignore:
Timestamp:
Aug 16, 2018 9:27:22 AM (6 years ago)
Author:
vboxsync
Message:

IPRT/r3/memsafer: Switched to individual scrambling words for each allocation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/memsafer-r3.cpp

    r69111 r73703  
    8787    /** The allocator used for this node. */
    8888    RTMEMSAFERALLOCATOR     enmAllocator;
     89    /** XOR scrambler value for memory. */
     90    uintptr_t               uScramblerXor;
    8991} RTMEMSAFERNODE;
    9092/** Pointer to an allocation tracking node. */
     
    101103/** Tree of allocation nodes. */
    102104static AVLPVTREE    g_pMemSaferTree;
    103 /** XOR scrambler value for memory. */
    104 static uintptr_t    g_uMemSaferScramblerXor;
    105105/** XOR scrambler value pointers. */
    106106static uintptr_t    g_uMemSaferPtrScramblerXor;
     
    116116    RT_NOREF_PV(pvUserIgnore);
    117117
    118     g_uMemSaferScramblerXor = (uintptr_t)RTRandU64();
    119118    g_uMemSaferPtrScramblerXor = (uintptr_t)RTRandU64();
    120119    g_cMemSaferPtrScramblerRotate = RTRandU32Ex(0, ARCH_BITS - 1);
     
    203202RTDECL(int) RTMemSaferScramble(void *pv, size_t cb)
    204203{
    205 #ifdef RT_STRICT
    206204    PRTMEMSAFERNODE pThis = rtMemSaferNodeLookup(pv);
    207205    AssertReturn(pThis, VERR_INVALID_POINTER);
    208206    AssertMsgReturn(cb == pThis->cbUser, ("cb=%#zx != %#zx\n", cb, pThis->cbUser), VERR_INVALID_PARAMETER);
    209 #endif
     207
     208    /* First time we get a new xor value. */
     209    if (!pThis->uScramblerXor)
     210        pThis->uScramblerXor = (uintptr_t)RTRandU64();
    210211
    211212    /* Note! This isn't supposed to be safe, just less obvious. */
     
    214215    while (cb > 0)
    215216    {
    216         *pu ^= g_uMemSaferScramblerXor;
     217        *pu ^= pThis->uScramblerXor;
    217218        pu++;
    218219        cb -= sizeof(*pu);
     
    226227RTDECL(int) RTMemSaferUnscramble(void *pv, size_t cb)
    227228{
    228 #ifdef RT_STRICT
    229229    PRTMEMSAFERNODE pThis = rtMemSaferNodeLookup(pv);
    230230    AssertReturn(pThis, VERR_INVALID_POINTER);
    231231    AssertMsgReturn(cb == pThis->cbUser, ("cb=%#zx != %#zx\n", cb, pThis->cbUser), VERR_INVALID_PARAMETER);
    232 #endif
    233232
    234233    /* Note! This isn't supposed to be safe, just less obvious. */
     
    237236    while (cb > 0)
    238237    {
    239         *pu ^= g_uMemSaferScramblerXor;
     238        *pu ^= pThis->uScramblerXor;
    240239        pu++;
    241240        cb -= sizeof(*pu);
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