“-fstack-protector all”和“-fstack-protector strong”,哪个更强?gcc对这些方案的解释如下:
-fstack-protector-all
Like -fstack-protector except that all functions are protected.
-fstack-protector-strong
Like -fstack-protector but includes additional functions to be protected --- those that have local array definitions, or have references to local frame addresses.所以,在我看来,我认为-fstack-protector-all更强大,对吗?
发布于 2021-08-25 05:19:01
-fstack-protector-all是“最强”的,是的,但可能是不必要的强大。
粗略地说:
-fstack-protector保护使用相当大的堆栈缓冲区的函数。-fstack-protector-strong保护使用任意大小、甚至非常小的堆栈缓冲区的函数。-fstack-protector-all保护所有功能。这包括一些函数,这些函数根本不使用堆栈,也不可能破坏堆栈,因此在许多情况下,它可能会为了不增加安全性而对性能造成影响。例如:
void other_func(char *p);
void f1(void) {
}
void f2(void) {
char buf[16];
other_func(buf);
}
void f3(void) {
char c;
other_func(&c);
}使用-fstack-protector只会增加对f2的保护。-fstack-protector-strong将其添加到f2和f3中。-fstack-protector-all将它添加到所有三个函数中,包括以前只由ret组成的f1,没有可能溢出任何东西,但现在大约有10个指令。
有关详细信息,请参阅“GCC的‘强’堆栈保护”杰克边缘,LWN.net,2014年2月5日。一文
https://stackoverflow.com/questions/68905062
复制相似问题