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: unassignedb...@nondot.org
          Reporter: r...@google.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to