public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init
@ 2023-07-26 14:06 serge.guelton@telecom-bretagne.eu
2023-07-26 14:38 ` [Bug c++/110816] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: serge.guelton@telecom-bretagne.eu @ 2023-07-26 14:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110816
Bug ID: 110816
Summary: Emit initialization code for empty class under
-ftrivial-auto-var-init
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: serge.guelton@telecom-bretagne.eu
Target Milestone: ---
As show cased by https://godbolt.org/z/o5asYGq8G, gcc doesn't fill the byte
used by empty class/struct under -ftrivial-auto-var-init. This potentially
leaks a byte of memory.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/110816] Emit initialization code for empty class under -ftrivial-auto-var-init
2023-07-26 14:06 [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init serge.guelton@telecom-bretagne.eu
@ 2023-07-26 14:38 ` redi at gcc dot gnu.org
2023-07-26 16:05 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-26 14:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110816
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The testcase is:
struct f { void crash(); };
void bar(bool cond) {
f t;
if(cond)
t.crash();
//user(&t);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/110816] Emit initialization code for empty class under -ftrivial-auto-var-init
2023-07-26 14:06 [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init serge.guelton@telecom-bretagne.eu
2023-07-26 14:38 ` [Bug c++/110816] " redi at gcc dot gnu.org
@ 2023-07-26 16:05 ` pinskia at gcc dot gnu.org
2023-07-26 16:08 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-26 16:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110816
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> This potentially leaks a byte of memory.
The only way to access that byte is to use memcpy or via char.
-ftrivial-auto-var-init is not designed for security this way but rather for
normal code ...
IIRC atomic compare and swap will zero it out too ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/110816] Emit initialization code for empty class under -ftrivial-auto-var-init
2023-07-26 14:06 [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init serge.guelton@telecom-bretagne.eu
2023-07-26 14:38 ` [Bug c++/110816] " redi at gcc dot gnu.org
2023-07-26 16:05 ` pinskia at gcc dot gnu.org
@ 2023-07-26 16:08 ` redi at gcc dot gnu.org
2023-07-27 7:15 ` rguenth at gcc dot gnu.org
2023-07-27 8:31 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-26 16:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110816
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-07-26
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> The only way to access that byte is to use memcpy or via char.
> -ftrivial-auto-var-init is not designed for security this way but rather for
> normal code ...
That's not what the manual says (emphasis mine):
"Initialize automatic variables with either a pattern or with zeroes to
increase the security and predictability of a program by preventing
**uninitialized memory disclosure** and use."
> IIRC atomic compare and swap will zero it out too ...
The std::atomic and std::atomic_ref compare_exchange members will zero it, but
the compiler built-in won't.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/110816] Emit initialization code for empty class under -ftrivial-auto-var-init
2023-07-26 14:06 [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init serge.guelton@telecom-bretagne.eu
` (2 preceding siblings ...)
2023-07-26 16:08 ` redi at gcc dot gnu.org
@ 2023-07-27 7:15 ` rguenth at gcc dot gnu.org
2023-07-27 8:31 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27 7:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110816
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > The only way to access that byte is to use memcpy or via char.
> > -ftrivial-auto-var-init is not designed for security this way but rather for
> > normal code ...
>
> That's not what the manual says (emphasis mine):
>
> "Initialize automatic variables with either a pattern or with zeroes to
> increase the security and predictability of a program by preventing
> **uninitialized memory disclosure** and use."
probably should add 'some' qualification here.
> > IIRC atomic compare and swap will zero it out too ...
>
> The std::atomic and std::atomic_ref compare_exchange members will zero it,
> but the compiler built-in won't.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/110816] Emit initialization code for empty class under -ftrivial-auto-var-init
2023-07-26 14:06 [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init serge.guelton@telecom-bretagne.eu
` (3 preceding siblings ...)
2023-07-27 7:15 ` rguenth at gcc dot gnu.org
@ 2023-07-27 8:31 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-27 8:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110816
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And fix the spelling of zeros, which is generally preferred to zeroes for the
noun.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-27 8:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 14:06 [Bug c++/110816] New: Emit initialization code for empty class under -ftrivial-auto-var-init serge.guelton@telecom-bretagne.eu
2023-07-26 14:38 ` [Bug c++/110816] " redi at gcc dot gnu.org
2023-07-26 16:05 ` pinskia at gcc dot gnu.org
2023-07-26 16:08 ` redi at gcc dot gnu.org
2023-07-27 7:15 ` rguenth at gcc dot gnu.org
2023-07-27 8:31 ` redi at gcc dot gnu.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).