Skip to content
Race condition Disclosed report Advanced

[tsan] data race initializing the SharedFTFace in gfxFontconfigFontEntry::GetFTFace

A data race exists in the fontconfig font backend where two threads can initialise the same FreeType face object concurrently without synchronisation. The text only claims a ThreadSanitizer warning from a testcase, not an exploitable security impact.

Jonathan Kew Follow

Originally disclosed on Mozilla

  • Fixed in 6 days
  • Paid in 12 days
  • Disclosed after 6 days
Text
+++ This bug was initially created as a clone of Bug #1823365 +++

After fixing the originally-reported missing-glyph atlas issue, Tyson is still seeing another, unrelated data race with the same testcase; see bug 1823365 comment 11, and attachment 9324553.

The race here involved the fontconfig backend and its management of the FreeType face:
'''
WARNING: ThreadSanitizer: data race (pid=104338)
  Read of size 8 at 0x7b5400001d60 by thread T18:
    #0 RefPtr /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:97:27 (libxul.so+0x5917041) (BuildId: 9ee4bdacd12c56311ad459908123f344c17c0ace)
    #1 gfxFontconfigFontEntry::CreateFontInstance(gfxFontStyle const*) /builds/worker/checkouts/gecko/gfx/thebes/gfxFcPlatformFontList.cpp:859:31 (libxul.so+0x5917041)
    #2 gfxFontEntry::FindOrMakeFont(gfxFontStyle const*, gfxCharacterMap*) /builds/worker/checkouts/gecko/gfx/thebes/gfxFontEntry.cpp:266:22 (libxul.so+0x5947cfe) (BuildId: 9ee4bdacd12c56311ad459908123f344c17c0ace)
'''
vs
'''
  Previous write of size 8 at 0x7b5400001d60 by thread T20:
    #0 assign_assuming_AddRef /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:71:13 (libxul.so+0x59162e3) (BuildId: 9ee4bdacd12c56311ad459908123f344c17c0ace)
    #1 operator=<mozilla::gfx::SharedFTFace> /builds/worker/workspace/obj-build/dist/include/mozilla/RefPtr.h:226:5 (libxul.so+0x59162e3)
    #2 gfxFontconfigFontEntry::GetFTFace() /builds/worker/checkouts/gecko/gfx/thebes/gfxFcPlatformFontList.cpp:941:13 (libxul.so+0x59162e3)
    #3 gfxFontconfigFontEntry::CreateFontInstance(gfxFontStyle const*) /builds/worker/checkouts/gecko/gfx/thebes/gfxFcPlatformFontList.cpp:859:31 (libxul.so+0x5917036) (BuildId: 9ee4bdacd12c56311ad459908123f344c17c0ace)
    #4 gfxFontEntry::FindOrMakeFont(gfxFontStyle const*, gfxCharacterMap*) /builds/worker/checkouts/gecko/gfx/thebes/gfxFontEntry.cpp:266:22 (libxul.so+0x5947cfe) (BuildId: 9ee4bdacd12c56311ad459908123f344c17c0ace)
'''

I guess the root of the problem here is that the `mFTFace` and `mFTFaceInitialized` members of `gfxFontconfigFontEntry` are not guarded or atomic, so we have a problem if two threads call GetFTFace() on the same (not-yet-initialized) entry at the same time.

The original report as published on Mozilla's Bugzilla, by Jonathan Kew. 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

Likely the shared font-face pointer and its initialisation flag are plain members read and written by multiple threads without a lock or atomic operation.

Impact

The race could cause undefined behaviour in the font code, but the text shows no security impact beyond the sanitiser warning.

What the attacker needed

A testcase that triggers concurrent font loading

The fix

The shared face pointer and its initialisation state should be guarded by a lock or made atomic so concurrent callers cannot race.

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.

When two parts of a program run at the same time (threads) and touch the same shared value without coordination, the result can be unpredictable; this is called a data race. Here two threads could both try to set up the same font object at once, and a checking tool flagged it. The report does not show any way for an attacker to abuse it.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by Jonathan Kew

View all

1 more disclosed report, 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.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.