public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tg at mirbsd dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/30477]  New: Integer Overflow detection code optimised away, -fwrapv broken
Date: Mon, 15 Jan 2007 23:43:00 -0000	[thread overview]
Message-ID: <bug-30477-13924@http.gcc.gnu.org/bugzilla/> (raw)

Bug originally reported against gcc 4.1.1 by Felix von Leitner,
found at http://blog.fefe.de/?ts=bb5517a4 (filed as PR #30475).

This is sort of a "follow-up" bug report, but with a
different _focus_ and a different _aim_, namely the
gcc developers, especially Andrew Pinski, to provide
a patch against older gcc versions to vendors that
wish to or must continue to use them, which unbreaks
the inability of "-fwrapv" to disable gcc optimising
away code often used in security checks added to an
existing legacy code base. These patches should be
provided publicly, so that any operating system ven-
dor who uses gcc2 or gcc3 can pick them up, because
it is not MirBSD specific.


I found out that gcc 3.4.6 (MirBSD; Propolice) and both
gcc 2.95 and 3.4.3 on DragonFly BSD are vulnerable as
well, but did not want to report that because they are
heavily patched against the FSF version.

However, Andrew Pinski writes in the following comment:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475#c2
That adding "-fwrapv" to the command line should fix this
important security issue. This, however, does not work
for me on gcc 3.4.6 (MirBSD, of course), but I've got a
shell account on a Debian GNU/Linux 4.0 box, whose sy-
stem gcc 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
indeed suppresses this optimisation with "-fwrapv".

I then downloaded gcc-core-3.4.6.tar.gz (the pristine
source), extracted and compiled it on that Debian box.

tglaser@hephaistos:~/test $ bin/bin/gcc -v
Reading specs from
/home/t/tglaser/test/bin/lib/gcc/i686-pc-linux-gnu/3.4.6/specs
Configured with: ../gcc-3.4.6/configure --prefix=/home/t/tglaser/test/bin
--enable-languages=c --disable-nls --disable-shared
Thread model: posix
gcc version 3.4.6
tglaser@hephaistos:~/test $ rm -f a.out; bin/bin/gcc -O0 int.c && ./a.out
200 100
a.out: int.c:4: foo: Assertion `a+100 > a' failed.
Aborted
134|tglaser@hephaistos:~/test $ rm -f a.out; bin/bin/gcc -O1 int.c && ./a.out
200 100
-2147483549 2147483647
255|tglaser@hephaistos:~/test $ rm -f a.out; bin/bin/gcc -O1 -fwrapv int.c &&
./a.out
200 100
-2147483549 2147483647
255|tglaser@hephaistos:~/test $ cat int.c
#include <assert.h>

int foo(int a) {
  assert(a+100 > a);
  printf("%d %d\n",a+100,a);
  return a;
}

int main() {
  foo(100);
  foo(0x7fffffff);
}
tglaser@hephaistos:~/test $ rm -f a.out; bin/bin/gcc -Os -fwrapv int.c &&
./a.out 
200 100
-2147483549 2147483647


-- 
           Summary: Integer Overflow detection code optimised away, -fwrapv
                    broken
           Product: gcc
           Version: 3.4.6
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tg at mirbsd dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


             reply	other threads:[~2007-01-15 23:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15 23:43 tg at mirbsd dot org [this message]
2007-01-15 23:56 ` [Bug c/30477] " pinskia at gcc dot gnu dot org
2007-01-15 23:57 ` pinskia at gcc dot gnu dot org
2007-01-16  2:34 ` tg at mirbsd dot org
2007-01-16  3:04 ` pinskia at gmail dot com
2007-01-16  3:40 ` tg at mirbsd dot de
2007-01-16  3:48   ` Andrew Pinski
2007-01-16  3:49 ` pinskia at physics dot uc dot edu
2007-01-16  4:08 ` tg at mirbsd dot org
2007-01-16 10:36 ` rguenth at gcc dot gnu dot org
2007-01-16 16:56 ` tg at mirbsd dot org
2007-01-16 17:18 ` rguenth at gcc dot gnu dot org
2007-01-16 17:34 ` tg at mirbsd dot org
2007-01-16 17:49 ` tg at mirbsd dot org
2007-01-16 18:00 ` pinskia at gcc dot gnu dot org
2007-01-16 18:01 ` gdr at cs dot tamu dot edu
2007-01-22 23:54 ` tg at mirbsd dot de
2007-01-25 14:29 ` tg at mirbsd dot org
2007-01-25 14:50 ` rguenth at gcc dot gnu dot org
2007-01-25 16:09 ` tg at mirbsd dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30477-13924@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).