This is an archive of the discontinued LLVM Phabricator instance.

Prevent double release of mach ports
ClosedPublic

Authored by friss on Mar 28 2018, 6:04 PM.

Details

Summary

When a MIG routine returns KERN_FAILURE, the demux function will release any OOL resources like ports. In this case, task_port and thread_port will be released twice, potentially resulting in use after free of the ports.

I don't think we can test this in any useful way
rdar://problem/37331387

Diff Detail

Repository
rL LLVM

Event Timeline

friss created this revision.Mar 28 2018, 6:04 PM

Yes, this is one of the required MIG functions, but it isn't the flavor we register to receive callbacks on (we pass EXCEPTION_DEFAULT to task_set_exception_ports), so this function should never get called. That makes it doubly hard to test!

davide added a subscriber: davide.Mar 28 2018, 6:34 PM

I'm not particularly worried about testing double-free behavior, FWIW.
Ideally we should, but, I really understand it's a PITA. I think we might get this for free when testing msan/asan (or just running under valgrind), assuming there was already coverage for this path.
(and if there wasn't, well, it's a separate issue).

Because of the mysteries of MIG, all the flavors of catch_exception_raise have to be defined, but you register for a particular flavor when you set the task exception ports. This isn't the flavor we register. So this function is necessary but never used.

jasonmolenda accepted this revision.Mar 28 2018, 6:50 PM

valgrind/asan/msan aren't going to help - this is a pretty obscure stuff. We could verify by hand that we're not leaking a port if this code was actually executed via lsmp(1) on macos, but Jim knows more about our MIG use than I do & I'm sure he's right that this code is never called. LGTM.

This revision is now accepted and ready to land.Mar 28 2018, 6:50 PM
This revision was automatically updated to reflect the committed changes.