Fix Type Confusion in CorrectSizes causing invalid T->O size#50
Open
MrAlaskan wants to merge 1 commit into
Open
Fix Type Confusion in CorrectSizes causing invalid T->O size#50MrAlaskan wants to merge 1 commit into
MrAlaskan wants to merge 1 commit into
Conversation
…izes() was casting a CipByteArray* to a ByteBuf* to call size(), which caused memory layout misinterpretation and returned garbage sizes on 64-bit systems. Changed to safely cast to AssemblyInstance* and call SizeBytes() instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug Summary
A critical Type Confusion vulnerability exists in
CorrectSizes()(src/cip/cipconnection.cc) that causes the connection size validation to fail on 64-bit systems, resulting in validForwardOpenrequests being rejected with0x127(invalid O->T connection size) or0x128(invalid T->O connection size) errors.Root Cause Analysis
When fetching the actual size of the configured assembly instance, the code performs a C-style cast from
CipByteArray*toByteBuf*:However,
CipByteArrayandByteBufhave completely incompatible memory layouts:CipByteArraylayout (approx 16-24 bytes depending on alignment):uint8_t* start,uint16_t cap,uint16_t len,[Padding]ByteBuflayout (16 bytes):uint8_t* start,uint8_t* limitWhen
attr_data->size()(which is implemented aslimit - start) is called, the compiler treats thecap,len, and subsequent padding bytes of theCipByteArrayas a 64-bitlimitpointer. This pointer arithmetic produces an astronomical garbage value (e.g.,1762171072) instead of the true size (e.g.,128). Consequently, the size checkdata_size != attr_sizespuriously fails.Impact
Legitimate Originators cannot establish Class 1 I/O connections because the Target always reports an invalid connection size.
Fix Details
Removed the unsafe
ByteBuf*cast. Since I/O connection instances are inherently Assembly instances, the code now safely downcasts toAssemblyInstance*and directly invokes the built-inSizeBytes()method to retrieve the accurate assembly size.