[cairo-bugs] [Bug 69470] New: Race in _cairo_toy_font_face_destroy

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Tue Sep 17 07:13:12 PDT 2013


https://bugs.freedesktop.org/show_bug.cgi?id=69470

          Priority: medium
            Bug ID: 69470
          Assignee: chris at chris-wilson.co.uk
           Summary: Race in _cairo_toy_font_face_destroy
        QA Contact: cairo-bugs at cairographics.org
          Severity: normal
    Classification: Unclassified
                OS: All
          Reporter: clockworksaint at gmail.com
          Hardware: Other
            Status: NEW
           Version: 1.12.14
         Component: general
           Product: cairo

When creating and destroying toy font faces concurrently on multiple threads,
sometimes an assertion is raised:

/build/buildd/cairo-1.12.14/src/cairo-hash.c:506:
_cairo_hash_table_lookup_exact_key: Assertion `!"reached"' failed.

I first observed this in Mono:

https://bugzilla.xamarin.com/show_bug.cgi?id=2426


I asked about it on the mailing list and someone confirmed that it occurs even
in a trivial C program:

http://lists.cairographics.org/archives/cairo/2013-September/024667.html


I think this is the sequence of events:

Thread A runs cairo_toy_font_face_create to create a font. It completes
normally and is added to cairo_toy_font_face_hash_table.

Thread A decrefs the font face. Its refcount drops to 0, and
_cairo_toy_font_face_destroy will run, except--

Thread B runs cairo_toy_font_face_create to create the same font. It is found
in the hash table, a reference is added, and it is returned.

Thread B decrefs the font face. Its refcount drops to 0.

Thread B runs _cairo_toy_font_face_destroy.

Thread B acquires the lock on the hash table, confirms that the refcount is
still 0, then removes the hash table entry, releases the lock and goes on to
deallocate the font.

Thead A wakes up and continues running _cairo_toy_font_face_destroy. It
acquires the lock on the hash table, and - uh-oh! - it confirms that the
refcount is still 0. It is! (I think this was potentially an access-after-free,
too.) Thread A tries to remove the font from the hash table, and asserts.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo-bugs/attachments/20130917/692ca84c/attachment.html>


More information about the cairo-bugs mailing list