Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for x86 in setcanary like getcanary #53

Merged
merged 1 commit into from
Nov 30, 2018
Merged

Added support for x86 in setcanary like getcanary #53

merged 1 commit into from
Nov 30, 2018

Conversation

sudhackar
Copy link
Contributor

cmake-build-multiarch.sh fails for setcanary for x86. Adding the support for x86 similar to what getcanary does.

@sudhackar
Copy link
Contributor Author

$ 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

@zardus zardus merged commit 74b2ce6 into zardus:master Nov 30, 2018
@zardus
Copy link
Owner

zardus commented Nov 30, 2018

Thanks! Tests would be great, of course :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants