Depuis la version 2.4 de la glibc des symboles de controle ( comme __stack_chk_fail ) sont intégrés par defaut dans tous les binaires compilés. C'est le SSP dans GCC qui est responsable de cette action et il est possible de désactiver ce SSP avec l'option -fno-stack-protector.
Un petit code C comme exemple :
#include <stdio.h>
#include <pthread.h>
int main() {
pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&fastmutex);
printf("Tst\n");
pthread_mutex_unlock(&fastmutex);
}
Ensuite on teste :
none@zef:~# gcc -O2 -o test.bin test.c
none@zef:~# readelf -a test.bin | grep _stack_
080496c8 00000507 R_386_JUMP_SLOT 00000000 __stack_chk_fail
5: 00000000 70 FUNC GLOBAL DEFAULT UND __stack_chk_fail@GLIBC_2.4 (3)
75: 00000000 70 FUNC GLOBAL DEFAULT UND __stack_chk_fail@@GLIBC_2
none@zef:~# gcc -O2 -fno-stack-protector -o test.bin test.c
none@zef:~# readelf -a test.bin | grep _stack_
none@zef:~#
Ca rend de fait portable le binaire pour des glibc > 2.3 :)
none@zef:~# file /lib/libc-2.5.so
/lib/libc-2.5.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, stripped
none@zef:~# gcc -O2 -o test.bin test.c
none@zef:~# readelf -a test.bin | grep -i GLIBC_2.4
5: 00000000 70 FUNC GLOBAL DEFAULT UND __stack_chk_fail@GLIBC_2.4 (3)
004: 2 (GLIBC_2.0) 3 (GLIBC_2.4) 2 (GLIBC_2.0) 1 (*global*)
0x0010: Name: GLIBC_2.4 Flags: none Version: 3
none@zef:~# gcc -O2 -fno-stack-protector -o test.bin test.c
none@zef:~# readelf -a test.bin | grep -i GLIBC_2.4
none@zef:~#