Closed sudhackar closed 5 years ago
$ tail -n 35 z.c
#include <stdio.h>
#include <stdint.h>
#ifdef __x86_64__
#define canary_t uint64_t
#define INSN_READ "movq %%fs:0x28, %0;"
#define FMT "Found canary: %#lx\n"
#elif __i386__
#define canary_t uint32_t
#define INSN_READ "movl %%gs:0x14, %0;"
#define FMT "Found canary: %#x\n"
#endif
canary_t read_canary()
{
canary_t val = 0;
__asm__(INSN_READ
: "=r"(val)
:
:);
return val;
}
int main(int argc, char **argv)
{
printf(FMT, read_canary());
return 0;
}
$ gcc -no-pie -fno-pic z.c -o z64
$ gcc -m32 -no-pie -fno-pic z.c -o z32
$ PREENY_DEBUG=1 PREENY_INFO=1 PREENY_ERROR=1 CANARY=280267669825 LD_PRELOAD=~/tools/preeny/build_x64/lib/libsetcanary.so:~/tools/preeny/build_x64/lib/libgetcanary.so ./z64
--- Found canary: 0xd09868c5f39cd900
+++ Overwriting canary with 0x41414141...
Found canary: 0x4141414141
$ PREENY_DEBUG=1 PREENY_INFO=1 PREENY_ERROR=1 CANARY=1094795585 LD_PRELOAD=~/tools/preeny/build_x86/lib/libsetcanary.so:~/tools/preeny/build_x86/lib/libgetcanary.so ./z32
--- Found canary: 0x2526d900
+++ Overwriting canary with 0x41414141...
Found canary: 0x41414141
If it helps I can make a PR with tests for setcanary
Thanks! Tests would be great, of course :-)
cmake-build-multiarch.sh
fails forsetcanary
for x86. Adding the support for x86 similar to whatgetcanary
does.