Undefined behavior in ShmemCharMapHashEntry
Originally disclosed on Mozilla
- Fixed in 16 days
- Paid in 20 days
- Disclosed after 16 days
`ShmemCharMapHashEntry` (`gfx/thebes/gfxPlatformFontList.h`) invokes undefined behavior because it hasa `mozilla::fontlist::Pointer` which hasa `std::atomic<uint32_t>`, which is not guaranteed to be trivially copyable. Yet `ShmemCharMapHashEntry` is declared as `ALLOW_MEMMOVE = true`, which allows `nsHashtable` to move it using `memmove()` instead of by calling its move constructor/move assignment operator. `memcpy/memmove`ing is valid only for "trivially copyable" types; see C++ Standard N4750 s.6.7(1-3). Nothing in the Standard requires `std::atomic` to be trivially copyable, so this operation is UB. Indeed, `std::` classes can be implemented in any manner that produces the correct observable behavior, N4750 s.4.1.1, unless explicitly documented otherwise.
Source from `FIREFOX_123_0_1_RELEASE`:
(`gfx/thebes/gfxPlatformFontList.h`):
'''
89: class ShmemCharMapHashEntry final : public PLDHashEntryHdr {
...
127: enum { ALLOW_MEMMOVE = true };
128:
129: private:
130: // charMaps are stored in the shared memory that FontList objects point to,
131: // and are never deleted until the FontList (all referencing font lists,
132: // actually) have gone away.
...
134: mozilla::fontlist::Pointer mCharMap;
...
136: };
'''
(`gfx/thebes/SharedFontList.h`):
'''
28: struct Pointer {
...
101: // We store the block index and the offset within the block as a single
102: // atomic 32-bit value so we can safely modify a Pointer without other
103: // processes seeing a broken (partially-updated) value.
104: std::atomic<uint32_t> mBlockAndOffset;
105: };
'''
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A low-severity security bug in Graphics: Text. Mozilla made it public on 5 April 2024 as CVE-2024-4774.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.