VirtualBox

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


Ignore:
Timestamp:
May 24, 2013 9:25:35 AM (12 years ago)
Author:
vboxsync
Message:

Devices/LsiLogic: Limit the amount of memory the guest can allocate for the diagnostic memory to 1MB, prevents malicous guests from DOSing the host my llocating loads of memory

File:
1 edited

Legend:

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

    r45970 r46253  
    6767#define LSILOGIC_MAX_ALLOC_TOO_MUCH 20
    6868
     69/** Maximum size of the memory regions (prevents teh guest from DOSing the host by
     70 * allocating loadds of memory). */
     71#define LSILOGIC_MEMORY_REGIONS_MAX (_1M)
     72
    6973/*******************************************************************************
    7074*   Structures and Typedefs                                                    *
     
    337341    /** Current address to read from or write to in the diagnostic memory region. */
    338342    uint32_t                         u32DiagMemAddr;
    339 
     343    /** Current size of the memory regions. */
     344    uint32_t                         cbMemRegns;
     345
     346#if HC_ARCH_BITS ==32
    340347    uint32_t                         u32Padding3;
     348#endif
    341349
    342350    union
     
    786794        RTMemFree(pIt);
    787795    }
     796    pThis->cbMemRegns = 0;
    788797}
    789798
     
    878887            uint32_t cRegionSizeOld = (pRegion->u32AddrEnd - pRegion->u32AddrStart) / 4 + 1;
    879888            uint32_t cRegionSizeNew = cRegionSizeOld + 512;
    880             PLSILOGICMEMREGN pRegionNew = (PLSILOGICMEMREGN)RTMemRealloc(pRegion, RT_OFFSETOF(LSILOGICMEMREGN, au32Data[cRegionSizeNew]));
    881 
    882             if (pRegionNew)
     889
     890            if (pThis->cbMemRegns + 512 * sizeof(uint32_t) < LSILOGIC_MEMORY_REGIONS_MAX)
    883891            {
    884                 pRegion = pRegionNew;
    885                 memset(&pRegion->au32Data[cRegionSizeOld], 0, 512 * sizeof(uint32_t));
    886                 pRegion->au32Data[cRegionSizeOld] = u32Data;
    887                 pRegion->u32AddrEnd = pRegion->u32AddrStart + (cRegionSizeNew - 1) * sizeof(uint32_t);
    888             }
    889             /* else: Silently fail, there is nothing we can do here and the guest might work nevertheless. */
    890 
    891             lsilogicR3MemRegionInsert(pThis, pRegion);
    892         }
    893         else
    894         {
    895             /* Create completely new. */
    896             pRegion = (PLSILOGICMEMREGN)RTMemAllocZ(RT_OFFSETOF(LSILOGICMEMREGN, au32Data[512]));
    897             if (pRegion)
    898             {
    899                 pRegion->u32AddrStart = pThis->u32DiagMemAddr;
    900                 pRegion->u32AddrEnd   = pRegion->u32AddrStart + (512 - 1) * sizeof(uint32_t);
    901                 pRegion->au32Data[0]  = u32Data;
     892                PLSILOGICMEMREGN pRegionNew = (PLSILOGICMEMREGN)RTMemRealloc(pRegion, RT_OFFSETOF(LSILOGICMEMREGN, au32Data[cRegionSizeNew]));
     893
     894                if (pRegionNew)
     895                {
     896                    pRegion = pRegionNew;
     897                    memset(&pRegion->au32Data[cRegionSizeOld], 0, 512 * sizeof(uint32_t));
     898                    pRegion->au32Data[cRegionSizeOld] = u32Data;
     899                    pRegion->u32AddrEnd = pRegion->u32AddrStart + (cRegionSizeNew - 1) * sizeof(uint32_t);
     900                    pThis->cbMemRegns += 512 * sizeof(uint32_t);
     901                }
     902                /* else: Silently fail, there is nothing we can do here and the guest might work nevertheless. */
    902903
    903904                lsilogicR3MemRegionInsert(pThis, pRegion);
    904905            }
    905             /* else: Silently fail, there is nothing we can do here and the guest might work nevertheless. */
     906        }
     907        else
     908        {
     909            if (pThis->cbMemRegns + 512 * sizeof(uint32_t) < LSILOGIC_MEMORY_REGIONS_MAX)
     910            {
     911                /* Create completely new. */
     912                pRegion = (PLSILOGICMEMREGN)RTMemAllocZ(RT_OFFSETOF(LSILOGICMEMREGN, au32Data[512]));
     913                if (pRegion)
     914                {
     915                    pRegion->u32AddrStart = pThis->u32DiagMemAddr;
     916                    pRegion->u32AddrEnd   = pRegion->u32AddrStart + (512 - 1) * sizeof(uint32_t);
     917                    pRegion->au32Data[0]  = u32Data;
     918                    pThis->cbMemRegns += 512 * sizeof(uint32_t);
     919
     920                    lsilogicR3MemRegionInsert(pThis, pRegion);
     921                }
     922                /* else: Silently fail, there is nothing we can do here and the guest might work nevertheless. */
     923            }
    906924        }
    907925
     
    46394657                    SSMR3GetMem(pSSM, &pRegion->au32Data[0], cRegion * sizeof(uint32_t));
    46404658                    lsilogicR3MemRegionInsert(pThis, pRegion);
     4659                    pThis->cbMemRegns += cRegion * sizeof(uint32_t);
    46414660                }
    46424661                else
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