-
Notifications
You must be signed in to change notification settings - Fork 721
Add boundary checks to prevent memory safety issues in BgpLayer::getHeaderLen #1954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure why the CI has a failure on checkout on windows. :/
I think the error is that Windows can't contain |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1954 +/- ##
==========================================
- Coverage 83.51% 83.49% -0.02%
==========================================
Files 310 310
Lines 54884 54910 +26
Branches 12220 12223 +3
==========================================
+ Hits 45834 45849 +15
- Misses 7786 8197 +411
+ Partials 1264 864 -400
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
if (m_Data - m_Packet->m_RawPacket->getRawData() + static_cast<ptrdiff_t>(offsetInLayer) > | ||
static_cast<ptrdiff_t>(m_Packet->m_RawPacket->getRawDataLen())) | ||
{ | ||
PCPP_LOG_ERROR("Requested offset is larger than total packet length"); | ||
return false; | ||
} | ||
|
||
if (m_NextLayer != nullptr && static_cast<ptrdiff_t>(offsetInLayer) > m_NextLayer->m_Data - m_Data) | ||
{ | ||
PCPP_LOG_ERROR("Requested offset exceeds current layer's boundary"); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these checks needed? All we need to check is that offsetInLayer
is within the layer's boundary, which means it is smaller than or equal to m_DataLen
. Why do we need to compare it to the whole packet or involve m_NextLayer
?
if (m_Data - m_Packet->m_RawPacket->getRawData() + static_cast<ptrdiff_t>(offsetInLayer) + | ||
static_cast<ptrdiff_t>(numOfBytesToShorten) > | ||
static_cast<ptrdiff_t>(m_Packet->m_RawPacket->getRawDataLen())) | ||
{ | ||
PCPP_LOG_ERROR("Requested number of bytes to shorten is larger than total packet length"); | ||
return false; | ||
} | ||
|
||
if (m_NextLayer != nullptr && | ||
static_cast<ptrdiff_t>(offsetInLayer) + static_cast<ptrdiff_t>(numOfBytesToShorten) > | ||
m_NextLayer->m_Data - m_Data) | ||
{ | ||
PCPP_LOG_ERROR("Requested number of bytes to shorten exceeds current layer's boundary"); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
if (dataPtr > m_RawPacket->getRawData() + m_RawPacket->getRawDataLen()) | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can such a thing happen? curLayer->getHeaderLen()
should never exceed the packet data, unless we have a bug in one of the layers
if (dataPtr > m_RawPacket->getRawData() + m_RawPacket->getRawDataLen()) | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Closes #1864
This PR fixes heap-use-after-free and heap-buffer-overflow issues in BgpLayer::getHeaderLen(), reported by AddressSanitizer when extending or shortening the BGP layer
Added boundary checks to ensure that requested offsets and lengths do not exceed:
Added regression_samples