Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Mar 2023 16:07:46 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: ee71c37bc123 - stable/13 - Add RELRO build knob, default to enabled
Message-ID:  <202303021607.322G7koZ021277@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=ee71c37bc1231f56b82e6b8993d370ccb22a91f6

commit ee71c37bc1231f56b82e6b8993d370ccb22a91f6
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-06-22 12:58:04 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-03-02 14:25:27 +0000

    Add RELRO build knob, default to enabled
    
    Note that lld enables relro by default, so that we already had either
    partial or full RELRO, depending on the state of the BIND_NOW knob.
    
    Add a RELRO knob so that the option can be disabled if desired, and so
    that builds using the GNU toolchain are equivalent to those using the
    standard Clang/LLVM toolchain.
    
    Reviewed by:    markj
    MFC after:      3 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D35545
    
    (cherry picked from commit 2f3a961487c97dc879f07bb97bc62d7bd70b3f8d)
---
 share/mk/bsd.lib.mk               | 5 +++++
 share/mk/bsd.opts.mk              | 1 +
 share/mk/bsd.prog.mk              | 5 +++++
 tools/build/options/WITHOUT_RELRO | 4 ++++
 tools/build/options/WITH_BIND_NOW | 7 +++++++
 tools/build/options/WITH_RELRO    | 5 +++++
 6 files changed, 27 insertions(+)

diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index d4819615d50c..71c3dab011ef 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -77,6 +77,11 @@ TAG_ARGS=	-T ${TAGS:[*]:S/ /,/g}
 .if ${MK_BIND_NOW} != "no"
 LDFLAGS+= -Wl,-znow
 .endif
+.if ${MK_RELRO} == "no"
+LDFLAGS+= -Wl,-znorelro
+.else
+LDFLAGS+= -Wl,-zrelro
+.endif
 .if ${MK_RETPOLINE} != "no"
 .if ${COMPILER_FEATURES:Mretpoline} && ${LINKER_FEATURES:Mretpoline}
 CFLAGS+= -mretpoline
diff --git a/share/mk/bsd.opts.mk b/share/mk/bsd.opts.mk
index 33d843593427..33516070ac67 100644
--- a/share/mk/bsd.opts.mk
+++ b/share/mk/bsd.opts.mk
@@ -62,6 +62,7 @@ __DEFAULT_YES_OPTIONS = \
     NLS \
     OPENSSH \
     PROFILE \
+    RELRO \
     SSP \
     TESTS \
     TOOLCHAIN \
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
index 5e7aaaeb37f8..78fc920ec337 100644
--- a/share/mk/bsd.prog.mk
+++ b/share/mk/bsd.prog.mk
@@ -41,6 +41,11 @@ MK_DEBUG_FILES=	no
 .if ${MK_BIND_NOW} != "no"
 LDFLAGS+= -Wl,-znow
 .endif
+.if ${MK_RELRO} == "no"
+LDFLAGS+= -Wl,-znorelro
+.else
+LDFLAGS+= -Wl,-zrelro
+.endif
 .if ${MK_PIE} != "no"
 # Static PIE is not yet supported/tested.
 .if !defined(NO_SHARED) || ${NO_SHARED:tl} == "no"
diff --git a/tools/build/options/WITHOUT_RELRO b/tools/build/options/WITHOUT_RELRO
new file mode 100644
index 000000000000..f5b661f5916d
--- /dev/null
+++ b/tools/build/options/WITHOUT_RELRO
@@ -0,0 +1,4 @@
+Do not apply the Relocation Read-Only (RELRO) vulnerability mitigation.
+See also the
+.Va BIND_NOW
+option.
diff --git a/tools/build/options/WITH_BIND_NOW b/tools/build/options/WITH_BIND_NOW
index 02e4c37352b4..a2d3ac7e7779 100644
--- a/tools/build/options/WITH_BIND_NOW
+++ b/tools/build/options/WITH_BIND_NOW
@@ -3,3 +3,10 @@ Build all binaries with the
 .Dv DF_BIND_NOW
 flag set to indicate that the run-time loader should perform all relocation
 processing at process startup rather than on demand.
+The combination of the
+.Va BIND_NOW
+and
+.Va RELRO
+options provide "full" Relocation Read-Only (RELRO) support.
+With full RELRO the entire GOT is made read-only after performing relocation at
+startup, avoiding GOT overwrite attacks.
diff --git a/tools/build/options/WITH_RELRO b/tools/build/options/WITH_RELRO
new file mode 100644
index 000000000000..cfc344dd9cfe
--- /dev/null
+++ b/tools/build/options/WITH_RELRO
@@ -0,0 +1,5 @@
+Build all binaries with the Relocation Read-Only (RELRO) vulnerability
+mitigation applied.
+See also the
+.Va BIND_NOW
+option.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202303021607.322G7koZ021277>