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

Fortify source should require -O2 #1432

Closed
MarkusTeufelberger opened this issue Dec 10, 2015 · 7 comments
Closed

Fortify source should require -O2 #1432

MarkusTeufelberger opened this issue Dec 10, 2015 · 7 comments
Assignees

Comments

@MarkusTeufelberger
Copy link
Collaborator

While trying to get clang's static analyzer to run with rippled, I encountered some weird looking errors when building gcc.debug:

#warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]

(Relevant lines in Sconstruct: around line 605)
Apparently, the fortify source switch only makes sense with optimizations turned ON. I already had a -Og switch in there a while ago, but it was patched out later in d26241d since it apparently caused some trouble.

@nbougalis
Copy link
Contributor

I don't think that _FORTIFY_SOURCE requires -O2 as such. In fact, I have been happily compiling with _FORTIFY_SOURCE under gcc for a while and have never seen a complaint.

@MarkusTeufelberger
Copy link
Collaborator Author

glibc introduced this check: https://sourceware.org/git/?p=glibc.git;a=commit;f=include/features.h;h=05c2c9618f583ea4acd69b3fe5ae2a2922dd2ddc. Here's the gcc patch implementing the checks in general (http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html) and here the man page about it (http://man7.org/linux/man-pages/man7/feature_test_macros.7.html)

According to Debian: https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_FORTIFY_.28gcc.2Fg.2B-.2B-_-D_FORTIFY_SOURCE.3D2.29 and Ubuntu: https://wiki.ubuntu.com/ToolChain/CompilerFlags#A-D_FORTIFY_SOURCE.3D2

The real problem is what Debian patches in glibc (http://metadata.ftp-master.debian.org/changelogs/main/g/glibc/glibc_2.21-4_changelog):

Amongst other things: "[ Matthias Klose ]

  • Add patches/any/local-revert-bz13979.diff: revert a commit that made
    attempts to build with FORTIFIED_SOURCE issue warnings if GCC didn't
    have optimisations turned on. This breaks some unclever AC macros."

This way you won't see this warning on debian based distros, it'll probably just fail silently. I assume you've been compiling happily on debian based distributions exclusively? I see this compliant with Arch Linux for example (which rarely modifies upstream code)...

@nbougalis
Copy link
Contributor

Thanks @MarkusTeufelberger: I'll think about how we should tackle this.

@MarkusTeufelberger
Copy link
Collaborator Author

Apparently fixed by no longer fortifying debug builds (e60981f). Let's hope everyone out there runs release builds.

@nbougalis
Copy link
Contributor

@MarkusTeufelberger: we don't fortify anything any more (commit b0704b4 is the version that was merged). What do you mean "Let's hope everyone out there runs release builds"? Do you think some additional changes are needed?

@MarkusTeufelberger
Copy link
Collaborator Author

As far as I understand it, FORTIFY_SOURCE helps with detecting buffer overflows both at compile time and run time. This can protect against some types of buffer overflow attacks, also in compromised running systems (crashing the binary instead of continuing).

The argument that address sanitizer works similarly is not a very good one (already pointed out in the pull request) and it is anyways not enabled by default in release builds (it also didn't build for me at least, see #1932 for the fix).

I personally would like to see as many hardening techniques enabled as possible for release builds. With sanitizers I'm not so sure, since they might fire because of problems in the code, not in the execution of the binary, but ASLR, FORTIFY_SOURCE etc. are defensive tools against attacks that are beyond what's written in your code, not just debugging helpers.

@nbougalis
Copy link
Contributor

nbougalis commented Jan 13, 2017

I agree that sanitizers aren't targeting the same case, and that using as much source-hardening as possible (or at least, offering the option) is a good idea. We can make it an option for those that build the release version of rippled themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants