fix: keep CompileOptions includer alive across copy and move#1544
Open
Sakura-501 wants to merge 1 commit intogoogle:mainfrom
Open
fix: keep CompileOptions includer alive across copy and move#1544Sakura-501 wants to merge 1 commit intogoogle:mainfrom
Sakura-501 wants to merge 1 commit intogoogle:mainfrom
Conversation
CompileOptions stores include callbacks inside the cloned or moved C options object but originally kept the C++ includer under unique ownership. Copying only cloned options_ and moving only transferred options_, so the registered include user_data pointer could outlive the owning CompileOptions object and become dangling after destruction. Keep the includer alive across copies and moves by storing it in a shared_ptr and re-registering the callback user_data whenever CompileOptions is copied or moved. Add regression tests that verify the includer remains alive after the source object is destroyed and that preprocessing with #include still succeeds.
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
This fixes a use after free in
shaderc::CompileOptionswhen a custom includer is configured throughSetIncluder()and the options object is later copied or moved before preprocessing or compilation reaches#include.Vulnerability details
SetIncluder()stores the includer callback state in two places:CompileOptions::includer_;include_user_data.Before this change, copying
CompileOptionsonly clonedoptions_, and moving it only transferredoptions_. The registeredinclude_user_datatherefore kept pointing at an includer owned by a differentCompileOptionsinstance. Once that source object was destroyed, any later#includepreprocessing path could call through a dangling pointer and trigger a heap use after free.Both copy and move paths were affected. A remote shader compilation service that registers a custom includer and passes
CompileOptionsby value could be crashed with a single shader containing#include.Fix
std::shared_ptrso its lifetime can safely span copiedCompileOptionsobjects;include_user_data;SetIncluder(nullptr)is used;CompileOptionsinstance is destroyed and that preprocessing with#includestill succeeds.Verification
cmake --build build-test --target check-copyright -j4./build-test/libshaderc/shaderc_shaderc_cpp_test