public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "andreas at andreas dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/30475] assert(int+100 > int) optimized away
Date: Sun, 21 Jan 2007 17:30:00 -0000	[thread overview]
Message-ID: <20070121172951.17226.qmail@sourceware.org> (raw)
In-Reply-To: <bug-30475-3511@http.gcc.gnu.org/bugzilla/>



------- Comment #35 from andreas at andreas dot org  2007-01-21 17:29 -------
(In reply to comment #34)
> > The range analysis has nothing to do with just assuming integers can't wrap.
> Partly wrong, range analysis is helped by the fact assuming integers can't
> wrap.

And in those cases then leads to code that does unexpected things, such as
breaking existing security checks.

> >I don't see why making make_range in fold-const.c 
> It is already if you use -fwrapv.

No, it is not.  What happens is that make_range will generate invalid ranges in
any case, and then optimizations depending on those ranges will be skipped when
-fwrapv is specified.  (Please correct me if I'm reading the code wrong, even
though I'm maintaining an open source compiler myself, I don't have much
experience reading gcc code.)

What this means is that in the example you posted above, even though the
compiler *could* compute a correct range and properly fold the if statement
even given LIA-1 compliant overflow behaviour, gcc will skip the optimization
when passed -fwrapv.

After reading the code, I can certainly see why making -fwrapv is something
you'd rather avoid: it makes a lot of optimizations go down the drain. But:
this wouldn't have to happen if you fixed make_range to do something sensible
instead.  I wonder why this didn't jump right into the face of the person who
implemented -fwrapv, it must have been a real pain to track down all the
usages.

> The problem here is that the people who added these security checks in the
> first place did not know C.  So either GCC can be changed or these programs can
> be fixed by the way comp.lang.c faq recommends or by using -fwrapv.  If we
> change GCC, you punish the people who actually write defined C so that is out
> of the question.  

Well, maybe they didn't.  I did a non-representative survey with the C
programmers I know: everybody assumed overflow of signed ints would behave as
it does for the underlying machine representation.  Not a single one was aware
of the danger.  And we're talking of people with 20+ years of professional
experience in the field here.

And I think people who do know can be expected to read the gcc manual to figure
out that there were a -fnowrapv option to make their code go a wee bit faster.

Did I mention that I have yet to see a convincing example of a case where
undefinedness of signed overflow actually makes code go faster that isn't per
definition a security problem?  Especially after having learned from reading
the gcc code that -fwrapv turns off a whole lot more optimizations than it has
to?

> I think the real issue that some of the security folks want to check after the
> fact that something happened instead of before it happend which is the correct
> way to do anything.

No, I would call any security expert who refuses to learn that there is a
problem with signed overflow and how to check for that correctly an idiot.  The
issue here is really how to deal with the existing body of code out there that
was written in the implicit assumption of LIA-1 compliant behaviour.

This is about risk management for all the Linux systems out there.  It is not
about "whose fault is it".  It's about "Houston, we have a problem, and need it
fixed".


-- 


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


  parent reply	other threads:[~2007-01-21 17:30 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15 19:43 [Bug c/30475] New: " felix-gcc at fefe dot de
2007-01-15 19:46 ` [Bug c/30475] " felix-gcc at fefe dot de
2007-01-15 19:47 ` pinskia at gcc dot gnu dot org
2007-01-15 19:50 ` felix-gcc at fefe dot de
2007-01-15 19:57 ` felix-gcc at fefe dot de
2007-01-15 20:04 ` pinskia at gcc dot gnu dot org
2007-01-16  4:47 ` pinskia at gcc dot gnu dot org
2007-01-16  7:00 ` pluto at agmk dot net
2007-01-16  7:24 ` gcc at mailinator dot com
2007-01-17 13:55 ` felix-gcc at fefe dot de
2007-01-17 14:26 ` rguenth at gcc dot gnu dot org
2007-01-17 14:31 ` rguenth at gcc dot gnu dot org
2007-01-17 15:21 ` felix-gcc at fefe dot de
2007-01-17 16:32 ` rguenth at gcc dot gnu dot org
2007-01-17 16:37 ` felix-gcc at fefe dot de
2007-01-17 16:54 ` erdgeist-gcc at erdgeist dot org
2007-01-17 16:57 ` pinskia at gcc dot gnu dot org
2007-01-17 17:03 ` felix-gcc at fefe dot de
2007-01-17 17:06 ` rguenth at gcc dot gnu dot org
2007-01-17 17:12 ` pinskia at gcc dot gnu dot org
2007-01-17 17:14 ` amacleod at redhat dot com
2007-01-17 17:20 ` felix-gcc at fefe dot de
2007-01-17 17:42 ` pinskia at gcc dot gnu dot org
2007-01-17 18:23 ` felix-gcc at fefe dot de
2007-01-17 18:43 ` pinskia at gcc dot gnu dot org
2007-01-17 19:04 ` felix-gcc at fefe dot de
2007-01-17 19:18 ` pinskia at gcc dot gnu dot org
2007-01-18 15:20 ` felix-gcc at fefe dot de
2007-01-18 15:24 ` felix-gcc at fefe dot de
2007-01-18 17:36 ` pinskia at gcc dot gnu dot org
2007-01-21  8:58 ` pinskia at gcc dot gnu dot org
2007-01-21 12:23 ` andreas at andreas dot org
2007-01-21 12:49 ` andreas at andreas dot org
2007-01-21 13:53 ` felix-gcc at fefe dot de
2007-01-21 16:31 ` pinskia at gcc dot gnu dot org
2007-01-21 17:30 ` andreas at andreas dot org [this message]
2007-01-21 17:47 ` felix-gcc at fefe dot de
2007-01-21 18:16 ` pluto at agmk dot net
2007-01-21 19:46 ` rguenth at gcc dot gnu dot org
2007-01-21 20:14 ` pinskia at gcc dot gnu dot org
2007-01-21 21:52 ` tromey at gcc dot gnu dot org
2007-01-22  2:18 ` felix-gcc at fefe dot de
2007-01-22  2:27 ` pinskia at gcc dot gnu dot org
2007-01-22 13:02 ` felix-gcc at fefe dot de
2007-01-22 17:15 ` pinskia at gcc dot gnu dot org
2007-01-22 18:26 ` steven at gcc dot gnu dot org
2007-01-22 18:33 ` pinskia at gcc dot gnu dot org
2007-01-22 18:36 ` andreas at andreas dot org
2007-01-22 19:50 ` felix-gcc at fefe dot de
2007-01-22 20:16 ` ian at airs dot com
2007-01-22 22:27 ` pinskia at gcc dot gnu dot org
2007-01-22 23:10 ` andreas at andreas dot org
2007-01-23  0:46 ` kargl at gcc dot gnu dot org
2007-03-08  1:03 ` js at linuxtv dot org
2007-03-08  1:14 ` pinskia at gcc dot gnu dot org
2007-03-08 16:23 ` js at linuxtv dot org
     [not found] <bug-30475-4@http.gcc.gnu.org/bugzilla/>
2014-02-16 10:00 ` jackie.rosen at hushmail dot com
2021-01-05 12:26 ` daniel.marjamaki at gmail dot com
2021-01-05 12:56 ` daniel.marjamaki at gmail dot com
2021-01-05 13:30 ` jakub at gcc dot gnu.org
2021-01-05 13:37 ` jakub at gcc dot gnu.org
2021-01-06 10:37 ` daniel.marjamaki at gmail dot com

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=20070121172951.17226.qmail@sourceware.org \
    --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).