Page MenuHomePhabricator

Mark REAL(swapcontext) with indirect_return attribute on x86

Authored by on Jul 20 2018, 10:33 AM.



When shadow stack from Intel CET is enabled, the first instruction of all
indirect branch targets must be a special instruction, ENDBR.

lib/asan/ has


int res = REAL(swapcontext)(oucp, ucp);


REAL(swapcontext) is a function pointer to swapcontext in libc. Since
swapcontext may return via indirect branch on x86 when shadow stack is
enabled, as in this case,

int res = REAL(swapcontext)(oucp, ucp);

^^^^^^^^^^^^^^^^^^^^^^^^^^^^  This function may be

returned via an indirect branch.

Here compiler must insert ENDBR after call, like

call *bar(%rip)

I opened an LLVM bug:

to add the indirect_return attribute so that it can be used to inform
compiler to insert ENDBR after REAL(swapcontext) call. We mark
REAL(swapcontext) with the indirect_return attribute if it is available.

Diff Detail

Event Timeline created this revision.Jul 20 2018, 10:33 AM
Herald added subscribers: Restricted Project, kubamracek. · View Herald TranscriptJul 20 2018, 10:33 AM
eugenis added inline comments.

Please add a __ has_attribute compatibility definition here (same as __ has_feature):

Added a __ has_attribute compatibility definition.

eugenis added inline comments.Jul 20 2018, 12:14 PM

an extra ")"

Remove the extra ")".

This revision is now accepted and ready to land.Jul 20 2018, 12:20 PM
This revision was automatically updated to reflect the committed changes.