This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] [windows] Add more assembly patterns for interception
ClosedPublic

Authored by toshi on Sep 16 2021, 7:04 PM.

Details

Summary

To intercept the functions in Win11's ntdll.dll, we need to use the trampoline
technique because there are bytes other than 0x90 or 0xcc in the gaps between
exported functions. This patch adds more patterns that appear in ntdll's
functions.

Bug: https://bugs.llvm.org/show_bug.cgi?id=51721

Diff Detail

Event Timeline

toshi created this revision.Sep 16 2021, 7:04 PM
toshi requested review of this revision.Sep 16 2021, 7:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2021, 7:04 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
timurrrr edited reviewers, added: rnk; removed: timurrrr.Sep 16 2021, 8:23 PM
rnk accepted this revision.Sep 20 2021, 12:29 PM

lgtm, thanks for the patch. Would you like me to push it for you? Would you like me to exclude or include your email from the Author record?

This revision is now accepted and ready to land.Sep 20 2021, 12:29 PM
toshi added a comment.Sep 20 2021, 6:20 PM

lgtm, thanks for the patch. Would you like me to push it for you? Would you like me to exclude or include your email from the Author record?

Thank you for reviewing my patch! Yes, I'd like you to land this on my behalf. Please include my email to the record if possible. That's an honor.

This revision was landed with ongoing or failed builds.Sep 21 2021, 3:52 PM
This revision was automatically updated to reflect the committed changes.

Note that we should get in contact with the Windows maintainers about this. Windows OS dlls are built with /HOTPATCH and should all be hotpatchable. It's unclear what the leading junk in the hotpatch padding is.

I've followed up with people more knowledgeable than myself. The unknown leading bytes in the padding region are XFG hashes and can be safely overwritten as long as XFG is not enabled for the process. (XFG is an eXtension of CFG, control flow guard)
I can't imagine many people will have both ASan and XFG enabled at the same time so I think the interception logic should just always assume there is padding before Windows OS functions.