Skip to content

Commit

Permalink
i#1569 AArch64: Implement tests/security-common/codemod.c.
Browse files Browse the repository at this point in the history
Make code 4-byte aligned and call __clear_cache.

Review-URL: https://codereview.appspot.com/295370043
  • Loading branch information
egrimley-arm committed Jun 2, 2016
1 parent 43f52fc commit 8b29fdc
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions suite/tests/security-common/codemod.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,41 @@
#define ON_STACK 1

#if !ON_STACK
char buf[32];
unsigned int buf[8];
#endif

int
main()
{
#if ON_STACK
char buf[32];
unsigned int buf[8];
#endif
char *foo = buf;
void (*foo)(void) = (void *)buf;

INIT();
print("starting up\n");

#ifdef X86
buf[0] = 0xc3; /* ret */
#if defined(X86)
*(unsigned char *)buf = 0xc3; /* ret */
#elif defined(ARM)
buf[0] = 0xe12fff1e; /* bx lr */
#elif defined(AARCH64)
buf[0] = 0xd65f03c0; /* ret */
#else
/* XXX i#1639: this results in SIGILL natively even though we have
* execstack and this is a transition to ARM. This runs fine under
* DR but apparently that's a transparency violation as it should crash
* for reasons unknown.
# error NYI
#endif

#ifndef X86
/* The call to __clear_cache is not required on Intel, and the function
* may not be provided by all compilers.
*/
*(int*)buf = 0xe12fff1e; /* bx lr */
__clear_cache(buf, buf + sizeof(buf));
#endif
((void (*)(void)) foo)();

foo();

print("about to exit\n");

buf[1] = 0xc3; /* ret */
((unsigned char *)buf)[1] = 0xc3;
return 0;
}

0 comments on commit 8b29fdc

Please sign in to comment.