Fix integer overflow vulnerability in XML deserialization #33945
+103
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Integer Overflow Vulnerability in XML Deserialization
Summary
This PR addresses a critical security vulnerability in XML model deserialization where unsigned integer overflow in the expression
offset + sizecould allow malicious XML files to bypass bounds checking and cause out-of-bounds memory access.Vulnerability Details
The vulnerable code performed bounds checking using:
When both
offsetandsizeare largesize_tvalues, their sum can overflow, wrapping around to a small number that incorrectly passes the bounds check.Attack Example:
Solution
The fix replaces the overflow-prone check with safe component-wise validation:
Mathematical Proof of Correctness
Goal: Verify that
offset + size <= m_weights->size()without computingoffset + sizeProof:
First, check
offset <= m_weights->size()m_weights->size() - offsetis well-defined and non-negativeNext, check
size <= m_weights->size() - offsetsize + offset <= m_weights->size()offset + size <= m_weights->size()No overflow can occur because:
offset + sizem_weights->size() - offsetis safe due to the first checkLogical Equivalence:
Changes Made
Fixed Files:
src/core/xml_util/src/xml_deserialize_util.cpp(lines 840, 907)src/plugins/intel_cpu/src/utils/graph_serializer/deserializer.cpp(line 322)Test Coverage:
overflow_protection_offset_sizetest insrc/core/tests/xml_util/custom_ir.cppTesting
The new test covers three scenarios:
offset = SIZE_MAX - 50, size = 100SIZE_MAX/2for both offset and sizeAll scenarios correctly throw exceptions for invalid cases and succeed for valid ones.
Impact
Ticket ID: CVS-180563