Use after free in Sessions (CVE-2026-79129)
A use-after-free exists in TabRestoreServiceHelper::RestoreEntryById on Android because a synchronous Java-to-C++ re-entrancy can prune the tab restore entry being restored. An attacker could corrupt memory in the browser process, potentially leading to arbitrary code execution.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 4 months
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports without the Chrome Security team.
Overview: A potential Use-After-Free vulnerability exists in TabRestoreServiceHelper::RestoreEntryById on Android due to synchronous Java-to-C++ re-entrancy. When restoring a tab, pending tab closures are synchronously committed, which can prune the exact tab restore entry currently being restored. Subsequent C++ vector operations on the freed stack references allow for memory corruption in the browser process.
Affected files:
components/sessions/core/tab_restore_service_helper.ccchrome/browser/ui/android/tab_model/android_live_tab_context_wrapper.ccchrome/browser/android/historical_tab_saver.cc
Estimated timestamp from git blame: 2024-04-29
Description
A potential Use-After-Free (UAF) vulnerability exists in TabRestoreServiceHelper::RestoreEntryById in the non-sandboxed browser process on Android. The issue arises from unsafe raw stack references held across a complex, synchronous C++-to-Java-to-C++ call chain that can mutate the underlying data structure.
In RestoreEntryById, the service looks up the entry to restore and holds raw stack references to it (e.g., auto& group = static_cast<Group&>(entry);). It sets a restoring_ flag and proceeds to call RestoreTab, which eventually bridges into Java via TabModelJniBridge::CreateTab to instantiate the tab in the Android UI.
On the Java side, adding a new tab (TabCollectionTabModelImpl.addTabInternal) synchronously calls commitAllTabClosures(). This ensures any pending "Undo" snackbars are flushed before state changes. Flushing closures triggers a JNI callback into C++ (historical_tab_saver.cc -> TabRestoreServiceHelper::CreateHistoricalGroup or BrowserClosing).
Unlike CreateHistoricalTab, which safely checks if (restoring_) return std::nullopt;, the BrowserClosing and CreateHistoricalGroup methods do not check the restoring_ flag. They immediately add the newly committed historical entry to the front of entries_ and call PruneEntries(). If the service is already at its capacity (kMaxEntries, which is 25), PruneEntries() deletes the oldest entry. If the entry being restored happens to be this oldest entry, it is freed while RestoreEntryById still holds stack references to it.
When the JNI call unwinds, RestoreEntryById uses the now-dangling group reference to call group.tabs.erase(). This vector erasure primitive on attacker-controlled freed memory can lead to arbitrary memory writes or arbitrary free primitives, potentially allowing for arbitrary code execution in the browser process. MiraclePtr does not mitigate this bug as the dangling pointers are raw stack references (auto&) to a plain C++ struct.
Suggested Steps to Reproduce
Note: These are potential steps derived from static analysis; our tooling agent does not have the ability to run code or provide a live Proof of Concept.
- An attacker (or interaction flow) populates the
TabRestoreServiceto its maximum limit (kMaxEntries= 25). The oldest entry (index 24) must be a Group entry with at least two tabs. - The user closes a tab or group of tabs, triggering an "Undo" snackbar (this queues a pending closure in
PendingTabClosureManager). - Before the snackbar expires, the user navigates to "Recent tabs" and restores a single tab from the oldest group entry.
- C++
RestoreEntryByIdgrabs a reference to the oldest group and calls into Java to create the tab. - Java's
addTabInternalforcescommitAllTabClosures(), committing the pending closure from Step 2. - This fires a JNI call back to
TabRestoreServiceHelper::BrowserClosing/CreateHistoricalGroup. - The new entry is pushed to
entries_.PruneEntries()executes and drops the 26th (oldest) entry, freeing the memory of the group currently being restored. - The call stack unwinds to
RestoreEntryById.group.tabs.erase()is executed on the freed memory, causing a UAF.
Suggested Fix
-
Add a
restoring_check toTabRestoreServiceHelper::BrowserClosingandTabRestoreServiceHelper::CreateHistoricalGroup, identical to the one inCreateHistoricalTab. For example:C++ if (restoring_) { return; } -
Alternatively, avoid holding raw C++ references across boundaries that can execute arbitrary UI/JNI delegates. Looking up the entry by ID after the
RestoreTabcall completes would prevent dangling references if the list is mutated.
Evaluated with Chrome root at commit: 096fc8fdbfacf2546485756d03f160a3d04fcc9b
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the code holds raw C++ references to an entry across a call chain that can synchronously mutate the entry list and free that entry, without checking the restoring_ flag in BrowserClosing and CreateHistoricalGroup.
Impact
This vector erasure primitive on attacker-controlled freed memory could lead to arbitrary memory writes or arbitrary free primitives, potentially allowing for arbitrary code execution in the browser process.
What the attacker needed
Android browser; Tab restore service at capacity (25 entries); Oldest entry is a group with at least two tabs; User closes a tab to queue a pending closure
The fix
The fix should add a restoring_ check to BrowserClosing and CreateHistoricalGroup, or avoid holding raw references across boundaries by looking up the entry by ID after RestoreTab completes.
How it was found
- Populate the TabRestoreService to its maximum limit (25 entries), with the oldest entry being a Group with at least two tabs.
- Close a tab or group of tabs to trigger an Undo snackbar, queuing a pending closure.
- Before the snackbar expires, restore a single tab from the oldest group entry via Recent tabs.
- C++ RestoreEntryById grabs a reference to the oldest group and calls into Java to create the tab.
- Java's addTabInternal forces commitAllTabClosures(), committing the pending closure.
- This fires a JNI call back to BrowserClosing / CreateHistoricalGroup, which pushes a new entry and PruneEntries() frees the oldest entry being restored.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A use-after-free happens when a program keeps using a piece of memory after it has been freed. Here, while restoring a tab, the browser frees the very entry it is working on, then writes to that freed memory. This can let an attacker take control of the browser process.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.