This is an archive of the discontinued LLVM Phabricator instance.

Plug dlerror() leak for swift_demangle
ClosedPublic

Authored by krytarowski on Nov 22 2017, 10:16 PM.

Details

Summary

InitializeSwiftDemangler() attempts to resolve the
swift_demangle symbol. If this is not available, we
observe dlerror message leak.

Caught on NetBSD/amd64 in TSan.

Sponsored by <The NetBSD Foundation>

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.Nov 22 2017, 10:16 PM
dvyukov accepted this revision.Nov 25 2017, 4:41 AM
This revision is now accepted and ready to land.Nov 25 2017, 4:41 AM
krytarowski closed this revision.Nov 25 2017, 8:47 AM
marcan added a subscriber: marcan.EditedMar 13 2023, 2:39 AM

FYI, this introduces a subtle regression. dlerror() calls into gettext to translate the error. ASAN itself can be initialized from a random malloc intercept which can turn out to be in gettext, which is quite common since apps initialize gettext early, and some libraries even do so in loader init calls. This ends up re-entering into gettext and corrupting a rwmutex by trying to take the write lock while the read-side is locked. The unlock sequence leaves the rwlock in a bad state. Things then deadlock much later on the bad mutex.

Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 2:39 AM
pcc added a subscriber: pcc.Mar 21 2023, 5:52 PM

FYI, this introduces a subtle regression. dlerror() calls into gettext to translate the error. ASAN itself can be initialized from a random malloc intercept which can turn out to be in gettext, which is quite common since apps initialize gettext early, and some libraries even do so in loader init calls. This ends up re-entering into gettext and corrupting a rwmutex by trying to take the write lock while the read-side is locked. The unlock sequence leaves the rwlock in a bad state. Things then deadlock much later on the bad mutex.

Looks like this was fixed by D128992 by removing the call to dlerror().