musl has no support for textrels, so we always need PIC. At some point, I want
to move this into the general profiles by default (especially given the Binutils
work we're doing, see 86ac5c16e3), but baby steps.
Anyway, this is essential given things will crash on musl otherwise.
Bug: https://bugs.gentoo.org/707660
Signed-off-by: Sam James <sam@gentoo.org>
Unlike _p1 will likely keyword (and later stable) this one, but
have not really tested yet nor looked into if binutils did any
notable changes with mingw, so keep unkeyworded for a bit.
Signed-off-by: Ionen Wolkens <ionen@gentoo.org>
Newer Binutils has its several configure arguments we can use:
* --enable-textrel-check={warning,error}
* --enable-warn-execstack=yes (*)
* --enable-warn-rwx-segments=yes (*)
* --enable-default-execstack=no
We chuck these in now unconditionally (with some stricter changes for USE=hardened,
as described below) except for those marked with (*) where we whitelist certain
arches (amd64/arm64/x86 for now) because the autoconf logic is broken, see
https://sourceware.org/bugzilla/show_bug.cgi?id=29592 (it both needs --enable...=no
rather than --disable, but it also breaks arches where executable stacks are
unavoidable.)
In the past (see 47b8db23ff55dd29992198dfbadda53984a4ab2d, e4b8746852919960969944904c59334cecddfe25
in binutils-patches.git), we patched Binutils to always warn on textrels
opt-out on a per-build basis with '--no-warn-shared-textrel'). From >= Binutils 2.35,
upstream has a '--enable-textrel-check=warning' configure option we use.
For USE=hardened, our new changes for TEXTRELs are equivalent to `-z text`
which make TEXTRELs fatal.
Now, while at it, also make TEXTRELs fatal on musl unconditionally because
musl doesn't support them and they explode at runtime. Yet another reason
to get rid of them entirely.
So, in summary: there's several changes here:
* Make textrels fatal for USE=hardened (we've warned about them for a while
on all profiles)
* Make textrels fatal for musl (they don't work there at all, bug #707660)
* Disable implicit/automatic executable stacks for USE=hardened (plan to do this
in general later on)
* Warn on executable stacks in general
* Warn on RWX segments in general
See also https://www.redhat.com/en/blog/linkers-warnings-about-executable-stacks-and-segments
for more information.
All of this came to mind again after reading the Qualys writeup for the recent
OpenSSH bug (bug #910553): https://www.qualys.com/2023/07/19/cve-2023-38408/rce-openssh-forwarded-ssh-agent.txt.
(Note their use of various gadgets involving these.)
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29592
Bug: https://bugs.gentoo.org/707660
Bug: https://bugs.gentoo.org/869881
Bug: https://bugs.gentoo.org/871150
Bug: https://bugs.gentoo.org/910553
Signed-off-by: Sam James <sam@gentoo.org>
To ~arch for now in case this end up having unexpected
consequences, albeit will not wait all that long.
Also adjust messages (both first merge and update from -r0)
to advertise the full path if users need it.
Closes: https://bugs.gentoo.org/911245
Signed-off-by: Ionen Wolkens <ionen@gentoo.org>