Heap-use-after-free in [@ DatabaseFile::WriteSucceededClearBlobImpl] due to missing cross-database actor validation in TransactionBase::VerifyRequestParams
Categories
(Core :: Storage: IndexedDB, defect)
Tracking
()
People
(Reporter: bugmon, Assigned: hsingh)
Details
(7 keywords, Whiteboard: [prefs-checked])
Attachments
(3 files)
|
1.61 KB,
text/html
|
Details | |
|
3.02 KB,
patch
|
Details | Diff | Splinter Review | |
|
7.56 KB,
text/plain
|
Details |
Summary
A heap-use-after-free in the parent process caused by missing validation in TransactionBase::VerifyRequestParams at /firefox/dom/indexedDB/ActorsParent.cpp line ~10398. The parent does not verify that PBackgroundIDBDatabaseFileParent actors referenced in FileAddInfo are managed by the same Database as the receiving transaction. A compromised content process can therefore inject a file actor belonging to Database A into an add/put request on Database B. Since each database runs its operations on a separate connection thread, the single-thread-owned DatabaseFile::mBlobImpl (an InitializedOnce<const RefPtr<BlobImpl>>) gets destroyed on one thread while still being read on another.
Affected Code
File: dom/indexedDB/ActorsParent.cpp, line ~10398
for (const FileAddInfo& fileAddInfo : aParams.fileAddInfos()) {
const PBackgroundIDBDatabaseFileParent* file =
fileAddInfo.file().AsParent();
switch (fileAddInfo.type()) {
case StructuredCloneFileBase::eBlob:
if (NS_AUUF_OR_WARN_IF(!file)) {
return false;
}
// MISSING: no check that file->Manager() == this transaction's Database
break;
The IPDL layer only guarantees that file is some live PBackgroundIDBDatabaseFileParent on this channel — it does not guarantee it is managed by the specific PBackgroundIDBDatabaseParent that owns this transaction. Without an explicit manager check, a malicious child can pass any file actor from any database.
The consequence is in DatabaseFile at line 2486-2529:
// mBlobImpl's ownership lifecycle:
// - Initialized on the background thread at creation time. Then
// responsibility is handed off to the connection thread.
// - Checked and used by the connection thread to generate a stream...
// - Cleared on the connection thread once the file has successfully been
// written to disk.
InitializedOnce<const RefPtr<BlobImpl>> mBlobImpl;
...
void WriteSucceededClearBlobImpl() {
MOZ_ASSERT(!IsOnBackgroundThread());
MOZ_ASSERT(*mBlobImpl);
mBlobImpl.destroy(); // <-- not thread-safe; assumed single connection thread
}
InitializedOnce::destroy() and the corresponding GetInputStream() reads of mBlobImpl have no synchronization because the design assumes a single owning connection thread.
Correct Pattern
case StructuredCloneFileBase::eBlob:
if (NS_AUUF_OR_WARN_IF(!file)) {
return false;
}
// Reject actors managed by a different Database
if (NS_AUUF_OR_WARN_IF(file->Manager() !=
static_cast<const PBackgroundIDBDatabaseParent*>(
&GetDatabase()))) {
return false;
}
break;
Exploit Chain
- Compromised content process opens multiple IndexedDB databases (e.g., 16) under the same origin. Each gets its own
Databaseactor and its own connection-threadTaskQueuein the parent'sConnectionPool. - Content process creates a single
PBackgroundIDBDatabaseFileChildactor on Database A (viaPBackgroundIDBDatabaseFileConstructor). - Content process sends
ObjectStoreAddParams/ObjectStorePutParamsto transactions on Databases B, C, D, … each containing aFileAddInfothat references the actor from step 2. - Parent's
TransactionBase::VerifyRequestParamsaccepts each request because it only checks!file, notfile->Manager(). - Each database's connection thread runs
ObjectStoreAddOrPutRequestOp::DoDatabaseWork, which callsStoredFileInfo::GetInputStream()→DatabaseFile::GetInputStream()(readsmBlobImpl) and, on successful write,StoredFileInfo::NotifyWriteSucceeded()→DatabaseFile::WriteSucceededClearBlobImpl()→mBlobImpl.destroy(). - Because steps 5 run concurrently on different connection threads against the same
DatabaseFile, one thread frees theStreamBlobImplwhile another dereferences it (or both calldestroy()concurrently), producing a heap-use-after-free.
IPC Path
- IPDL protocols:
PBackgroundIDBDatabase(managesPBackgroundIDBDatabaseFileandPBackgroundIDBTransaction),PBackgroundIDBTransaction(managesPBackgroundIDBRequest) - Parent side:
Database,TransactionBase,DatabaseFile,ObjectStoreAddOrPutRequestOpindom/indexedDB/ActorsParent.cpp - Child side:
IDBDatabase,IDBObjectStoreindom/indexedDB/ - Message flow: child sends
PBackgroundIDBDatabaseFileConstructoron DB-A → child sendsPBackgroundIDBRequestConstructor(ObjectStorePutParams{ fileAddInfos: [ {file: actor-from-DB-A} ] })on transactions belonging to DB-B…N → parent dispatches to each DB's connection thread without rejecting the foreign actor.
Steps to Reproduce
- Apply the provided exploit patch to
dom/indexedDB/IDBObjectStore.cpp(simulates a compromised content process by creating the file actor on the first-opened database and reusing it in all subsequent databases' put requests). - Rebuild Firefox.
- Load the testcase HTML which opens 16 databases and loops 2000 iterations of concurrent
put()of the same Blob into all databases. Race typically triggers within a few seconds.
Security Impact
- Severity: High (sec-high). Parent-process heap-use-after-free reachable from a compromised content process → sandbox escape primitive.
- Attacker capability: A content-process RCE can use this to corrupt parent-process heap memory. The freed
StreamBlobImpl(184 bytes) can be reclaimed with attacker-controlled data between the free on one thread and the vtable dereference inCreateInputStreamon another thread, potentially leading to parent-process code execution. - Preconditions: Requires a prior content-process compromise (standard sandbox-escape threat model). No non-default prefs required.
ASAN Report
==152677==ERROR: AddressSanitizer: heap-use-after-free on address 0x7633442897a0 at pc 0x753320b5d66f bp 0x753295f57190 sp 0x753295f57188
READ of size 8 at 0x7633442897a0 thread T86
#0 0x753320b5d66e in mozilla::dom::StreamBlobImpl::CreateInputStream(nsIInputStream**, mozilla::ErrorResult&) const /firefox/dom/file/StreamBlobImpl.cpp:142:66
#1 0x753323e09c26 in mozilla::dom::indexedDB::(anonymous namespace)::DatabaseFile::GetInputStream(mozilla::ErrorResult&) const /firefox/dom/indexedDB/ActorsParent.cpp:2569:17
#2 0x753323e09c26 in mozilla::dom::indexedDB::(anonymous namespace)::ObjectStoreAddOrPutRequestOp::StoredFileInfo::GetInputStream()::$_1::operator()(RefPtr<mozilla::dom::indexedDB::(anonymous namespace)::DatabaseFile> const&) const /firefox/dom/indexedDB/ActorsParent.cpp:3929:43
...
#8 0x753323e09c26 in mozilla::dom::indexedDB::(anonymous namespace)::ObjectStoreAddOrPutRequestOp::DoDatabaseWork(mozilla::dom::indexedDB::(anonymous namespace)::DatabaseConnection*) /firefox/dom/indexedDB/ActorsParent.cpp:19262:9
#9 0x753323deb62c in mozilla::dom::indexedDB::(anonymous namespace)::TransactionDatabaseOperationBase::RunOnConnectionThread() /firefox/dom/indexedDB/ActorsParent.cpp:17304:14
#10 0x753323de9770 in mozilla::dom::indexedDB::(anonymous namespace)::TransactionDatabaseOperationBase::Run() /firefox/dom/indexedDB/ActorsParent.cpp:17472:7
#11 0x7533187e95f7 in mozilla::TaskQueue::Runner::Run() /firefox/xpcom/threads/TaskQueue.cpp:309:20
#12 0x7533188391b7 in nsThreadPool::Run() /firefox/xpcom/threads/nsThreadPool.cpp:444:14
0x7633442897a0 is located 96 bytes inside of 184-byte region [0x763344289740,0x7633442897f8)
freed by thread T81 here:
#0 0x58d7c77516d6 in __interceptor_free
#1 0x753320b5a3f5 in mozilla::dom::BlobImpl::Release() /firefox/dom/file/BlobImpl.cpp:96:1
#2 0x753320b5a3f5 in mozilla::dom::StreamBlobImpl::Release() /firefox/dom/file/StreamBlobImpl.cpp:22:1
...
#9 0x753323e0ae4f in mozilla::dom::indexedDB::(anonymous namespace)::DatabaseFile::WriteSucceededClearBlobImpl() /firefox/dom/indexedDB/ActorsParent.cpp:2529:15
#10 0x753323e0ae4f in mozilla::dom::indexedDB::(anonymous namespace)::ObjectStoreAddOrPutRequestOp::StoredFileInfo::NotifyWriteSucceeded() const /firefox/dom/indexedDB/ActorsParent.cpp:3909:11
#11 0x753323e0ae4f in mozilla::dom::indexedDB::(anonymous namespace)::ObjectStoreAddOrPutRequestOp::DoDatabaseWork(mozilla::dom::indexedDB::(anonymous namespace)::DatabaseConnection*) /firefox/dom/indexedDB/ActorsParent.cpp:19312:26
#12 0x753323deb62c in mozilla::dom::indexedDB::(anonymous namespace)::TransactionDatabaseOperationBase::RunOnConnectionThread() /firefox/dom/indexedDB/ActorsParent.cpp:17304:14
previously allocated by thread T9 here:
#0 0x58d7c7751974 in __interceptor_malloc
...
#3 0x753320b5a579 in mozilla::dom::StreamBlobImpl::Create(...) /firefox/dom/file/StreamBlobImpl.cpp:76:43
#4 0x753320b6bcfa in mozilla::dom::IPCBlobUtils::Deserialize(mozilla::dom::IPCBlob const&) /firefox/dom/file/ipc/IPCBlobUtils.cpp:53:16
#5 0x753323dd79eb in mozilla::dom::indexedDB::(anonymous namespace)::Database::AllocPBackgroundIDBDatabaseFileParent(mozilla::dom::IPCBlob const&) /firefox/dom/indexedDB/ActorsParent.cpp:9685:30
SUMMARY: AddressSanitizer: heap-use-after-free
Suggested Fix
Add a manager check in TransactionBase::VerifyRequestParams(const ObjectStoreAddPutParams&) immediately after the null check:
case StructuredCloneFileBase::eBlob:
if (NS_AUUF_OR_WARN_IF(!file)) {
return false;
}
// Reject actors managed by a different Database
if (NS_AUUF_OR_WARN_IF(file->Manager() !=
static_cast<const PBackgroundIDBDatabaseParent*>(
&GetDatabase()))) {
return false;
}
break;
This ensures every referenced file actor belongs to the transaction's own database, preserving the single-connection-thread invariant that DatabaseFile::mBlobImpl depends on.
| Reporter | ||
Comment 1•7 months ago
|
||
| Reporter | ||
Comment 2•7 months ago
|
||
| Reporter | ||
Comment 3•7 months ago
|
||
Updated•7 months ago
|
Comment 5•7 months ago
|
||
Smells like a dup of https://bugzilla.mozilla.org/show_bug.cgi?id=2021894
Comment 6•7 months ago
|
||
(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #5)
Smells like a dup of https://bugzilla.mozilla.org/show_bug.cgi?id=2021894
The bot also highlighted this. But that bug is fixed and the image should be newer. I'll let the triage bot actually try to reproduce and then close.
Updated•7 months ago
|
Updated•7 months ago
|
Updated•7 months ago
|
Comment 7•7 months ago
|
||
Confirming this is a duplicate of bug 2021894. The manager-chain check that comment 0 describes as missing is already present in current trunk at dom/indexedDB/ActorsParent.cpp:10407-10412:
// Reject actors managed by a different Database
if (NS_AUUF_OR_WARN_IF(file->Manager() !=
static_cast<const PBackgroundIDBDatabaseParent*>(
&GetDatabase()))) {
return false;
}
This landed in rev 4f187245066f on 2026-03-26, five days before this bug was filed. The code snippet quoted in comment 0 shows the pre-fix state, so the reporter ran against a stale source snapshot. The fix covers the only case (eBlob) that dereferences the file actor; all other FileAddInfo types already return false unconditionally, so there is no remaining variant.
No prefs required ([prefs-checked] added); the exploit patch modifies only content-process code, which is the standard compromised-renderer threat model.
This is an automated analysis result. If this result is incorrect please add a needinfo and feel free to correct the error.
| Assignee | ||
Comment 8•7 months ago
|
||
above analysis looks good to me and as an author of the duplicate bug, I am resolving this as a duplicate.
| Assignee | ||
Updated•7 months ago
|
Updated•6 months ago
|
Description
•