RELRO feature support has been added to our linker in early 2012 by kib.
Given there is no know performances issues I do propose to activate it by default
Differential D3001
Activate relro and bindnow in build system bapt on Jul 6 2015, 9:01 AM. Authored by Tags None Referenced Files
Tokens
Details
Diff Detail
Event TimelineComment Actions -z now changes the symbol resolution model. Also it has performance penalty for large binaries. Comment Actions Is the penalty for -z,relro, or for -z,now or for both? (I thought that relro is mainly marking the objects and penalty associated with it should be small, no?) BTW. it looks like we are not write-protecting the PLT even when doing BIND_NOW? Comment Actions Never mind for this part, I misinterpreted '-z now changes' as '"-z" now changes' while you actually meant '"-z now" changes'. Comment Actions Performance impact of -z relro is negligible.
GNU ld puts plt into the RX (not-writeable) segment even without -z relro, at least on x86. Plt does not need to be writeable, it references GOT (gotplt) entries which are patched by rtld during binding. Comment Actions The thing is relro is pretty useless without BIND_NOW. After checking what I can see is that on linux what they do is activate relro on all binaries, and cherry-pick bind_now (like they do for PIE) only on binaries that already had a security issue in the past years. Maybe I should only activate relro here, and add a mechanism to cherry pick bind_now Comment Actions This is not completely true. Without -z now, the ctr/dtr and dynamic tables are still placed into the relro pages. Yes, without -z now, GOT usually cannot be placed into relro page.
-z now probably should never be turned for for code which load plugins, without somebody asserting that nothing wrong happens. I think that nss is safe in this regard, but I am very much unsure about crazy tricks which could be done e.g. by perl xs modules. Comment Actions Just an opinion ... Comment Actions Agreed. Would it be a good idea to have bindnow as a WITH_* flag that defaults to off? Comment Actions I can't see any downside. Comment Actions BTW, I found this link: Also: Comment Actions I don't like this approach:
I adapted a patch to our binutils and I have asked for an exp-run (PR 203394) along with another change (stack-protector-strong) which may be expected to be of small/no impact. Note that older GNU strip had issues with relro, so we should test BSD strip(1): Comment Actions Google is your friend ... https://wiki.gentoo.org/wiki/Hardened/Toolchain#Issues_arising_from_default_NOW Comment Actions I do not think it is reasonable to change default linker behaviour to diverge from the upstream. Not all linker trickery lives in ports, your change will certainly break some private code. Compare how less ABI-damaging --hash-style=gnu or similarly affecting --enable-new-dtags are handled. When Linux/glibc people changed the value of --copy-dt-needed-entries, they did that with a year-long campaign to ensure that the transition went smooth. relro is lesser feature, but it still can damage someone. Comment Actions I agree the change is controversial: we are indeed choosing between adding GNUisms to our build or maintaining an extra line in the linker. For some reason Redhat (CentOS), which also owns sourceware, carries this patch and it seems more practical than the alternatives. Doing it as a build flag will leave all ports unaffected unless we add the new ldflags also to the ports tree.
Private code can still disable relro, but I see your point. Nevertheless, it still will be interesting to see, through the exp-run, how ports react to having relro by default. Comment Actions You would only see a half of the interesting things, at best. Another half happens at runtime, which cannot be tested by an exp-run. Comment Actions The toolchain will certainly be runtime tested, and some ports have testing targets. I am also running it on my box. The question is .. what would be affected? Is there any particular port I should check? Comment Actions It is definitely not toolchain but the final linked binaries which should be tested.
I do not aware about in-ports apps. I would expect the hacks like runtime API intereceptors to break (which is, so to say, the purpose of relro). Comment Actions Yes, you should take a look at Xorg port, we running into some issue with full relro in our test builds, but for more details ask Shawn. Comment Actions I meant the linked binaries from the toolchains. Not only the base binaries but stuff like gcc48. Also emacs and java (I think) has some bootstrapping code.
I will rebuild Java, perhaps that is affected. To make things clear: I am just testing the waters. Comment Actions As expected an exp-run with partial relro enabled didn't find any issue. It appears upstream (binutils) will not make partial relro the default as it is not supported everywhere. For reference: NetBSD doesn't support it yet and OpenBSD does relro by default in their native toolchain but they intentionally left no way to turn it off. I brought the subject to the GNU binutils list and a Gentoo developer recommended the linker approach, claiming they have been doing it for 9 years. Apparently there is a recurring subject with a patch to enable it as a configure option but they haven't agreed on the details. Comment Actions We've been running with a modified version of this patch in HardenedBSD for a while now. It only applies to base and not ports, though we have some ports opting into RELRO + BIND_NOW. Would this be something that could be committed? Or are there still objections? Comment Actions Nothing has changed ... I don't think FreeBSD should follow that path. Eventually, performance issues with BIND_NOW need to be evaluated on a per-case basis. OTOH, if you want to see *partial* RELRO as a default in the future, you could work with upstream binutils to get their WIP patch cleaned up: Comment Actions
Note that binutils 2.27 now supports a configure-time relro default, and it is enabled by default on (non-frv|hppa|ia64|mips) Linux. We can set it by default in our binutils ports, and then push it upstream. Comment Actions Good, I was expecting it to happen someday ;). I have a patch for our base binutils here: Our binutils port is still in version 2.25 so we will have to wait, also I am not sure if FreeBSD-9.0 supports partial relro so enabling relro will depend on OSVERSION. Comment Actions Answering to myself: support for RELRO was merged to FreeBSD 9-Stable on r231579 and included in 9.1 so it appears all supported OS versions can use RELRO. |