Is there something that prevents stack overflows in the assembly?

In assembly language programming, what (if anything) prevents the stack from growing until it dumps data or instructions?

+4
source share
4 answers

What (if anything) is preventing the stack from growing and dropping data or instructions?

YOU! When assembling in assembly, there is no hand. You have to make sure that all values ​​fit into their buffers, all pointer pointers are within. You leave space on the stack, make sure that all this fits into this buffer. You are responsible for all aspects of programming when using Assembly.

+2
source

Only the CPU / MMU configuration, which is usually performed by the OS, can prevent or intercept stack overflows and memory corruption or attempts to access something without the necessary privileges.

You can read the memory management chapters in the Intel / AMD x86 processor manuals to learn more.

+5
source

You can use canaries directly below the accepted bottom of the stack and constantly check the canary values.

In kernelland code (ring 0), you can also set a hardware breakpoint by setting the value of one of the debug registers dr0 , dr1 , dr2 and dr3 to the linear address of the breakpoint address, directly below the accepted lower border of the stack, and then set the correct bit of the dr7 flag, and report or try to correct the situation in the breakpoint handler code. See HardWare BreakPoints Ultimate Guide .

+4
source

99.99% of the reasons are a program error or a bad program design.

Now we have two main questions:

1) How to prevent assembly errors?

2) How to make a good program design?

+1
source

Source: https://habr.com/ru/post/1436979/


All Articles