Starting in clang 3.7 they've introduced a new argument -fsanitize=cfi
which aims to protect indirect calls from overwrites.
All the code and binaries I used can be downloaded here
First, I thought I would look at how CFI applied to simple C structs with function pointers. After fighting with the compiler to get it to stop optimizing my code, (i.e. call <puts>
instead of call rcx
because clang
realized that rcx
was always going to be puts(3)
) I got it calling things from memory. However, there was no CFI protection on the call. I played around with this a bit (interestingly, clang
will optimize use of un-initialized memory to the ud2
instruction) but was unable to get any CFI protection in place.
Reading a bit of the clang manual, it talked a lot about C++ virtual
methods, so I thought I would look at those. I also played around with non virtual
calls, those were replaced with static cal