<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Windows stack guard needs to XOR the stack pointer with __stack_cookie"
   href="https://bugs.llvm.org/show_bug.cgi?id=35449">35449</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Windows stack guard needs to XOR the stack pointer with __stack_cookie
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rnk@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>