syn: fix stack-use-after-return in constant fold sliceDff, revised#10771
Open
povik wants to merge 3 commits into
Open
syn: fix stack-use-after-return in constant fold sliceDff, revised#10771povik wants to merge 3 commits into
povik wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the return type of the Graph::add function from Bundle to BundleView in both its declaration and definition. The review feedback suggests updating the corresponding documentation comment to reflect this change. Additionally, it recommends optimizing the Bundle::Bundle(BundleView) constructor to prevent unnecessary heap allocations when callers assign the returned BundleView to a Bundle, particularly since Graph::add returns consecutive nets.
2 tasks
Contributor
Author
|
The LLM has good suggestions, I'll take them up later. |
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>
Since the return value of `add` represents a contiguous block of net indices we can use `BundleView` for it which is both more efficient and prevents use-after-free should the caller cast to BundleView. Signed-off-by: Martin Povišer <povik@cutebit.org>
Signed-off-by: Martin Povišer <povik@cutebit.org>
a815a5e to
060af12
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
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 is a revised fix from #10768.
Since the return value of
addrepresents a contiguous block of net indices we can useBundleViewfor it which is both more efficient and prevents use-after-free should the caller cast to BundleView.Type of Change