Fix SIGSEGV in ShadowNode::getTag() caused by use-after-free in findShadowNodeByTag_DEPRECATED#55751
Open
Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Open
Fix SIGSEGV in ShadowNode::getTag() caused by use-after-free in findShadowNodeByTag_DEPRECATED#55751Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Conversation
…hadowNodeByTag_DEPRECATED
Summary:
A SIGSEGV crash is occurring in production when `ShadowNode::getTag()` is called on a destroyed ShadowNode during focus navigation (`FabricUIManagerBinding::findNextFocusableElement`).
**Root cause**: `UIManager::findShadowNodeByTag_DEPRECATED` captures a **raw pointer** to the root shadow node inside a `tryCommit` callback, then dereferences it **after the lock is released**. Another thread can commit a new tree in between, destroying the old root and leaving a dangling pointer:
```
tryCommit([&](const RootShadowNode& old) {
rootShadowNode = &old; // capture raw address
return nullptr; // cancel commit, release lock
}, {});
// !!! LOCK RELEASED — another thread can replace + destroy the old root
rootShadowNode->getChildren(); // use-after-free → SIGSEGV
```
**Fix**: Replace the `tryCommit` + raw pointer pattern with `ShadowTree::getCurrentRevision()`, which returns a `ShadowTreeRevision` by value containing a `shared_ptr<const RootShadowNode>`. The `shared_ptr` copy keeps the root node alive for the entire traversal.
**Why the old root gets destroyed**: After a commit, the old root's `shared_ptr` in `currentRevision_` is replaced. The `MountingCoordinator::push()` also overwrites `lastRevision_`. If no other holder remains (e.g. `baseRevision_` holds an earlier root), the old root's refcount drops to 0 and it is freed — while the finder thread may still hold a raw pointer to it.
Changelog: [Internal]
Differential Revision: D94376636
|
@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D94376636. |
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:
A SIGSEGV crash is occurring in production when
ShadowNode::getTag()is called on a destroyed ShadowNode during focus navigation (FabricUIManagerBinding::findNextFocusableElement).Root cause:
UIManager::findShadowNodeByTag_DEPRECATEDcaptures a raw pointer to the root shadow node inside atryCommitcallback, then dereferences it after the lock is released. Another thread can commit a new tree in between, destroying the old root and leaving a dangling pointer:Fix: Replace the
tryCommit+ raw pointer pattern withShadowTree::getCurrentRevision(), which returns aShadowTreeRevisionby value containing ashared_ptr<const RootShadowNode>. Theshared_ptrcopy keeps the root node alive for the entire traversal.Why the old root gets destroyed: After a commit, the old root's
shared_ptrincurrentRevision_is replaced. TheMountingCoordinator::push()also overwriteslastRevision_. If no other holder remains (e.g.baseRevision_holds an earlier root), the old root's refcount drops to 0 and it is freed — while the finder thread may still hold a raw pointer to it.Changelog: [Internal]
Differential Revision: D94376636