VirtualBox

Changeset 97024 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Oct 6, 2022 8:26:17 AM (2 years ago)
Author:
vboxsync
Message:

Main/glue: Applied the out-of-process restrictions to the IDLLHost interface (COM internal) as well. bugref:10294

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/initterm.cpp

    r96407 r97024  
    245245
    246246/**
     247 * Replacement function for the InvokeStub method for the IDLLHost stub.
     248 */
     249static HRESULT STDMETHODCALLTYPE
     250DLLHost_InvokeStub(IRpcStubBuffer *pThis, RPCOLEMESSAGE *pMsg, IRpcChannelBuffer *pBuf) RT_NOTHROW_DEF
     251{
     252    /*
     253     * Our mission here is to prevent remote calls to this interface as method #3
     254     * contain a raw pointer an DllGetClassObject function.  There are only that
     255     * method in addition to the IUnknown stuff, and it's ASSUMED that it's
     256     * process internal only (cross apartment stuff).
     257     */
     258    uint32_t const iMethod = pMsg->iMethod & 0xffff; /* Uncertain, but there are hints that the upper bits are flags. */
     259    HRESULT        hrc;
     260    if (pMsg->rpcFlags & RPCFLG_LOCAL_CALL)
     261        hrc = CStdStubBuffer_Invoke(pThis, pMsg, pBuf);
     262    else
     263    {
     264        LogRel(("DLLHost_InvokeStub: Rejected call to CDLLHost::%s: rpcFlags=%#x cbBuffer=%#x dataRepresentation=%d buffer=%p:{%.*Rhxs} reserved1=%p reserved2={%p,%p,%p,%p,%p}\n",
     265                pMsg->iMethod == 0 ? "QueryInterface" :
     266                pMsg->iMethod == 1 ? "AddRef" :
     267                pMsg->iMethod == 2 ? "ReleaseRef" :
     268                pMsg->iMethod == 3 ? "DllGetClassObject" : "Unknown", pMsg->rpcFlags, pMsg->cbBuffer,
     269                pMsg->dataRepresentation, pMsg->Buffer, RT_VALID_PTR(pMsg->Buffer) ? pMsg->cbBuffer : 0, pMsg->Buffer,
     270                pMsg->reserved1, pMsg->reserved2[0], pMsg->reserved2[1], pMsg->reserved2[2], pMsg->reserved2[3], pMsg->reserved2[4]));
     271        hrc = E_ACCESSDENIED;
     272    }
     273    return hrc;
     274}
     275
     276/**
    247277 * Replaces the IRundown InvokeStub method with Rundown_InvokeStub so we can
    248278 * reject remote calls to a couple of misdesigned methods.
     279 *
     280 * Also replaces the IDLLHost for the same reasons.
    249281 */
    250282void PatchComBugs(void)
     
    283315     */
    284316    static const IID s_IID_Rundown = {0x00000134,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
     317    static const IID s_IID_DLLHost = {0x00000141,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
    285318    decltype(CStdStubBuffer_Invoke) *pfnInvoke = (decltype(pfnInvoke))GetProcAddress(hmod, "CStdStubBuffer_Invoke");
    286319    if (!pfnInvoke)
     
    319352                            cAlreadyPatched++;
    320353                    }
     354                    else if (IsEqualIID(*piid, s_IID_DLLHost))
     355                    {
     356                        if (pCurStub->Vtbl.Invoke == pfnInvoke)
     357                        {
     358                            DWORD fOld = 0;
     359                            if (VirtualProtect(&pCurStub->Vtbl.Invoke, sizeof(pCurStub->Vtbl.Invoke), PAGE_READWRITE, &fOld))
     360                            {
     361                                pCurStub->Vtbl.Invoke = DLLHost_InvokeStub;
     362                                VirtualProtect(&pCurStub->Vtbl.Invoke, sizeof(pCurStub->Vtbl.Invoke), fOld, &fOld);
     363                                cPatched++;
     364                            }
     365                            else
     366                                AssertMsgFailed(("%d\n", GetLastError()));
     367                        }
     368                        else
     369                            cAlreadyPatched++;
     370                    }
    321371                }
    322372            }
     
    338388                        ("last error: %u; Rundown_InvokeStub=%p\n", GetLastError(), Rundown_InvokeStub));
    339389    }
    340     else
    341         AssertLogRelMsg(cAlreadyPatched > 0, ("COM patching of IRundown failed!\n"));
     390    AssertLogRelMsg(cAlreadyPatched + cPatched >= 2,
     391                    ("COM patching of IRundown/IDLLHost failed! (%d+%d)\n", cAlreadyPatched, cPatched));
    342392}
    343393
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