From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by sourceware.org (Postfix) with ESMTPS id 747F03858C83 for ; Wed, 2 Mar 2022 20:45:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 747F03858C83 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-2dc28791ecbso19037837b3.4 for ; Wed, 02 Mar 2022 12:45:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OkSH0Ddx4KcCqqeTA+/xGwcMLKykmEs9ZVrYVZTV6w0=; b=G8a8Gn56oPTISsbUkY3fNwq1xQPmw6TtewPnRym2BKG3nHK8Vs2NyM7+hWtloXsSwo ysQzgqNeIpMdQPPb7OEXLNb5/dMizaHPj6fvfgcHq0acONziaTBDkCM8eCE0joX5rmwE 9DuYQktb2oYEAK/ULocgpVeX4DgbOi0R79zLCdP8BcveksnH18a9sqcvI2bEj3TUMQa9 ZMa/72SA/8SCajaJHuGIxK2XT6j+RBodHUJZgDPywGSeEQfsnnE9SHk2qXTCIyj0VxgU yGN2vWivulz1lTVhaOAdgjdXzFa1ZhDYqEDCRb06seWTA9D92CZiGZdb2gLbxaXgdSa8 DAzQ== X-Gm-Message-State: AOAM533TPDycgcMgHOtCSwgFQvL0TkmUpdPAroDxadgLzhD92WAYwALC Hv7W79D2aud33U6UT7acHaDuqN8wkXESg5tQiHk= X-Google-Smtp-Source: ABdhPJx9T4JqdDbXejuZMs+29DReTzBIuMFjLWpHanWlQlOT2ihNaIm0XykrAUlNV3f/Tj4CqQVDY0RFVYkiMblq0dY= X-Received: by 2002:a81:5389:0:b0:2db:6d7a:93ca with SMTP id h131-20020a815389000000b002db6d7a93camr17781806ywb.11.1646253958900; Wed, 02 Mar 2022 12:45:58 -0800 (PST) MIME-Version: 1.0 References: <87o82ok616.fsf@oldenburg.str.redhat.com> <2a574a7a0dbb4f1ef4472d2a43b029f0ceca9065.camel@mengyan1223.wang> <204cd10c9d34c6c798e701f1d990c120c2d77897.camel@mengyan1223.wang> In-Reply-To: <204cd10c9d34c6c798e701f1d990c120c2d77897.camel@mengyan1223.wang> From: Reinoud Koornstra Date: Wed, 2 Mar 2022 12:45:46 -0800 Message-ID: Subject: Re: Fortify_source and stack-protector-strong To: Xi Ruoyao Cc: Florian Weimer , Reinoud Koornstra via Gcc-help X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2022 20:46:00 -0000 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 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 > School of Aerospace Science and Technology, Xidian University >