VirtualBox

Changeset 27404 in vbox


Ignore:
Timestamp:
Mar 16, 2010 1:34:17 PM (15 years ago)
Author:
vboxsync
Message:

alloc-ef.cpp: fix fence in front case no man's area filling (had a rounding error leading to heap corruption), and additionally fill and check the alignment padding area after the allocated buffer in the fence after the block case.

File:
1 edited

Legend:

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

    r27297 r27404  
    292292#endif
    293293    }
    294     cb = RT_ALIGN_Z(cb, RTALLOC_EFENCE_ALIGNMENT);
     294#ifndef RTALLOC_EFENCE_IN_FRONT
     295    /* Alignment decreases fence accuracy, but this is at least partially
     296     * counteracted by filling and checking the alignment padding. When the
     297     * fence is in front then then no extra alignment is needed. */
     298    size_t cbAlign = RT_ALIGN_Z(cb, RTALLOC_EFENCE_ALIGNMENT);
     299#endif
    295300
    296301#ifdef RTALLOC_EFENCE_TRACE
     
    321326        void *pv = (char *)pvEFence + RTALLOC_EFENCE_SIZE;
    322327#ifdef RTALLOC_EFENCE_NOMAN_FILLER
    323         memset((char *)pv + cb, RTALLOC_EFENCE_NOMAN_FILLER, PAGE_SIZE - cb % PAGE_SIZE);
     328        memset((char *)pv + cb, RTALLOC_EFENCE_NOMAN_FILLER, cbBlock - RTALLOC_EFENCE_SIZE - cb);
    324329#endif
    325330        #else
    326331        void *pvEFence = (char *)pvBlock + (cbBlock - RTALLOC_EFENCE_SIZE);
    327         void *pv = (char *)pvEFence - cb;
     332        void *pv = (char *)pvEFence - cbAlign;
    328333#ifdef RTALLOC_EFENCE_NOMAN_FILLER
    329         memset(pvBlock, RTALLOC_EFENCE_NOMAN_FILLER, cbBlock - RTALLOC_EFENCE_SIZE - cb);
     334        memset(pvBlock, RTALLOC_EFENCE_NOMAN_FILLER, cbBlock - RTALLOC_EFENCE_SIZE - cbAlign);
     335        memset((char *)pv + cb, RTALLOC_EFENCE_NOMAN_FILLER, cbAlign - cb);
    330336#endif
    331337        #endif
     
    396402         */
    397403# ifdef RTALLOC_EFENCE_IN_FRONT
    398         void *pvNoMan = (char *)pv + pBlock->cb;
    399 # else
    400         void *pvNoMan = (void *)((uintptr_t)pv & ~PAGE_OFFSET_MASK);
    401 # endif
    402         void *p = ASMMemIsAll8(pvNoMan,
     404        void *p = ASMMemIsAll8((char *)pv + pBlock->cb,
    403405                               RT_ALIGN_Z(pBlock->cb, PAGE_SIZE) - pBlock->cb,
    404406                               RTALLOC_EFENCE_NOMAN_FILLER);
     407# else
     408        /* Alignment must match allocation alignment in rtMemAlloc(). */
     409        size_t cbAlign = RT_ALIGN_Z(pBlock->cb, RTALLOC_EFENCE_ALIGNMENT);
     410        void *p = ASMMemIsAll8((char *)pv + pBlock->cb,
     411                               cbAlign - pBlock->cb,
     412                               RTALLOC_EFENCE_NOMAN_FILLER);
     413        if (p)
     414            RTAssertDoPanic();
     415        p = ASMMemIsAll8((void *)((uintptr_t)pv & ~PAGE_OFFSET_MASK),
     416                         RT_ALIGN_Z(cbAlign, PAGE_SIZE) - cbAlign,
     417                         RTALLOC_EFENCE_NOMAN_FILLER);
     418# endif
    405419        if (p)
    406420            RTAssertDoPanic();
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