Skip to content

Fix heap-use-after-free in PrimaDelayCalc copy constructor#458

Open
maliberty wants to merge 1 commit into
parallaxsw:masterfrom
maliberty:fix-prima-dcalc-copy-uaf
Open

Fix heap-use-after-free in PrimaDelayCalc copy constructor#458
maliberty wants to merge 1 commit into
parallaxsw:masterfrom
maliberty:fix-prima-dcalc-copy-uaf

Conversation

@maliberty

Copy link
Copy Markdown
Contributor

The copy constructor copied node_index_map_, a
std::map<const ParasiticNode*, size_t, ParasiticNodeLess>. Copying the map reconstructs its red-black tree, which invokes the ParasiticNodeLess comparator and dereferences the ParasiticNode* keys.

When a delay calculator is cloned for parallel delay calculation (GraphDelayCalc::findDelays -> FindVertexDelays -> ArcDelayCalc::copy), the source map can hold pointers to ParasiticNodes that were already freed because the net's parasitic network was rebuilt (e.g. during resizer repair). Dereferencing those freed keys is a heap-use-after-free.

node_index_map_ is transient state: findNodeCount() clears and rebuilds it from the current parasitic network before any read, and the primary constructor leaves it default-constructed. Copying it is therefore both unnecessary and the sole source of the dangling-pointer dereference, so leave it default-constructed in the copy constructor as well.

The copy constructor copied node_index_map_, a
std::map<const ParasiticNode*, size_t, ParasiticNodeLess>. Copying the
map reconstructs its red-black tree, which invokes the ParasiticNodeLess
comparator and dereferences the ParasiticNode* keys.

When a delay calculator is cloned for parallel delay calculation
(GraphDelayCalc::findDelays -> FindVertexDelays -> ArcDelayCalc::copy),
the source map can hold pointers to ParasiticNodes that were already
freed because the net's parasitic network was rebuilt (e.g. during
resizer repair). Dereferencing those freed keys is a heap-use-after-free.

node_index_map_ is transient state: findNodeCount() clears and rebuilds
it from the current parasitic network before any read, and the primary
constructor leaves it default-constructed. Copying it is therefore both
unnecessary and the sole source of the dangling-pointer dereference, so
leave it default-constructed in the copy constructor as well.

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant