Skip to content

Commit

Permalink
[Encode] Fix Wild Pointer Double Free Heap Corruption Issue
Browse files Browse the repository at this point in the history
There is two pointer points to an avp interface and may cause heap corruption due to double free. This fix is to set one pointer to nullptr as not used to avoid free again.
  • Loading branch information
chenhao5-Intel authored and intel-mediadev committed Dec 18, 2024
1 parent a943748 commit 3d2c719
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ CodechalHwInterfaceXe_Hpm::CodechalHwInterfaceXe_Hpm(
: CodechalHwInterfaceG12(osInterface, codecFunction, mhwInterfaces, disableScalability)
{
CODECHAL_HW_FUNCTION_ENTER;
m_avpInterface = static_cast<MhwInterfacesXehp_Sdv*>(mhwInterfaces)->m_avpInterface;

PrepareCmdSize(codecFunction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ CodechalHwInterfaceXe_Xpm::CodechalHwInterfaceXe_Xpm(
{
CODECHAL_HW_FUNCTION_ENTER;


m_avpInterface = static_cast<MhwInterfacesXehp_Sdv*>(mhwInterfaces)->m_avpInterface;

m_bltState = MOS_New(BltStateXe_Xpm, m_osInterface);
if(m_bltState != nullptr)
{
Expand Down
8 changes: 7 additions & 1 deletion media_driver/agnostic/gen12/codec/hal/codechal_hw_g12_X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ CodechalHwInterfaceG12::CodechalHwInterfaceG12(
: CodechalHwInterface(osInterface, codecFunction, mhwInterfaces, disableScalability)
{
CODECHAL_HW_FUNCTION_ENTER;
m_avpInterface = static_cast<MhwInterfacesG12Tgllp*>(mhwInterfaces)->m_avpInterface;

MhwInterfacesG12Tgllp *mhwItfG12Tgllp = static_cast<MhwInterfacesG12Tgllp *>(mhwInterfaces);
CODECHAL_HW_ASSERT(mhwItfG12Tgllp);
m_avpInterface = mhwItfG12Tgllp->m_avpInterface;
//Set the original m_avpInterface to nullptr to avoid double free and wild pointer
mhwItfG12Tgllp->m_avpInterface = nullptr;

m_mediaSfcItf = std::make_shared<MediaSfcInterfaceLegacy>(m_osInterface);

InternalInit(codecFunction);
Expand Down

0 comments on commit 3d2c719

Please sign in to comment.