#include #include #include #include #include #include #include #include static void init (void) __attribute__ ((constructor)); int stat(const char *path, struct stat *buf); int fstat(int filedes, struct stat *buf); int lstat(const char *path, struct stat *buf); static void init (void) { fprintf(stderr,"lib loaded\n"); } int lstat(const char *path, struct stat *buf) { fprintf(stderr,"LSTAT\n"); return 0; } int stat(const char *path, struct stat *buf) { fprintf(stderr,"STAT\n"); return 0; } int fstat(int filedes, struct stat *buf) { fprintf(stderr, "FSTAT\n"); return 0; } ###################################################################### #include #include #include #include int main () { struct stat buffer; int status; printf("lstat: %d\n", stat("./dontexitsts", &buffer)); } ##################################################################### willem[preload]$ gcc -fPIC -shared -o lib.so lib.c willem[preload]$ LD_PRELOAD="./lib.so" ./a.out lib loaded lstat: -1 lstat should return 0 as it got hijacked, but doesnt seems so ...