This is an archive of the discontinued LLVM Phabricator instance.

[asan] Intercept and wrap XPC callback blocks
ClosedPublic

Authored by kubamracek on Aug 31 2015, 2:33 AM.

Details

Summary

On recent OS X systems, blocks used as callbacks for XPC events (set up e.g. via xpc_connection_set_event_handler) are not later executed via the public libdispatch API (dispatch_async, etc). Because we don't intercept the path where the block is executed, we can fail to register the newly created dispatch thread. To fix that, let's intercept libxpc's APIs that take a block as a callback handler, and let's wrap these blocks in the same way as we do for libdispatch API.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek updated this revision to Diff 33562.Aug 31 2015, 2:33 AM
kubamracek retitled this revision from to [asan] Intercept and wrap XPC callback blocks.
kubamracek updated this object.
kubamracek added reviewers: samsonov, glider.
kubamracek added subscribers: llvm-commits, samsonov, glider and 2 others.
glider edited edge metadata.Sep 4 2015, 9:05 AM

How does this test check that the underlying thread(s) has been correctly registered?
Should we make the callback crash to make sure the report is correct?

lib/asan/asan_mac.cc
47 ↗(On Diff #33562)

While at it, can you please fix the inclusion order?

test/asan/TestCases/Darwin/xpc_interceptors.mm
29 ↗(On Diff #33562)

Why pass trace[0] to fprintf here?

How does this test check that the underlying thread(s) has been correctly registered?
Should we make the callback crash to make sure the report is correct?

__asan_get_alloc_stack will internally try to retrieve the thread from ThreadRegistry, which will currently (without the patch) crash.

glider added a comment.Sep 4 2015, 9:14 AM

Got it. Can you please add a comment about this?

Got it. Can you please add a comment about this?

I'll change the test to perform a buffer overflow or something, that'll be better.

kubamracek updated this revision to Diff 34134.Sep 7 2015, 3:05 AM
kubamracek edited edge metadata.

Updating patch to perform a buffer overflow in the XPC callback thread. Added comment explaining the bug. Fixed inclusion order.

glider accepted this revision.Sep 7 2015, 4:11 AM
glider edited edge metadata.

LGTM if xpc.h available on all OSX versions for which ASan is supported.

lib/asan/asan_mac.cc
47 ↗(On Diff #34134)

Is this header available on all OSX versions we're targeting?

This revision is now accepted and ready to land.Sep 7 2015, 4:11 AM

Yes, the APIs and the header is available on 10.7+.

This revision was automatically updated to reflect the committed changes.

Reverted in r246967. The header's not available in the simulator SDK.