Skip to content

Update compile flags per security review #4368

Closed

Description

@eseidelGoogle

During security review we were asked to make sure our C++ compile flags for Release configs use the following:

Compile-time flags: -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all -fPIE -Wa,--noexecstack -Wformat -Wformat-security
Link-time flags: -pie -Wl,-z,relro,-z,now

This is non-urgent, but we should address for 1.0.

FYI @abarth @chinmaygarde

Activity

  1. added this to the milestone on Jun 3, 2016
  2. modified the milestones: , on Jan 30, 2017
  3. modified the milestones: 3: Current Milestone, on Dec 20, 2017
  4. added a commit that references this issue on Apr 3, 2018
  5. kf6gpe commented on Oct 2, 2018

    @kf6gpe
    Contributor

    So, the Android changes are in my branch; I'm working on testing the iOS changes now. Some notes about iOS changes:

    • iOS compiles with PIE by default, but I'll add it as explicit flags so it's clear what we're doing.
    • The compiler flags -fstack-protector-all, -Wa,--noexecstack, -Wformat and -Wformat-security appear to have no corresponding flags in the iOS toolchain. I haven't found good counterparts, but admit I need to continue to look.
    • The linker flag -Wl,-z,relro,-z,now has no correspondence either.
  6. kf6gpe commented on Oct 4, 2018

    @kf6gpe
    Contributor

    After chatting with @goderbauer, we agree that we don't want -O2 if we can help it either --- the space hit is just too high --- -Oz on helloworld weighs in at 5,805,240B, while -O2 weighs in at 8,024060B in his test. I'm backing that out now.

  7. self-assigned this
    on Oct 4, 2018
  8. goderbauer commented on Oct 4, 2018

    @goderbauer
    Member

    @kf6gpe The sizes you quoted are for the uncompressed libflutter.so, which ships with every app (not just helloworld).

  9. kf6gpe commented on Oct 4, 2018

    @kf6gpe
    Contributor

    @goderbauer Good point --- thanks for the clarification.

  10. kf6gpe commented on Oct 29, 2018

    @kf6gpe
    Contributor

    Looks like this has caused regressions in disk space size as well as performance for tiles_scroll_perf__timeline_summary/average_frame_rasterizer_time_millis. We've rolled back this CL at present until we pinpoint which flag is the culprit.

  11. 2 remaining items

  12. kf6gpe commented on Jul 31, 2019

    @kf6gpe
    Contributor

    We've left the reversion in place, preferring the reduction in package size over the footprint increase.

  13. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  14. removed this from the milestone on Jun 2, 2020
  15. removed this from the milestone on Jun 2, 2020
  16. removed this from the milestone on Aug 17, 2020
  17. Seirdy commented on Dec 9, 2021

    @Seirdy

    Many linux distros are trying to get all executables to be PIE-only as part of the road to full ASLR, so this would be appreciated. -fcf-protection=full in CFLAGS and -Wl,--as-needed in LDFLAGS could also help.

    Additionally, enabling LTO could pave the way to eventually supporting Clang's forward-edge CFI with -fsanitize=cfi, and could reduce binary size when paired with -ffunction-sections -fdata-sections. This could help offset the increases in package size, especially if combined with linking some libs statically and dropping the .so files.

  18. chinmaygarde commented on Dec 9, 2021

    @chinmaygarde
    Contributor

    Many linux distros are trying to get all executables to be PIE-only as part of the road to full ASLR, so this would be appreciated. -fcf-protection=full in CFLAGS and -Wl,--as-needed in LDFLAGS could also help.

    Flutter does have support for plugging in custom toolchains and some support for passing toolchain specific flags. So distros can do this for the engine dylib if they want to build the engine on their own. Is there a specific binary/distro you are thinking of? This may be a good thing to do everywhere.

    Additionally, enabling LTO could pave the way to eventually supporting...

    Flutter already performs LTO on all optimized targets with at least some of the flags you mentioned already being applied. The last time LTO was tuned was a while ago however so it may be a good time to revisit all LTO flags.

    linking some libs statically and dropping the .so files.

    All engine libraries are already linked statically into a single engine .so file.

  19. Seirdy commented on Dec 9, 2021

    @Seirdy
  20. Hixie commented on Mar 16, 2023

    @Hixie
    Contributor

    I'm going to close this; we have more methodical work ongoing to harden our toolchain now.

  21. github-actions commented on Mar 30, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  22. locked as resolved and limited conversation to collaborators on Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: releaseChallenges faced when attempting to productionize an appc: contributor-productivityTeam-specific productivity, code health, technical debt.engineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions