VirtualBox

Changeset 57254 in vbox


Ignore:
Timestamp:
Aug 9, 2015 2:26:51 PM (9 years ago)
Author:
vboxsync
Message:

SUPDrv: Enabled AC=1 I/O control checks on Linux and extended the checks to include the interrupt flag, I/O privilege level and the direction flag.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
4 edited

Legend:

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

    r57220 r57254  
    705705                | $$(dir $$@)
    706706        $(call MSG_TOOL,Creating,,$@)
    707  ifndef VBOX_WITH_HARDENING
    708         $(QUIET)$(SED) -e "s;-DVBOX_WITH_HARDENING;;g" --output $@ $<
    709  else
    710         $(QUIET)$(CP) -f $< $@
    711  endif
     707        $(QUIET)$(SED) -e "" \
     708                $(if-expr !defined(VBOX_WITH_HARDENING)   ,-e "s;-DVBOX_WITH_HARDENING;;g",) \
     709                $(if-expr ($(VBOX_VERSION_BUILD) % 2) == 0,-e "s;-DVBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV;;g",) \
     710                --output $@ $<
    712711        %$(QUIET2)$(APPEND) -t '$(PATH_TARGET)/vboxdrv-mod-1.dep' \
    713712                'Support/$(KBUILD_TARGET)/Makefile_VBOX_HARDENED=$(VBOX_WITH_HARDENING)'
  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r57252 r57254  
    645645     * SMAP check.
    646646     */
    647 #ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
    648647    RTCCUINTREG fSavedEfl = ASMAddFlags(X86_EFL_AC);
    649 #else
    650     RTCCUINTREG fSavedEfl = ASMGetFlags();
    651     ASMSetAC();
     648
     649    int rc = VBoxDrvDarwinIOCtl(Dev, iCmd, pData, fFlags, pProcess);
     650
     651#if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
     652    /*
     653     * Before we restore AC and the rest of EFLAGS, check if the IOCtl handler code
     654     * accidentially modified it or some other important flag.
     655     */
     656    if (RT_UNLIKELY(   (ASMGetFlags() & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL))
     657                    != ((fSavedEfl    & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL)) | X86_EFL_AC) ))
     658    {
     659        char szTmp[48];
     660        RTStrPrintf(szTmp, sizeof(szTmp), "iCmd=%#x: %#x->%#x!", iCmd, (uint32_t)fSavedEfl, (uint32_t)ASMGetFlags());
     661        supdrvBadContext(&g_DevExt, "SUPDrv-darwin.cpp",  __LINE__, szTmp);
     662    }
    652663#endif
    653664
    654     int rc = VBoxDrvDarwinIOCtl(Dev, iCmd, pData, fFlags, pProcess);
    655 
    656 #if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
    657     if (RT_UNLIKELY(!(ASMGetFlags() & X86_EFL_AC)))
    658     {
    659         char szTmp[32];
    660         RTStrPrintf(szTmp, sizeof(szTmp), "iCmd=%#x!", iCmd);
    661         supdrvBadContext(&g_DevExt, "SUPDrv-darwin.cpp",  __LINE__, szTmp);
    662     }
    663 #endif
    664665    ASMSetFlags(fSavedEfl);
    665666    return rc;
  • trunk/src/VBox/HostDrivers/Support/linux/Makefile

    r56293 r57254  
    256256KFLAGS   := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
    257257            -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \
    258            -DSUPDRV_WITH_RELEASE_LOGGER \
     258            -DSUPDRV_WITH_RELEASE_LOGGER -DVBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV \
    259259            -Wno-declaration-after-statement
    260260ifdef VBOX_REDHAT_KABI
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r57108 r57254  
    6767
    6868
    69 
    7069/*******************************************************************************
    7170*   Defined Constants And Macros                                               *
     
    9695                                       VBOX_VERSION_BUILD)
    9796#define VBoxDrvLinuxIOCtl RT_CONCAT(VBoxDrvLinuxIOCtl_,VBoxDrvLinuxVersion)
     97
    9898
    9999/*******************************************************************************
     
    650650    PSUPDRVSESSION pSession = (PSUPDRVSESSION)pFilp->private_data;
    651651    int rc;
     652#if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
     653    RTCCUINTREG fSavedEfl;
     654
     655    /*
     656     * Refuse all I/O control calls if we've ever detected EFLAGS.AC being cleared.
     657     *
     658     * This isn't a problem, as there is absolutely nothing in the kernel context that
     659     * depend on user context triggering cleanups.  That would be pretty wild, right?
     660     */
     661    if (RT_UNLIKELY(g_DevExt.cBadContextCalls > 0))
     662    {
     663        SUPR0Printf("VBoxDrvDarwinIOCtl: EFLAGS.AC=0 detected %u times, refusing all I/O controls!\n", g_DevExt.cBadContextCalls);
     664        return EDEVERR;
     665    }
     666
     667    fSavedEfl = ASMAddFlags(X86_EFL_AC);
     668# else
     669    stac();
     670# endif
    652671
    653672    /*
     
    660679                      || uCmd == SUP_IOCTL_FAST_DO_NOP)
    661680                  && pSession->fUnrestricted == true))
    662     {
    663         stac();
    664681        rc = supdrvIOCtlFast(uCmd, ulArg, &g_DevExt, pSession);
    665         clac();
    666         return rc;
    667     }
    668     return VBoxDrvLinuxIOCtlSlow(pFilp, uCmd, ulArg, pSession);
    669 
     682    else
     683        rc = VBoxDrvLinuxIOCtlSlow(pFilp, uCmd, ulArg, pSession);
    670684#else   /* !HAVE_UNLOCKED_IOCTL */
    671685    unlock_kernel();
     
    678692        rc = VBoxDrvLinuxIOCtlSlow(pFilp, uCmd, ulArg, pSession);
    679693    lock_kernel();
     694#endif  /* !HAVE_UNLOCKED_IOCTL */
     695
     696#if defined(VBOX_STRICT) || defined(VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV)
     697    /*
     698     * Before we restore AC and the rest of EFLAGS, check if the IOCtl handler code
     699     * accidentially modified it or some other important flag.
     700     */
     701    if (RT_UNLIKELY(   (ASMGetFlags() & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL))
     702                    != ((fSavedEfl    & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL)) | X86_EFL_AC) ))
     703    {
     704        char szTmp[48];
     705        RTStrPrintf(szTmp, sizeof(szTmp), "uCmd=%#x: %#x->%#x!", uCmd, (uint32_t)fSavedEfl, (uint32_t)ASMGetFlags());
     706        supdrvBadContext(&g_DevExt, "SUPDrv-linux.c",  __LINE__, szTmp);
     707    }
     708    ASMSetFlags(fSavedEfl);
     709#else
     710    clac();
     711#endif
    680712    return rc;
    681 #endif  /* !HAVE_UNLOCKED_IOCTL */
    682713}
    683714
     
    746777     * Process the IOCtl.
    747778     */
    748     stac();
    749779    rc = supdrvIOCtl(uCmd, &g_DevExt, pSession, pHdr, cbBuf);
    750     clac();
    751780
    752781    /*
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