syn: fix stack-use-after-return in constant fold sliceDff#10768
Closed
mguthaus wants to merge 1 commit into
Closed
syn: fix stack-use-after-return in constant fold sliceDff#10768mguthaus wants to merge 1 commit into
mguthaus wants to merge 1 commit into
Conversation
sliceDff() was declared to return a BundleView (a non-owning view) but returned the owning Bundle produced by Graph::add<Dff>(). The implicit BundleView(const Bundle&) conversion stores a pointer to that temporary, which is destroyed when sliceDff() returns, so foldSequentials() then indexes a dangling view (BundleView::operator[] -> Bundle::operator[]). This is undefined behavior that optimized builds tolerate (sliceDff() is inlined, so the temporary's storage survives the read), but a DEBUG (unoptimized) build faults on. It reproduces as a SIGSEGV during synthesis of larger designs using the integrated syn flow (e.g. asap7/aes, asap7/jpeg with SYNTH_USE_SYN=1); AddressSanitizer reports a stack-use-after-return at ir/Bundle.cc. Return an owning Bundle from sliceDff() and hold it as a Bundle at the call site (a BundleView local would re-create the dangle). Signed-off-by: Matthew Guthaus <mrg@ucsc.edu>
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the return type of the static helper function sliceDff in constant_fold.cc from BundleView to Bundle, and updates its usage in foldSequentials accordingly. There are no review comments, so no additional feedback is provided.
Contributor
|
Thanks for investigating to the cause. I prefer fixing this on the |
Contributor
|
Closing in favor of the other fix |
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
sliceDff()in the constant-fold pass returned a non-owningBundleViewbuilt from the owning
BundlethatGraph::add<Dff>()returns. The implicitBundleView(const Bundle&)conversion captures a pointer to that temporary,which is destroyed when
sliceDff()returns;foldSequentials()then indexesthe dangling view.
Fix: return an owning
BundlefromsliceDff()and hold it as aBundleatthe call site.
Type of Change
Impact
Optimized builds tolerate the UB (
sliceDffis inlined, so the temporary'sstorage survives the read), but a DEBUG (unoptimized) build SIGSEGVs during
synthesis of larger designs that use the integrated
synflow (e.g.asap7/aes,asap7/jpeg). After the fix, both a pure DEBUG build and a-DASAN=ONbuild complete synthesis ofasap7/aescleanly and produceidentical output (
1_synth.odbsha1 matches across configs). No behaviorchange for optimized builds.
Verification
./etc/Build.sh).graph_test,liveness_testunder ASan;
asap7/aessynthesis in DEBUG and ASan).Related Issues
N/A