[llvm-bugs] [Bug 35449] New: Windows stack guard needs to XOR the stack pointer with __stack_cookie

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 28 11:47:05 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35449

            Bug ID: 35449
           Summary: Windows stack guard needs to XOR the stack pointer
                    with __stack_cookie
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvm-bugs at lists.llvm.org

Consider:
void g(int*);
void f() {
  int x[16];
  g(&x[0]);
}

Compiled like so, here is a comparison of the relevant code:

$ cl -O2 -GS t2.c -Fat.s -c && grep -B1 -A2 security t.s
...
        sub     rsp, 120                                ; 00000078H
        mov     rax, QWORD PTR __security_cookie
        xor     rax, rsp
        mov     QWORD PTR __$ArrayPad$[rsp], rax
--
        xor     rcx, rsp
        call    __security_check_cookie
        add     rsp, 120                                ; 00000078H
        ret     0

$ clang-cl -O2 -GS t2.c -Fat.s -c && grep -B1 -A2 security t.s
        .seh_endprologue
        movq    __security_cookie(%rip), %rax
        movq    %rax, 96(%rsp)
        leaq    32(%rsp), %rcx
--
        movq    96(%rsp), %rcx
        callq   __security_check_cookie
        nop
        addq    $104, %rsp

The same is done with EBP on 32-bit. XORing the stack pointer (or frame pointer
when appropriate) into the canary improves security by making it harder to a
valid cookie from one location to another to bypass the guard.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171128/3ec82e5e/attachment.html>


More information about the llvm-bugs mailing list