Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the difference between segment fault and Stack smashing detected

Tags:

c

I have experienced two kind of error,one is segmentation fault, another is Stack smashing detected. I want to know what different between them and the different reasons caused them.

like image 881
shengfu zou Avatar asked Feb 03 '16 06:02

shengfu zou


People also ask

Is stack smashing a seg fault?

Stack smashing in X86_64 leads to Segmentation fault .

What does stack smashing detected mean?

Stack smashing is a form of vulnerability where the stack of a computer application or OS is forced to overflow. This may lead to subverting the program/system and crashing it.

How are segmentation faults detected?

Use debuggers to diagnose segfaults For example, you could use GNU's well-known debugger GDB to view the backtrace of a core file dumped by your program; whenever programs segfault, they usually dump the content of (their section of the) memory at the time of the crash into a core file.

How do I fix stack smashing detected?

Further, the compiler identifies by comparing with known values that the stack is compromised and generates an error saying: stack smashing detected . To prevent the buffer overflow protection variable and have some insights, we can disable the GCC's protection using the -fno-stack-protector while compiling.


4 Answers

This is typically Undefined behavior.

  • Segmentation fault is typically when your process is accessing memory location to which it doesn't have permission to access, or that location does not exist.

  • Stack smashing is an alert (generated by gcc for instance) that warns about an access out of bounds, for instance, on the stack. Typically that happens when the stack is written to where it shouldn't - like a local array written to at an index out of bounds.

There is a problem in your code that produces undefined behavior. Maybe you could share it with us so that we can help you.

Check in particular:

  • out of array bounds accesses
  • NULL pointers
like image 60
Déjà vu Avatar answered Oct 13 '22 16:10

Déjà vu


Segmentation fault is a fault raised by hardware with memory protection, notifying an operating system (OS) about a memory access violation. Stack smashing is reported when there is overflow of data in your program's call stack. Generally program's call stack is of fixed length.

like image 45
Cool Goose Avatar answered Oct 13 '22 16:10

Cool Goose


stack overflow and stack smashing both problems are related to faulty code or value found in the variables. For example when a loop run as that it run over extras index of the array and overwrite the value of another variable of the code then , it become problem to the function prolog and epilog to continue to next function hence the current function become unable to return to calle function because overrun of llop has just overwrite the return address of calle instruction and hence EIP pointing to somewhere it not allowed to fetch instruction .All codes into OS are run in memory protection schems , hence you get stack overrun or stack smashing . Segmentation fault is problems is normal situation when dealing with array and pointer in Linux OS . Try this http://www.drdobbs.com/security/anatomy-of-a-stack-smashing-attack-and-h/240001832

like image 31
Ganesh K Avatar answered Oct 13 '22 15:10

Ganesh K


Both are memory access violation. Segmentation fault is more general, means you are accessing something you are not allowed to. stack smashing is more specific, means something wrong in your stack. Actually, stack smashing can cause segmentation fault. you can refer to: https://en.wikipedia.org/wiki/Segmentation_fault or Stack smashing detected

like image 1
LKW Avatar answered Oct 13 '22 15:10

LKW