public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26457]  New: -fstack-protector leaks the upper bits of RAX
@ 2006-02-24 15:08 arjan at linux dot intel dot com
  2006-02-24 15:12 ` [Bug target/26457] " jakub at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: arjan at linux dot intel dot com @ 2006-02-24 15:08 UTC (permalink / raw)
  To: gcc-bugs

The following code snippet, compiled with -Os -fstack-protector:
#include <string.h>


int  StringChecksum(char *s)
{
        char buffer[2048];
        int i;
        int checksum = 0;

        memset(buffer, 0, 2048);
        strcpy(buffer, s);

        for (i=0; i<2048; i++)
                checksum += buffer[i];

        return checksum;
}

leads to the following snippet of assembly for the part where gcc puts the
canary value on the stack: (part of the full assembly of the function)

        movq    %rsp, %rdi
        movq    %fs:40, %rax
        movq    %rax, 2056(%rsp)
        xorl    %eax, %eax
        call    memset

the key instruction for this bug is the "xorl %eax, %eax". The intent of that
instruction seems to be to not leak the canary value into the actual function
code; however the canary value is 64 bits and in RAX, while the XOR is only
zeroing the lower 32 bits. For consistency and information security, this XOR
should, I think, clear all of RAX (which is same-cost anyway both in size and
execution)


-- 
           Summary: -fstack-protector leaks the upper bits of RAX
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: arjan at linux dot intel dot com
  GCC host triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26457


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-03-02 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-24 15:08 [Bug c/26457] New: -fstack-protector leaks the upper bits of RAX arjan at linux dot intel dot com
2006-02-24 15:12 ` [Bug target/26457] " jakub at gcc dot gnu dot org
2006-02-24 15:20 ` pinskia at gcc dot gnu dot org
2006-03-02 14:00 ` pinskia at gcc dot gnu dot org
2006-03-02 14:32 ` pluto at agmk dot net
2006-03-02 14:48 ` jakub at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).