Skip to content
Memory corruption Disclosed report Advanced CVE-2023-6863

Undefined behavior in ShutdownObserver()

The ShutdownObserver deletes objects through a base-class pointer that lacks a virtual destructor, causing undefined behaviour. An attacker could potentially exploit this to cause memory corruption or a crash, though the report does not demonstrate a practical attack.

mozillabugs Follow

Originally disclosed on Mozilla

  • Fixed in 3 days
  • Paid in 12 days
  • Disclosed after 3 days
Text
`ShutdownObserver` (`widget/GfxInfoBase.cpp`) invokes undefined behavior by deleting an object whose static type lacks a virtual destructor, where the object has a derived-class dynamic type. [1]

The issue concerns the three arrays in `widget/GfxDriverInfo.h` (line numbers are from trunk):

'''
    351: static nsAString* sWindowProtocol[static_cast<size_t>(WindowProtocol::Max)];
    ...
    355: static nsAString* sDeviceVendors[static_cast<size_t>(DeviceVendor::Max)];
    ...
    358: static nsAString* sDriverVendors[static_cast<size_t>(DriverVendor::Max)];
'''

These arrays' elements are assigned `nsString*` pointers by `GfxDriverInfo::GetWindowProtocol()`, `GfxDriverInfo::GetDeviceVendor()`, and `GfxDriverInfo::GetDriverVendor()`, respectively, e.g. from `widget/GfxDriverInfo.cpp`:

'''
    602: const nsAString& GfxDriverInfo::GetWindowProtocol(WindowProtocol id) {
    ...
    613:  sWindowProtocol[idx] = new nsString();
'''

and are deleted by `ShutdownObserver::Observe()` (`widget/GfxInfoBase.cpp`):

'''
71: NS_IMETHOD Observe(nsISupports* subject, const char* aTopic,
72:                     const char16_t* aData) override {
...
83:    for (auto& windowProtocol : GfxDriverInfo::sWindowProtocol) {
84:      delete windowProtocol;
85:      windowProtocol = nullptr;
86:    }
87:
88:    for (auto& deviceVendor : GfxDriverInfo::sDeviceVendors) {
89:      delete deviceVendor;
90:      deviceVendor = nullptr;
91:    }
92:
93:    for (auto& driverVendor : GfxDriverInfo::sDriverVendors) {
94:      delete driverVendor;
95:      driverVendor = nullptr;
96:    }
'''

But `nsString` is an alias for `nsTString<char16_t>`, which isa `nsTSubstring<char16_t>`. Whereas, `nsAString` is an alias for `nsTSubstring<char16_t>`. So the assignment is of a derived class pointer to a base class pointer. But the base class `nsTSubstring<char16_t>` lacks a virtual destructor, despite the quizzical comment from `xpcom/string/nsTSubstring.h`:

'''
    325:  // this acts like a virtual destructor
    326:  ~nsTSubstring() { Finalize(); }
'''

[1] See C++ 20 Standard (n4750) s.8.5.2.5(3) : "In a single-object delete expression, if the static type of the object to be deleted is different from its dynamic type, the static type shall be a base class of the dynamic type of the object to be deleted and the static type shall have a virtual destructor or the behavior is undefined."

The original report as published on Mozilla's Bugzilla, by mozillabugs. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

The base class nsTSubstring<char16_t> does not have a virtual destructor, so deleting a derived nsString object through a base-class pointer is undefined behaviour.

Impact

This could lead to memory corruption or a crash, but the report does not show a practical exploit.

What the attacker needed

None

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.

In C++, when you delete an object through a pointer to a base class, the base class must have a virtual destructor. Otherwise, the program's behaviour is undefined, meaning it might crash or corrupt memory. Here, the code deletes a string object using a base-class pointer that lacks a virtual destructor.

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.

More by mozillabugs

View all

41 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.