Potential UAFs caused by SafeRefPtr::operator=(SafeRefPtr &&)
The move assignment operator for SafeRefPtr does not check for self-assignment, so assigning an object to itself can incorrectly decrement its reference count. This could lead to a use-after-free in other code that uses the object.
Originally disclosed on Mozilla
- Fixed in 11 days
- Paid in 12 days
- Disclosed after 11 days
`SafeRefPtr::operator=(SafeRefPtr &&)` (`dom/indexedDB/SafeRefPtr.h`) doesn't check for self-assignment. If self-assignment occurs, the function spuriously decrements the reference count of its `mRawPtr` member, likely causing a UAF in other code that uses the object to which `mRawPtr` points.
There are several uses of this operator that might be unsafe, though many other usages are of the form `object = nullptr`, which is clearly safe. From `FIREFOX_122_0_RELEASE`:
'''
221: SafeRefPtr& operator=(SafeRefPtr&& aOther) noexcept {
222: assign_assuming_AddRef(aOther.mRawPtr);
223: aOther.mRawPtr = nullptr;
224: return *this;
225: }
166: void assign_assuming_AddRef(T* aNewPtr) {
167: T* oldPtr = mRawPtr;
168: mRawPtr = aNewPtr;
169: if (oldPtr) {
170: ConstRemovingRefPtrTraits<T>::Release(oldPtr);
171: }
172: }
'''
The fix is trivial and low risk.
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 move assignment operator lacks a self-assignment check, so it releases the old pointer even when the new pointer is the same object.
Impact
This could cause a use-after-free in code that uses the object, though the report notes that many usages are safe and only some might be unsafe.
What the attacker needed
Self-assignment of SafeRefPtr
The fix
The fix is trivial and low risk, likely by adding a self-assignment check.
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 reference count tracks how many parts of a program are using an object, and when it reaches zero the object is freed. If the count is wrongly decreased, the object might be freed while still in use, leading to a use-after-free bug where the program accesses memory that is no longer valid. This report points out that a specific assignment operation can cause that wrong decrease when an object is assigned to itself.
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.