Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a handful of compiler options to harden code #8551

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

grendello
Copy link
Contributor

The following compile-time warning options are added:

  • -Wformat=2
    Enable additional format function warnings. The 2 form of the
    option enables more extensive checks in calls to printf, scanf
    etc. These are compile-time only checks, no effect on runtime
    performance.
  • -Wimplicit-fallthrough
    Warn when a switch case falls through. If this is an intended
    -action, it can be marked with the [[fallthrough]] attribute
  • -Wtrampolines
    Enable warnings about trampolines that require executable stacks.

The following options which affect the generated code are added:

  • -fstack-clash-protection
    Enable run-time checks for variable-size stack allocation validity.
    This may affect performance if code allocates a lot of memory on the
    stack, but since we don't do that, we should be fine.
  • -fstrict-flex-arrays=3
    Consider trailing array (at the end of struct) as flexible array
    only if declared as []
  • (x86) -fcf-protection=full
    Enable control flow protection to counter Return Oriented
    Programming (ROP) and Jump Oriented Programming (JOP) attacks on
    many x86 architectures
  • (arm64) -mbranch-protection=standard
    Enable branch protection to counter Return Oriented
    Programming (ROP) and Jump Oriented Programming (JOP) attacks on
    AArch64

The following compile-time warning options are added:

  * -Wformat=2
    Enable additional format function warnings. The `2` form of the
    option enables more extensive checks in calls to `printf`, `scanf`
    etc. These are compile-time only checks, no effect on runtime
    performance.
  * -Wimplicit-fallthrough
    Warn when a switch case falls through. If this is an intended
    -action, it can be marked with the `[[fallthrough]]` attribute
  * -Wtrampolines
    Enable warnings about trampolines that require executable stacks.

The following options which affect the generated code are added:

  * -fstack-clash-protection
    Enable run-time checks for variable-size stack allocation validity.
    This may affect performance if code allocates a lot of memory on the
    stack, but since we don't do that, we should be fine.
  * -fstrict-flex-arrays=3
    Consider trailing array (at the end of struct) as flexible array
    only if declared as `[]`
  * (x86) -fcf-protection=full
    Enable control flow protection to counter Return Oriented
    Programming (ROP) and Jump Oriented Programming (JOP) attacks on
    many x86 architectures
  * (arm64) -mbranch-protection=standard
    Enable branch protection to counter Return Oriented
    Programming (ROP) and Jump Oriented Programming (JOP) attacks on
    AArch64
@jonpryor jonpryor merged commit 6f67509 into main Dec 4, 2023
47 checks passed
@jonpryor jonpryor deleted the dev/grendel/harden-native-code branch December 4, 2023 20:44
grendello added a commit that referenced this pull request Dec 4, 2023
* main:
  [monodroid] Add a handful of compiler options to harden code (#8551)
  Bump to dotnet/installer@42ace91ba7 .NET 9.0.100-alpha.1.23603.1 (#8366)
  [xaprepare] Track the versions of Android SDK Levels available on CI agents. (#8552)
grendello added a commit that referenced this pull request Dec 5, 2023
* main:
  [monodroid] Add a handful of compiler options to harden code (#8551)
  Bump to dotnet/installer@42ace91ba7 .NET 9.0.100-alpha.1.23603.1 (#8366)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants