public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Reinoud Koornstra <reinoudkoornstra@gmail.com>
To: Xi Ruoyao <xry111@mengyan1223.wang>
Cc: Florian Weimer <fweimer@redhat.com>,
	 Reinoud Koornstra via Gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Fortify_source and stack-protector-strong
Date: Fri, 11 Mar 2022 11:01:05 -0800	[thread overview]
Message-ID: <CAAA5faGO5pY36sR4gn83+mE40kRGXVCFohTLgxCzBsOpzC8d8Q@mail.gmail.com> (raw)
In-Reply-To: <CAAA5faG2-YHk1Ae7TaUFnsPoaiPANK_nB3NfOw_R9nbS2po0zw@mail.gmail.com>

One more question, for FORTIFY_SOURCE=2, can I use either -O1 or -O2
optimization flags?
I noticed it doesn't like -Os. Thanks,

Reinoud.

On Wed, Mar 2, 2022, 12:45 PM Reinoud Koornstra <reinoudkoornstra@gmail.com>
wrote:

> Thanks for the explanation!
> Better to use =2 then.
> But Strack protector and FORTIFY can be active as compiler arguments at
> the same time as I understand. Just the binary size will grow. Thanks,
>
> Reinoud.
>
> On Wed, Mar 2, 2022, 12:23 PM Xi Ruoyao <xry111@mengyan1223.wang> wrote:
>
>> On Wed, 2022-03-02 at 12:05 -0800, Reinoud Koornstra wrote:
>> > Hi Xi,
>> >
>> > Thanks for your reply.
>> > Then what is the difference between -D_FORTIFY_SOURCE=1 and
>> -D_FORTIFY_SOURCE=2 exactly?
>>
>> -D_FORTIFY_SOURCE=1 uses __builtin_object_size(..., 0) as the buffer
>> size, but -D_FORTIFY_SOURCE=2 uses __builtin_object_size(..., 1).  Read
>> https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html for the
>> details.
>>
>> One case is:
>>
>> struct frame
>> {
>>   int size;
>>   char buf[0];
>> };
>>
>> union
>> {
>>   struct frame f;
>>   char padding[100 + sizeof(struct frame)];
>> } u;
>>
>> u.frame.size = strlen(s) + 1;
>> strcpy(u.frame.buf, s);
>>
>> -D_FORTIFY_SOURCE=2 will abort this, but -D_FORTIFY_SOURCE=1 won't.
>> (Yes, I know "char buf[0]" should be changed to a flexible array member
>> "char buf[]" to fix this, but it is just an example.)
>> --
>> Xi Ruoyao <xry111@mengyan1223.wang>
>> School of Aerospace Science and Technology, Xidian University
>>
>

  reply	other threads:[~2022-03-11 19:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 23:23 Reinoud Koornstra
2022-03-02 10:22 ` Florian Weimer
2022-03-02 19:09   ` Reinoud Koornstra
2022-03-02 19:46     ` Xi Ruoyao
2022-03-02 20:05       ` Reinoud Koornstra
2022-03-02 20:23         ` Xi Ruoyao
2022-03-02 20:45           ` Reinoud Koornstra
2022-03-11 19:01             ` Reinoud Koornstra [this message]
2022-03-12  8:19               ` Xi Ruoyao
2022-04-19 11:24               ` Florian Weimer

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=CAAA5faGO5pY36sR4gn83+mE40kRGXVCFohTLgxCzBsOpzC8d8Q@mail.gmail.com \
    --to=reinoudkoornstra@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=xry111@mengyan1223.wang \
    /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).