From: Jakub Jelinek <jakub@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: Richard Biener <richard.guenther@gmail.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] gcc: Introduce -fhardened
Date: Tue, 19 Sep 2023 17:14:43 +0200 [thread overview]
Message-ID: <ZQm6408DsxgsIV+P@tucnak> (raw)
In-Reply-To: <ZQm3C6Jxv7lFcbw3@redhat.com>
On Tue, Sep 19, 2023 at 10:58:19AM -0400, Marek Polacek wrote:
> > > In <https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628748.html>
> > > I proposed -fhardened, a new umbrella option that enables a reasonable set
> > > of hardening flags. The read of the room seems to be that the option
> > > would be useful. So here's a patch implementing that option.
> > >
> > > Currently, -fhardened enables:
> > >
> > > -D_FORTIFY_SOURCE=3 (or =2 for older glibcs)
> > > -D_GLIBCXX_ASSERTIONS
> > > -ftrivial-auto-var-init=pattern
> > > -fPIE -pie -Wl,-z,relro,-z,now
> > > -fstack-protector-strong
> > > -fstack-clash-protection
> > > -fcf-protection=full (x86 GNU/Linux only)
> > >
> > > -fhardened will not override options that were specified on the command line
> > > (before or after -fhardened). For example,
> > >
> > > -D_FORTIFY_SOURCE=1 -fhardened
> > >
> > > means that _FORTIFY_SOURCE=1 will be used. Similarly,
> > >
> > > -fhardened -fstack-protector
> > >
> > > will not enable -fstack-protector-strong.
> > >
> > > In DW_AT_producer it is reflected only as -fhardened; it doesn't expand
> > > to anything. I think we need a better way to show what it actually
> > > enables.
> >
> > I do think we need to find a solution here to solve asserting compliance.
>
> Fair enough.
Well, asserting compliance doesn't make sense, because many of these features
are only best effort. So, one can assert that certain options have been
passed to the compiler (or not), and for that the current
-grecord-gcc-switches I think works mostly fine (well, it doesn't record -D*
options), one knows the compiler version/snapshot date etc. and what options
have been passed and can by repeating those options see what is and isn't
enabled in that case.
As for what exact options are actually enabled in the end, --help should be
able to answer that. Still, even if one records that -D_FORTIFY_SOURCE=3
was passed on the command line, that doesn't mean there is no
#undef _FORTIFY_SOURCE in the source before including headers, or that
the compiler has been successful to figure out object size (static or
dynamic) for certain pointer, or that a function has some array so that it
will use stack protector guard, or that certain function didn't disable
-fstack-protector through function attributes etc.
So, if one wants to know if certain vulnerability exploit can be stopped
through hardening, one needs to analyze actually emitted code, just looking
for checkboxes isn't enough.
One can assert -D_FORTIFY_SOURCE=2 has been passed, but without glibc
headers being used and actually using __builtin_*object_size it doesn't do
anything either. Programs can just declare memcpy etc. themselves and not
include glibc headers...
If the checkboxes are desirable for some reason, perhaps we could introduce
a new DWARF DW_AT_GNU_hardening attribute which would contain say bitfield
of which of those hardening features have been enabled (though, not sure if
we want to emit them just per DW_TAG_compile_unit, or DW_TAG_subprogram,
or both (say put on DW_TAG_compile_unit always if at least one of those is
enabled and on DW_TAG_subprogram only if it is different from the CU one).
Jakub
next prev parent reply other threads:[~2023-09-19 15:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-15 15:08 Marek Polacek
2023-09-18 6:57 ` Richard Biener
2023-09-19 14:58 ` Marek Polacek
2023-09-19 15:14 ` Jakub Jelinek [this message]
2023-10-11 20:48 ` [PATCH v2] " Marek Polacek
2023-10-18 20:12 ` Qing Zhao
2023-10-19 18:32 ` Marek Polacek
2023-10-19 12:24 ` Richard Biener
2023-10-19 12:33 ` Sam James
2023-10-19 18:33 ` Marek Polacek
2023-10-23 19:25 ` [PATCH v3] " Marek Polacek
2023-10-24 7:22 ` Richard Biener
2023-10-24 19:09 ` Marek Polacek
2023-10-26 15:55 ` Richard Biener
2023-11-03 22:51 ` [PATCH v4] " Marek Polacek
2023-11-13 15:41 ` Marek Polacek
2023-11-14 7:46 ` Richard Biener
2023-11-14 16:00 ` Marek Polacek
2023-11-15 11:42 ` Richard Biener
2023-11-15 12:25 ` Jakub Jelinek
2023-11-16 20:51 ` [PATCH v5] " Marek Polacek
2023-11-20 16:32 ` Jakub Jelinek
2023-11-21 15:41 ` Marek Polacek
2023-11-23 16:59 ` Marek Polacek
2023-10-24 7:44 ` [PATCH v3] " Iain Sandoe
2023-10-24 9:34 ` Iain Sandoe
2023-10-24 19:03 ` Marek Polacek
2023-10-24 19:16 ` Iain Sandoe
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=ZQm6408DsxgsIV+P@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@redhat.com \
--cc=richard.guenther@gmail.com \
/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).