dirtycow / dirtycow.github.io

Dirty COW
https://dirtycow.ninja
3.35k stars 940 forks source link

-lpthread or -pthread (and suppressing warnings) #11

Closed fat-tire closed 7 years ago

fat-tire commented 8 years ago

Minor thing, but dirtyc0w.c says to build with:

 gcc -lpthread dirtyc0w.c -o dirtyc0w

This (at least for me, gcc 6.2.0) results in errors:

 undefined reference to `pthread_create'
 undefined reference to `pthread_join

Using:

 gcc -pthread dirtyc0w.c -o dirtyc0w

Works fine. Also some warnings can be gotten rid of by adding

 #include <sys/stat.h>
 #include <unistd.h>

I got rid of the rest by adding:

 #include <stdint.h>

Then changing:

 lseek(f,map,SEEK_SET);

to

lseek(f, (uintptr_t) map,SEEK_SET);

and

 printf("mmap %x\n\n",map);

to

 printf("mmap %x\n\n",(uintptr_t) map);

Dunno if this is correct- it very well may not be- but it builds quietly for me now on my raspberry pi. So there ya go.

multiwebinc commented 8 years ago

After applying the above changes I was also getting:

dirtyc0w.c: In function ‘main’:
dirtyc0w.c:99:3: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
   printf("mmap %x\n\n",(uintptr_t) map);
   ^

So I changed line 99 to:

printf("mmap %lu\n\n",(uintptr_t) map);

Now I have no output at all. Maybe because it's patched?

sbrl commented 8 years ago

@multiwebinc: If you don't get any output, I think it means that it compiled successfully. To make sure, check that the exit code was 0 by running this command:

echo Exit code: $?
fat-tire commented 8 years ago

Try %lx instead of %lu .

fat-tire commented 8 years ago

Actually %zx should make sure it's the right size no matter the pointer size. Anyway, I submitted this stuff to PR #17 if anyone wants it all at once. So someone test it...

tempuser1909 commented 8 years ago

@multiwebinc Try changing Line 99: printf("mmap %x\n\n",(uintptr_t) map); to Line 99 : unsigned int map_t = (uintptr_t) map; Line 100: printf("mmap %x\n\n", map_t);

Making this change works for me.

sbrl commented 7 years ago

Erm why was this closed, @dirtycow?

therealbstern commented 7 years ago

The libc printf format character for a void pointer is %p, no casts needed.

dirtycow commented 7 years ago

Didn't #17 fixed all of this?