Bug 38274 - why the option "-fstack-protector-all" doesn't works?
Summary: why the option "-fstack-protector-all" doesn't works?
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-26 09:24 UTC by zuogang
Modified: 2023-03-21 00:05 UTC (History)
2 users (show)

See Also:
Host: x86, SUSE 10 ES,
Target: X86
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zuogang 2008-11-26 09:24:58 UTC
source file:
#include <stdio.h>

int main(void)
{
	char a = 1;
	int b = 2;
	short c = 3;
	char sztmp[22] = "hello worlds!";

	*(int *)&a=0xffff;

	sztmp[22]=0;
	printf("%s,a:%d,b%d\n",sztmp,a,b);

	return 0;
}

invoke gcc by :gcc  -fstack-protector-all test.c;

after my debugging a.out, I find the gcc doesn't adding a guard variable to functions's local stack vars, and the var "sztmp" follows var "a" and there aren't any room between the two vars.
Comment 1 Andrew Pinski 2008-11-29 03:10:04 UTC
Works for me with the trunk on i386-darwin8.11:
[236:~] apinski% ~/local-gcc/bin/gcc t.c  -fstack-protector-all 
[236:~] apinski% ./a.out
?,a:-1,b2
*** stack smashing detected ***:  terminated
Illegal instruction
Comment 2 zuogang 2008-12-01 10:13:12 UTC
(In reply to comment #1)
> Works for me with the trunk on i386-darwin8.11:
> [236:~] apinski% ~/local-gcc/bin/gcc t.c  -fstack-protector-all 
> [236:~] apinski% ./a.out
> ?,a:-1,b2
> *** stack smashing detected ***:  terminated
> Illegal instruction

what 's the version of the gcc src code you tried? 

can you try the gcc version 4.1.2
Comment 3 Andrew Pinski 2008-12-24 01:47:04 UTC
(In reply to comment #2) 
> what 's the version of the gcc src code you tried? 

Trunk meaning 4.4.0.
Comment 4 Jack Howarth 2008-12-24 02:53:59 UTC
Zougang,
    Considering they just closed the gcc 4.2 branch, the earliest one worth testing would be gcc 4.3.2.
Comment 5 Andrew Pinski 2023-03-21 00:03:33 UTC
-fstack-protector (-all) does not detect all buffer overflows and is not designed that way (or even documented that way). It only adds one space at the end of the stack to detect if there was a buffer overflow but it is also aligned so it might be further out than just one location too.
Comment 6 Andrew Pinski 2023-03-21 00:05:54 UTC
Note if you want to detect more buffer overruns you should try -fsanitize=address
 . Valgrind will also detect more too.
BUT note none of these are 100% either because they only have a limited redzone and valgrind also will detect less due to if two buffers are on the stack there is no zone inbetween the buffers.