VirtualBox

Changeset 55815 in vbox


Ignore:
Timestamp:
May 12, 2015 9:22:50 AM (9 years ago)
Author:
vboxsync
Message:

VMM/HMVMXR0: bounds checking for auto load/store MSR functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r55757 r55815  
    843843{
    844844    AssertPtrReturn(pMemObj, VERR_INVALID_PARAMETER);
    845     AssertPtrReturn(ppVirt, VERR_INVALID_PARAMETER);
     845    AssertPtrReturn(ppVirt,  VERR_INVALID_PARAMETER);
    846846    AssertPtrReturn(pHCPhys, VERR_INVALID_PARAMETER);
    847847
     
    12621262 * auto-load/store MSR area in the VMCS.
    12631263 *
    1264  * @returns true if the MSR was added -and- its value was updated, false
    1265  *          otherwise.
    1266  * @param   pVCpu           Pointer to the VMCPU.
    1267  * @param   uMsr            The MSR.
    1268  * @param   uGuestMsr       Value of the guest MSR.
    1269  * @param   fUpdateHostMsr  Whether to update the value of the host MSR if
    1270  *                          necessary.
    1271  */
    1272 static bool hmR0VmxAddAutoLoadStoreMsr(PVMCPU pVCpu, uint32_t uMsr, uint64_t uGuestMsrValue, bool fUpdateHostMsr)
     1264 * @returns VBox status code.
     1265 * @param   pVCpu               Pointer to the VMCPU.
     1266 * @param   uMsr                The MSR.
     1267 * @param   uGuestMsr           Value of the guest MSR.
     1268 * @param   fUpdateHostMsr      Whether to update the value of the host MSR if
     1269 *                              necessary.
     1270 * @param   pfAddedAndUpdated   Where to store whether the MSR was added -and-
     1271 *                              its value was updated. Optional, can be NULL.
     1272 */
     1273static int hmR0VmxAddAutoLoadStoreMsr(PVMCPU pVCpu, uint32_t uMsr, uint64_t uGuestMsrValue, bool fUpdateHostMsr,
     1274                                       bool *pfAddedAndUpdated)
    12731275{
    12741276    PVMXAUTOMSR pGuestMsr = (PVMXAUTOMSR)pVCpu->hm.s.vmx.pvGuestMsr;
     
    12871289        ++cMsrs;
    12881290        int rc = hmR0VmxSetAutoLoadStoreMsrCount(pVCpu, cMsrs);
    1289         AssertRC(rc);
     1291        AssertMsgRCReturn(rc, ("hmR0VmxAddAutoLoadStoreMsr: Insufficient space to add MSR %u\n", uMsr), rc);
    12901292
    12911293        /* Now that we're swapping MSRs during the world-switch, allow the guest to read/write them without causing VM-exits. */
     
    13201322    }
    13211323
    1322     return fUpdatedMsrValue;
     1324    if (pfAddedAndUpdated)
     1325        *pfAddedAndUpdated = fUpdatedMsrValue;
     1326    return VINF_SUCCESS;
    13231327}
    13241328
     
    47764780        if (pVM->hm.s.fAllow64BitGuests)
    47774781        {
    4778             hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_LSTAR,          pMixedCtx->msrLSTAR,        false /* fUpdateHostMsr */);
    4779             hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K6_STAR,           pMixedCtx->msrSTAR,         false /* fUpdateHostMsr */);
    4780             hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_SF_MASK,        pMixedCtx->msrSFMASK,       false /* fUpdateHostMsr */);
    4781             hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_KERNEL_GS_BASE, pMixedCtx->msrKERNELGSBASE, false /* fUpdateHostMsr */);
    4782 # ifdef DEBUG
     4782            int rc = VINF_SUCCESS;
     4783            rc |= hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_LSTAR,          pMixedCtx->msrLSTAR,        false, NULL);
     4784            rc |= hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K6_STAR,           pMixedCtx->msrSTAR,         false, NULL);
     4785            rc |= hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_SF_MASK,        pMixedCtx->msrSFMASK,       false, NULL);
     4786            rc |= hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_KERNEL_GS_BASE, pMixedCtx->msrKERNELGSBASE, false, NULL);
     4787            AssertRCReturn(rc, rc);
     4788#ifdef DEBUG
    47834789            PVMXAUTOMSR pMsr = (PVMXAUTOMSR)pVCpu->hm.s.vmx.pvGuestMsr;
    47844790            for (uint32_t i = 0; i < pVCpu->hm.s.vmx.cMsrs; i++, pMsr++)
     
    48324838            else
    48334839            {
    4834                 hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K6_EFER, pMixedCtx->msrEFER, false /* fUpdateHostMsr */);
     4840                int rc = hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K6_EFER, pMixedCtx->msrEFER, false /* fUpdateHostMsr */,
     4841                                                    NULL /* pfAddedAndUpdated */);
     4842                AssertRCReturn(rc, rc);
     4843
    48354844                /* We need to intercept reads too, see @bugref{7386} comment #16. */
    48364845                hmR0VmxSetMsrPermission(pVCpu, MSR_K6_EFER, VMXMSREXIT_INTERCEPT_READ, VMXMSREXIT_INTERCEPT_WRITE);
     
    67916800     * We assume all general purpose registers other than RSP are available.
    67926801     *
    6793      * RIP is a must as it will be incremented or otherwise changed.
     6802     * RIP is a must, as it will be incremented or otherwise changed.
    67946803     *
    67956804     * RFLAGS are always required to figure the CPL.
    67966805     *
    6797      * RSP isn't always required, however it's a GPR so frequently required.
     6806     * RSP isn't always required, however it's a GPR, so frequently required.
    67986807     *
    67996808     * SS and CS are the only segment register needed if IEM doesn't do memory
     
    68196828
    68206829/**
    6821  * Ensures that we've got a complete basic context.
     6830 * Ensures that we've got a complete basic guest-context.
    68226831 *
    68236832 * This excludes the FPU, SSE, AVX, and similar extended state.  The interface
     
    70997108    /*
    71007109     * !!! IMPORTANT !!!
    7101      * If you modify code here, make sure to check whether hmR0VmxCallRing3Callback() needs to be updated too.
     7110     * If you modify code here, check whether hmR0VmxCallRing3Callback() needs to be updated too.
    71027111     */
    71037112
     
    73647373        /*
    73657374         * !!! IMPORTANT !!!
    7366          * If you modify code here, make sure to check whether hmR0VmxLeave() and hmR0VmxLeaveSession() needs
    7367          * to be updated too. This is a stripped down version which gets out ASAP trying to not trigger any assertion.
     7375         * If you modify code here, check whether hmR0VmxLeave() and hmR0VmxLeaveSession() needs to be updated too.
     7376         * This is a stripped down version which gets out ASAP, trying to not trigger any further assertions.
    73687377         */
    73697378        RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER; \
     
    87878796        if (!(pVCpu->hm.s.vmx.u32ProcCtls & VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT))
    87888797        {
     8798            bool fMsrUpdated;
    87898799            int rc2 = hmR0VmxSaveGuestAutoLoadStoreMsrs(pVCpu, pMixedCtx);
    87908800            AssertRC(rc2);
    87918801            Assert(HMVMXCPU_GST_IS_UPDATED(pVCpu, HMVMX_UPDATED_GUEST_AUTO_LOAD_STORE_MSRS));
    8792             bool fMsrUpdated = hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_TSC_AUX, CPUMR0GetGuestTscAux(pVCpu),
    8793                                                           true /* fUpdateHostMsr */);
     8802
     8803            rc2 = hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_TSC_AUX, CPUMR0GetGuestTscAux(pVCpu), true /* fUpdateHostMsr */,
     8804                                             &fMsrUpdated);
     8805            AssertRC(rc2);
    87948806            Assert(fMsrUpdated || pVCpu->hm.s.vmx.fUpdatedHostMsrs);
     8807
    87958808            /* Finally, mark that all host MSR values are updated so we don't redo it without leaving VT-x. See @bugref{6956}. */
    87968809            pVCpu->hm.s.vmx.fUpdatedHostMsrs = true;
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