Why do Compilers put data inside .text(code) section of the PE and ELF files and how does the CPU distinguish between data and code?

前端 未结 2 1691
故里飘歌
故里飘歌 2020-12-10 18:14

So i am referencing this paper :

Binary Stirring: Self-randomizing Instruction Addresses of Legacy x86 Binary Code

https://www.utdallas.edu/~hamlen/wartell1

2条回答
  •  悲&欢浪女
    2020-12-10 18:31

    1. Interleaving code and data will keep the data closer to the code that use it. This will make the data accessible by simpler and faster instructions.
    2. The CPU doesn't, it is up to the programmer/compiler to make sure that the data is put in locations outside the actual program flow. If the program flow accidentally enters the data block the CPU will interpret the data as instructions. Normally the data is placed between functions but sometimes the compiler can add an extra branch instruction to make place for a data block inside a function.
    3. Normally this is not a problem since the programmer or compiler make sure that the data section is not entered by the program flow, but you are partially right since if an attacker manage to trick the CPU into execute the data this will not be caught by the memory protection mechanisms.

提交回复
热议问题