From 8b6f5ef6a0cc1613379e60be403e7a957e531b13 Mon Sep 17 00:00:00 2001 From: Yuri Benditovich Date: Wed, 10 Apr 2024 00:02:41 +0300 Subject: [PATCH] netkvm: fix memory leak in TX overfragmenting flow https://issues.redhat.com/browse/RHEL-24992 Memory leak of CNB::m_ExtraNBStorage happens if the packet os overfragmented but we do not succeed to allocate extra pages. Signed-off-by: Yuri Benditovich --- NetKVM/Common/ParaNdis_TX.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NetKVM/Common/ParaNdis_TX.cpp b/NetKVM/Common/ParaNdis_TX.cpp index d706ec201..1c7e0a447 100644 --- a/NetKVM/Common/ParaNdis_TX.cpp +++ b/NetKVM/Common/ParaNdis_TX.cpp @@ -809,6 +809,11 @@ CNB::~CNB() { NdisMFreeNetBufferSGList(m_Context->DmaHandle, m_SGL, m_NB); } + if (m_ExtraNBStorage) + { + // for unknown case it was not freed before + ReturnPages(); + } } void CNB::ReleaseResources() @@ -1221,6 +1226,8 @@ NBMappingStatus CNB::AllocateAndFillCopySGL(ULONG ParsedHeadersLength) RtlZeroMemory(m_ExtraNBStorage, sizeof(CExtendedNBStorage)); if (!m_ParentNBL->GetParentTXPath()->BorrowPages(m_ExtraNBStorage, Pages)) { + NdisFreeMemory(m_ExtraNBStorage, sizeof(CExtendedNBStorage), 0); + m_ExtraNBStorage = NULL; return NBMappingStatus::NO_RESOURCE; }