Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 876923 - [toolchain] Enable full relro / -z,now in LDFLAGS by default
Summary: [toolchain] Enable full relro / -z,now in LDFLAGS by default
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on: profile-23.0 892952
Blocks: future-profile
  Show dependency tree
 
Reported: 2022-10-13 06:12 UTC by Hanno Böck
Modified: 2024-04-10 03:49 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hanno Böck gentoo-dev 2022-10-13 06:12:00 UTC
Full relro is a hardening feature enabled by the linker flags "-z,relro,-z,now". It's enabled in Gentoo hardened, but not by default.

Other distros like Fedora or Ubuntu have enabled it by default for quite some time, I think it should be considered part of the "standard hardening" features that should be default on by now.

I'd suggest to enable it with profile-23.0.
Comment 1 Agostino Sarubbo gentoo-dev 2022-10-13 06:54:33 UTC
I understand your concern, but at some point there will be no difference between the default profile and the hardened profile
Comment 2 Hanno Böck gentoo-dev 2022-10-13 08:15:35 UTC
That would in my view be a good outcome. "Gentoo hardened" originated in a time where many exploit mitigation features where considered optional. Most of what originally was hardened, like stack protection and aslr, are considered default everywhere these days.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-10-13 18:38:48 UTC
(In reply to Agostino Sarubbo from comment #1)
> I understand your concern, but at some point there will be no difference
> between the default profile and the hardened profile

This isn't a reason by itself to not do it, and the aim is always to get stuff into vanilla builds if we can help it.

Hardened is both a testing ground for new hardening stuff which might never make it to vanilla but also stuff where we want it to mature and then graduate.

Anyway, here's a recent summary of the differences: https://wiki.gentoo.org/wiki/Hardened/Toolchain#Changes. Soon, we'll add -D_FORTIFY_SOURCE=3 and -D_GLIBCXX_ASSERTIONS to hardened.
Comment 4 Andreas K. Hüttel archtester gentoo-dev 2022-11-13 00:04:48 UTC
> Full relro is a hardening feature enabled by the linker flags
> "-z,relro,-z,now". It's enabled in Gentoo hardened, but not by default.
> [...] 
> I'd suggest to enable it with profile-23.0.

Works for me, but we need to nail down some technical details first.

In hardened, this is enabled by hardwiring "-z,relro,-z,now" into LDFLAGS
in gcc. That basically means all linker calls coming from gcc are handled (but, e.g., none from clang).
Making this a bit more configurable and moving it to general default is straightforward. But...

Would it make sense to do this inside ld.bfd instead? It already has a build time option ton enable "relro" by default, would need a similar one for "now".
Then again, that would handle all usage of ld.bfd and none of (bäh) ld.gold and ld.lld ...
Comment 5 Andreas K. Hüttel archtester gentoo-dev 2022-11-13 21:54:01 UTC
(In reply to Andreas K. Hüttel from comment #4)
> > Full relro is a hardening feature enabled by the linker flags
> > "-z,relro,-z,now". It's enabled in Gentoo hardened, but not by default.
> > [...] 
> > I'd suggest to enable it with profile-23.0.

At second thought...

"-z relro" is already enabled by default in Gentoo since 2017

"-z now" is available in gcc via the hardening flags, so let's just move it out of there and control it with a separate useflag.
Comment 6 Larry the Git Cow gentoo-dev 2022-12-05 00:26:47 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=adf44514cf590a860b3140efae31187854cf8cea

commit adf44514cf590a860b3140efae31187854cf8cea
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-12-05 00:25:46 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-12-05 00:26:35 +0000

    toolchain.eclass: allow default-znow, default-stack-clash-protection for 12.2.1_p20221203
    
    Bug: https://bugs.gentoo.org/675050
    Bug: https://bugs.gentoo.org/876923
    Signed-off-by: Sam James <sam@gentoo.org>

 eclass/toolchain.eclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=975678507aa3cebb0d1d1919d4b684c64d50ffe7

commit 975678507aa3cebb0d1d1919d4b684c64d50ffe7
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-12-05 00:25:19 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-12-05 00:26:34 +0000

    sys-devel/gcc: use patchset 3 for 12.2.1_p20221203
    
    Includes the default-* hardening bits.
    
    Bug: https://bugs.gentoo.org/675050
    Bug: https://bugs.gentoo.org/876923
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-devel/gcc/Manifest                    | 1 +
 sys-devel/gcc/gcc-12.2.1_p20221203.ebuild | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
Comment 7 Larry the Git Cow gentoo-dev 2024-03-23 15:42:57 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8bfd8afef6dd8c66def48ef52abcb624c0077ad1

commit 8bfd8afef6dd8c66def48ef52abcb624c0077ad1
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-03-23 15:04:34 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-03-23 15:38:51 +0000

    sys-devel/clang-common: updates for 23.0
    
    * Promote -Wl,-z,now to vanilla, following GCC (bug #876923)
    * Add USE=cet to control -fcf-protection, following GCC (bug #908600, bug #927298)
    
    Bug: https://bugs.gentoo.org/876923
    Bug: https://bugs.gentoo.org/927298
    Closes: https://bugs.gentoo.org/908600
    Signed-off-by: Sam James <sam@gentoo.org>

 profiles/arch/amd64/package.use.mask               |   1 +
 profiles/base/package.use.mask                     |   1 +
 profiles/features/musl/package.use.mask            |   1 +
 .../clang-common/clang-common-17.0.6-r2.ebuild     | 295 ++++++++++++++++++++
 .../clang-common/clang-common-18.1.2-r1.ebuild     | 297 +++++++++++++++++++++
 .../clang-common/clang-common-19.0.0.9999.ebuild   |  10 +-
 .../clang-common-19.0.0_pre20240316.ebuild         |  10 +-
 sys-devel/clang-common/metadata.xml                |  10 +
 8 files changed, 621 insertions(+), 4 deletions(-)
Comment 8 Andreas K. Hüttel archtester gentoo-dev 2024-04-10 03:49:07 UTC
This is fixed in the 23.0 profiles (available and stable now). Closing.