Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1349187

Re: Q: why didn't GCC warn about this uninitialized variable? (was: Re: [PATCH] perf tests: initialize sa.sa_flags)

From Ingo Molnar <mingo@kernel.org>
Newsgroups linux.kernel
Subject Re: Q: why didn't GCC warn about this uninitialized variable? (was: Re: [PATCH] perf tests: initialize sa.sa_flags)
Date 2016-03-03 15:10 +0100
Message-ID <r8C71-88W-27@gated-at.bofh.it> (permalink)
References (4 earlier) <r8f0K-89o-15@gated-at.bofh.it> <r8Aoy-6Zk-9@gated-at.bofh.it> <r8B1g-7eH-1@gated-at.bofh.it> <r8Buj-7F8-15@gated-at.bofh.it> <r8BNF-7MX-39@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


* Jakub Jelinek <jakub@redhat.com> wrote:

> On Thu, Mar 03, 2016 at 02:24:34PM +0100, Ingo Molnar wrote:
> > 6 hours of PeterZ time translates to quite a bit of code restructuring overhead to 
> > eliminate false positive warnings...
> 
> I'll file a bugzilla enhancement request for this (with new attribute),
> perhaps we could do it in FRE that is able to see through memory
> stores/loads even in addressable structures in some cases.
> Though, certainly GCC 7 material.

> And, in this particular case it couldn't do anything anyway, because
> the sigfillset call is not inlined, and takes address of a field in the
> structure.  The compiler can't know if it doesn't cast it back to struct
> sigaction and initialize the other fields.

That's true - but I think in the typical case it's a pretty fragile pattern to go 
outside the bounds of a on-stack structure you get passed, so I wouldn't mind a 
(default-disabled) warning for it, even if it generates false positives that have 
to be annotated for the few cases where it's a legitimate technique.

I am 99% sure that a fair number of security critical projects would migrate to 
the usage of such a warning, combined with -Werror. I'm 100% sure that perf would 
migrate to it.

> BTW, valgrind should be able to detect this.

Yes - assuming the uninitialized value gets used. Often they are in rarely used 
code and error paths, only triggered by exploits.

It would be far better if GCC allowed a (non-default) C variant that makes it 
impossible to introduce uninitialized values via on-stack variables. The 
maintenance cost of the false positives is the price paid for that (very valuable) 
guarantee.

Thanks,

	Ingo

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] perf tests: initialize sa.sa_flags Colin King <colin.king@canonical.com> - 2016-03-02 14:00 +0100
  Re: [PATCH] perf tests: initialize sa.sa_flags Peter Zijlstra <peterz@infradead.org> - 2016-03-02 14:00 +0100
    Re: [PATCH] perf tests: initialize sa.sa_flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-03-02 14:10 +0100
      Re: [PATCH] perf tests: initialize sa.sa_flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-03-02 14:30 +0100
        Q: why didn't GCC warn about this uninitialized variable? (was: Re:  [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 13:20 +0100
          Re: Q: why didn't GCC warn about this uninitialized variable? Colin Ian King <colin.king@canonical.com> - 2016-03-03 13:30 +0100
          Re: Q: why didn't GCC warn about this uninitialized variable? Måns Rullgård <mans@mansr.com> - 2016-03-03 13:40 +0100
            Re: Q: why didn't GCC warn about this uninitialized variable? Joe Perches <joe@perches.com> - 2016-03-03 13:50 +0100
            Re: Q: why didn't GCC warn about this uninitialized variable? Ingo Molnar <mingo@kernel.org> - 2016-03-03 13:50 +0100
          Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Jakub Jelinek <jakub@redhat.com> - 2016-03-03 14:00 +0100
            Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 14:30 +0100
              Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 14:50 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Jakub Jelinek <jakub@redhat.com> - 2016-03-03 15:20 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 15:50 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 16:00 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 16:10 +0100
              Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Jakub Jelinek <jakub@redhat.com> - 2016-03-03 14:50 +0100
                Re: Q: why didn't GCC warn about this uninitialized variable? (was:  Re: [PATCH] perf tests: initialize sa.sa_flags) Ingo Molnar <mingo@kernel.org> - 2016-03-03 15:10 +0100
      Re: [PATCH] perf tests: initialize sa.sa_flags Peter Zijlstra <peterz@infradead.org> - 2016-03-02 14:30 +0100
  Re: [PATCH] perf tests: initialize sa.sa_flags Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-03-02 14:10 +0100

csiph-web