fix: prevent OOB read in C API header validation (#737)#738
Open
BAder82t wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: prevent OOB read in C API header validation (#737)#738BAder82t wants to merge 1 commit intomicrosoft:mainfrom
BAder82t wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Serialization_IsCompatibleVersion and Serialization_IsValidHeader set *result = false on a caller-buffer size mismatch but fall through to memcpy(sizeof(SEALHeader)). A caller passing a smaller allocation (e.g. size=1) triggers an out-of-bounds read of up to sizeof(SEALHeader) bytes across the FFI boundary, yielding information disclosure or DoS. Return S_OK immediately after flagging the mismatch so the memcpy never runs on an undersized buffer. Closes microsoft#737
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.
Summary
Fixes out-of-bounds read in
Serialization_IsCompatibleVersionandSerialization_IsValidHeader(native/src/seal/c/serialization.cpp).Both functions set
*result = falsewhen the caller-providedsizedoes not matchsizeof(SEALHeader), but they do not return — execution falls through tomemcpy(&header, headerptr, sizeof(SEALHeader)). A caller passing e.g.size = 1with a 1-byte allocation triggers an OOB read of up tosizeof(SEALHeader)bytes across the FFI boundary, producing information disclosure / DoS.Fix
Return
S_OKimmediately after flagging the mismatch so thememcpynever executes on an undersized buffer. Preserves the existing contract (function returnsS_OK,*result == false).Testing
SerializationTestsuite passes (sealtest --gtest_filter=*Serialization*).sealtestsuite shows no new failures attributable to this diff. One pre-existing macOS-specific ASan finding inRandomGenerator.UniformRandomGeneratorInfoSaveLoad(memset_suse-after-poison inlibsystem_c) is unrelated and reproducible on unpatchedmain.native/tests/; this change is a strict tightening of an error path.Closes
#737