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

Compile with hardening flags #633

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Compile with hardening flags #633

wants to merge 6 commits into from

Conversation

bchurchill
Copy link

These flags mitigate the risk of zero-day memory corruption vulnerabilities, like buffer overflow attacks. In brief, the options added are:

-fpic -pie
Compiles position independent code, to take advantage of ASLR. This makes it harder to write exploits because it requires an information leak bug or brute force attack in addition to the memory corruption exploit.

-fstack-protector-all --param ssp-buffer-size=4
Ensures a canary is placed on the stack any time there's a potentially vulnerable function. This mitigates many stack-based overflows.

-Wl,-z,relro,-z,now
Makes relocation tables read-only, making it harder to do a return-to-libc style attack by rewriting a relocation entry.

-Wformat -Wformat-security
Complains loudly if there's an obvious format string injection vulnerability.

-D_FORTIFY_SOURCE=2
Adds some extra checks on buffer lengths.

You can read about some of these options in section 5 of https://wiki.debian.org/Hardening. Some details are also at https://wiki.ubuntu.com/ToolChain/CompilerFlags?action=show&redirect=CompilerFlags.

@bchurchill
Copy link
Author

I can't reproduce some of these environments locally, so I may need to submit a few more pull requests to get the kinks worked out.

@bchurchill bchurchill closed this Jul 9, 2015
@atomicturtle
Copy link
Member

For what its worth we've been building the rpms with this for many years now, and a good test suite to look at the settings is: http://www.trapkit.de/tools/checksec.html

As it stands right now, we still need to make some changes to the source tree to get this working right in 2.9 so I'm going to re-open this one.

@atomicturtle atomicturtle reopened this Jul 9, 2015
@bchurchill
Copy link
Author

At first I didn't realize I could make a commit and have travis rebuild the pull request, so I thought I'd have to submit others (which is why I closed this one earlier). Now that the build is working, I think it's ready for someone else to review.

@ddpbsd
Copy link
Member

ddpbsd commented Aug 13, 2015

I'm seeing a lot of messages I'd rather not see when compiling with this diff:

gcc: -z: linker input file unused because linking not done
gcc: relro: linker input file unused because linking not done
gcc: -z: linker input file unused because linking not done
gcc: now: linker input file unused because linking not done

@bchurchill
Copy link
Author

Ok, I'll look into that.

On 08/13/2015 01:18 PM, Dan Parriott wrote:

I'm seeing a lot of messages I'd rather not see when compiling with
this diff:

|gcc: -z: linker input file unused because linking not done
gcc: relro: linker input file unused because linking not done
gcc: -z: linker input file unused because linking not done
gcc: now: linker input file unused because linking not done
|


Reply to this email directly or view it on GitHub
#633 (comment).

@atomicturtle
Copy link
Member

Looks like this doesnt get ossec-dbd either:

   ossec-dbd  27528 No RELRO          Canary found           PaX enabled   No PIE                  

@atomicturtle
Copy link
Member

Oh and authd is only partial:
ossec-authd 29936 Partial RELRO Canary found PaX enabled PIE enabled

@sempervictus
Copy link

Is this still live, or have the v3+ compiler options included the relevant hardening bits in other commits?
Separately, I'd probably suggest buffer overflow and struct randomization under GCC, as well as building with selfrando for fine grained randomization per run so long as mprotect is not in play (maybe using mmap for those cases). I imagine clang builds could benefit from CFI and other hardening approaches as well.

@ddpbsd
Copy link
Member

ddpbsd commented Apr 6, 2018

I don't think they're on by default, but they can be set during compile time. @atomicturtle might be using some of these for the packages. I imagine some of these can be set for some systems, but whether AIX and similar systems would work is a mystery.

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

Successfully merging this pull request may close these issues.

None yet

4 participants