0

We know we can randomize the code,data/stack/heap by compile the code as PIE. While the code and data always have a fixed offset on each loading.

Is there a way that by adding some compile/link flags we can set code/data offset a random value?

xiaogw
  • 653
  • 8
  • 18

1 Answers1

0

The ASLR randomization algorithm always rounds to the page boundary, so there is no practical ability to change this at load-time.

If you want to adjust addresses at compile time, you can try altering the function address alignment (e.g. using -falign-functions=...); but you would be leaving windows in the code that could be used as trampoline locations.

Those offsets are defined in the ELF section data, so altering the offsets would involve altering those values before they get to the linker e.g. by making modifications to the link script.

If you pass -Wl,-verbose, you'll get a dump of the linker script that's used to generate the binary, and you could make adjustments to that script - it's different if you compile a pie file rather than a regular binary.

I don't know of any convenient flags that would allow you to alter the offset of the segments. Using the -Ttext option disables ASLR for the code segment, which is exactly the opposite of what you want.

Mind you, the linked paper seems to indicate that tools could be written to perform this without too much difficulty.

Too long for a comment, and probably not the answer you're looking for.

Community
  • 1
  • 1
Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122