Commit e028946
Add C++ test for Scheduler delegate UAF after JS-throw teardown (#56800)
Summary:
Pull Request resolved: #56800
Reproduces, in a standalone gtest, the use-after-free race between Scheduler
teardown and pending rendering-update lambdas previously enqueued via
runtimeScheduler->scheduleRenderingUpdate inside
Scheduler::uiManagerDidFinishTransaction.
The lambda captures the SchedulerDelegate by raw pointer; when the delegate
is destroyed (as part of an instance teardown triggered by an uncaught fatal
error) before the lambda runs, the dereference is a use-after-free unless
the invalidation-token guard in Scheduler::setDelegate
(enableSchedulerDelegateInvalidation) is enabled at queue time.
The test:
- Drives the *real* Scheduler::uiManagerDidFinishTransaction so the lambda
is enqueued via the regular code path into a real RuntimeScheduler's
pending-rendering-updates queue.
- Initiates teardown via an uncaught JSI host-function throw routed through
RuntimeScheduler's onTaskError callback (the test's analog of a host-side
fatal handler), which drops the delegate.
- Triggers the next event loop tick to drain the queue.
Three test cases:
1. Sanity_LambdaRunsOnNextTickWhenDelegateAlive -- baseline: lambda runs and
reaches the delegate when no teardown happens.
2. GuardEnabled_JSThrowInitiatedTeardownIsSafe -- with the guard ON, the
pending lambda observes the invalidation token after teardown and returns
without touching the freed delegate. Safe.
3. GuardDisabled_JSThrowInitiatedTeardownIsUAF -- with the guard OFF, the
lambda dereferences the destroyed delegate. Caught by EXPECT_DEATH via a
magic-sentinel ASSERT_EQ in the recording delegate, or by AddressSanitizer
on the vptr load.
Fantom is intentionally not used here: it shares the global runtime VM across
tests, which would interfere with this test's contract that no further JS
executes after a fatal-driven instance teardown.
Changelog: [Internal]
Reviewed By: javache
Differential Revision: D104777850
fbshipit-source-id: 7ecacaf21a4a9b121575fcc66c2fcbb6bfd4adc71 parent 8823a80 commit e028946
3 files changed
Lines changed: 623 additions & 0 deletions
File tree
- packages/react-native
- ReactCommon
- react/renderer/scheduler/tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| 476 | + | |
476 | 477 | | |
477 | 478 | | |
478 | 479 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| |||
0 commit comments