VirtualBox

Changeset 81587 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Oct 30, 2019 1:07:15 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134334
Message:

IPRT/memobj-r0drv-linux.c: Don't mark allocations as executable unless requested (linux < 2.4.22 only). Made the MY_SET_PAGES_EXEC macros be undefined on 5.4.0 and later since they should not be engaged there. (untested) ticketref:18945

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c

    r80327 r81587  
    8787     * This means it has to be given back as one chunk. */
    8888    bool                fContiguous;
     89    /** Set if executable allocation. */
     90    bool                fExecutable;
    8991    /** Set if we've vmap'ed the memory into ring-0. */
    9092    bool                fMappedToRing0;
     
    290292 * @param   fFlagsLnx   The page allocation flags (GPFs).
    291293 * @param   fContiguous Whether the allocation must be contiguous.
     294 * @param   fExecutable Whether the memory must be executable.
    292295 * @param   rcNoMem     What to return when we're out of pages.
    293296 */
    294297static int rtR0MemObjLinuxAllocPages(PRTR0MEMOBJLNX *ppMemLnx, RTR0MEMOBJTYPE enmType, size_t cb,
    295                                      size_t uAlignment, gfp_t fFlagsLnx, bool fContiguous, int rcNoMem)
     298                                     size_t uAlignment, gfp_t fFlagsLnx, bool fContiguous, bool fExecutable, int rcNoMem)
    296299{
    297300    size_t          iPage;
     
    372375    {
    373376        pMemLnx->apPages[iPage] = &paPages[iPage];
    374         MY_SET_PAGES_EXEC(pMemLnx->apPages[iPage], 1);
     377        if (fExecutable)
     378            MY_SET_PAGES_EXEC(pMemLnx->apPages[iPage], 1);
    375379        if (PageHighMem(pMemLnx->apPages[iPage]))
    376380            BUG();
     
    380384#endif /* < 2.4.22 */
    381385    pMemLnx->fContiguous = fContiguous;
     386    pMemLnx->fExecutable = fExecutable;
    382387
    383388#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
     
    410415             */
    411416            printk("rtR0MemObjLinuxAllocPages(cb=0x%lx, uAlignment=0x%lx): alloc_pages(..., %d) returned physical memory at 0x%lx!\n",
    412                     (unsigned long)cb, (unsigned long)uAlignment, rtR0MemObjLinuxOrder(cPages), (unsigned long)page_to_phys(pMemLnx->apPages[0]));
     417                   (unsigned long)cb, (unsigned long)uAlignment, rtR0MemObjLinuxOrder(cPages), (unsigned long)page_to_phys(pMemLnx->apPages[0]));
    413418            rtR0MemObjLinuxFreePages(pMemLnx);
    414419            return rcNoMem;
     
    439444        {
    440445#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
    441             /*
    442              * See SetPageReserved() in rtR0MemObjLinuxAllocPages()
    443              */
     446            /* See SetPageReserved() in rtR0MemObjLinuxAllocPages() */
    444447            ClearPageReserved(pMemLnx->apPages[iPage]);
    445448#endif
    446 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
    447 #else
    448             MY_SET_PAGES_NOEXEC(pMemLnx->apPages[iPage], 1);
     449#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 22)
     450            if (pMemLnx->fExecutable)
     451                MY_SET_PAGES_NOEXEC(pMemLnx->apPages[iPage], 1);
    449452#endif
    450453        }
     
    663666#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
    664667    rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_PAGE, cb, PAGE_SIZE, GFP_HIGHUSER,
    665                                    false /* non-contiguous */, VERR_NO_MEMORY);
     668                                   false /* non-contiguous */, fExecutable, VERR_NO_MEMORY);
    666669#else
    667670    rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_PAGE, cb, PAGE_SIZE, GFP_USER,
    668                                    false /* non-contiguous */, VERR_NO_MEMORY);
     671                                   false /* non-contiguous */, fExecutable, VERR_NO_MEMORY);
    669672#endif
    670673    if (RT_SUCCESS(rc))
     
    697700    /* ZONE_DMA32: 0-4GB */
    698701    rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_LOW, cb, PAGE_SIZE, GFP_DMA32,
    699                                    false /* non-contiguous */, VERR_NO_LOW_MEMORY);
     702                                   false /* non-contiguous */, fExecutable, VERR_NO_LOW_MEMORY);
    700703    if (RT_FAILURE(rc))
    701704#endif
     
    703706        /* ZONE_DMA: 0-16MB */
    704707        rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_LOW, cb, PAGE_SIZE, GFP_DMA,
    705                                        false /* non-contiguous */, VERR_NO_LOW_MEMORY);
     708                                       false /* non-contiguous */, fExecutable, VERR_NO_LOW_MEMORY);
    706709#else
    707710# ifdef CONFIG_X86_PAE
     
    709712        /* ZONE_NORMAL: 0-896MB */
    710713        rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_LOW, cb, PAGE_SIZE, GFP_USER,
    711                                        false /* non-contiguous */, VERR_NO_LOW_MEMORY);
     714                                       false /* non-contiguous */, fExecutable, VERR_NO_LOW_MEMORY);
    712715#endif
    713716    if (RT_SUCCESS(rc))
     
    739742    /* ZONE_DMA32: 0-4GB */
    740743    rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_DMA32,
    741                                    true /* contiguous */, VERR_NO_CONT_MEMORY);
     744                                   true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY);
    742745    if (RT_FAILURE(rc))
    743746#endif
     
    745748        /* ZONE_DMA: 0-16MB */
    746749        rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_DMA,
    747                                        true /* contiguous */, VERR_NO_CONT_MEMORY);
     750                                       true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY);
    748751#else
    749752        /* ZONE_NORMAL (32-bit hosts): 0-896MB */
    750753        rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_USER,
    751                                        true /* contiguous */, VERR_NO_CONT_MEMORY);
     754                                       true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY);
    752755#endif
    753756    if (RT_SUCCESS(rc))
     
    796799    rc = rtR0MemObjLinuxAllocPages(&pMemLnx, enmType, cb, uAlignment, fGfp,
    797800                                   enmType == RTR0MEMOBJTYPE_PHYS /* contiguous / non-contiguous */,
    798                                    VERR_NO_PHYS_MEMORY);
     801                                   false /*fExecutable*/, VERR_NO_PHYS_MEMORY);
    799802    if (RT_FAILURE(rc))
    800803        return rc;
  • trunk/src/VBox/Runtime/r0drv/linux/the-linux-kernel.h

    r80713 r81587  
    338338
    339339#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
    340 # define MY_SET_PAGES_EXEC(pPages, cPages)    set_pages_x(pPages, cPages)
    341 # define MY_SET_PAGES_NOEXEC(pPages, cPages)  set_pages_nx(pPages, cPages)
     340# if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) /* The interface was removed, but we only need it for < 2.4.22, so who cares. */
     341#  define MY_SET_PAGES_EXEC(pPages, cPages)     set_pages_x(pPages, cPages)
     342#  define MY_SET_PAGES_NOEXEC(pPages, cPages)   set_pages_nx(pPages, cPages)
     343# endif
    342344#else
    343345# define MY_SET_PAGES_EXEC(pPages, cPages) \
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette