077c9d
commit 94a4e9e4f401ffe829a992820439977ead0a0ce7
077c9d
Author: Florian Weimer <fweimer@redhat.com>
077c9d
Date:   Thu Apr 25 10:41:43 2019 +0200
077c9d
077c9d
    Extend BIND_NOW to installed programs with --enable-bind-now
077c9d
    
077c9d
    Commit 2d6ab5df3b675e96ee587ae6a8c2ce004c6b1ba9 ("Document and fix
077c9d
    --enable-bind-now [BZ #21015]") extended BIND_NOW to all installed
077c9d
    shared objects.  This change also covers installed programs.
077c9d
    
077c9d
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
077c9d
077c9d
diff --git a/INSTALL b/INSTALL
077c9d
index d6c8e899fbb47dac..d56e102ec9ed3281 100644
077c9d
--- a/INSTALL
077c9d
+++ b/INSTALL
077c9d
@@ -169,10 +169,10 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
077c9d
      protection.
077c9d
 
077c9d
 '--enable-bind-now'
077c9d
-     Disable lazy binding for installed shared objects.  This provides
077c9d
-     additional security hardening because it enables full RELRO and a
077c9d
-     read-only global offset table (GOT), at the cost of slightly
077c9d
-     increased program load times.
077c9d
+     Disable lazy binding for installed shared objects and programs.
077c9d
+     This provides additional security hardening because it enables full
077c9d
+     RELRO and a read-only global offset table (GOT), at the cost of
077c9d
+     slightly increased program load times.
077c9d
 
077c9d
 '--enable-pt_chown'
077c9d
      The file 'pt_chown' is a helper binary for 'grantpt' (*note
077c9d
diff --git a/Makeconfig b/Makeconfig
077c9d
index 8dc2fec9dc683416..742c0c0783a14bfa 100644
077c9d
--- a/Makeconfig
077c9d
+++ b/Makeconfig
077c9d
@@ -398,6 +398,8 @@ endif
077c9d
 # test modules.
077c9d
 ifeq ($(bind-now),yes)
077c9d
 LDFLAGS-lib.so += -Wl,-z,now
077c9d
+# Extra flags for dynamically linked non-test main programs.
077c9d
+link-extra-flags += -Wl,-z,now
077c9d
 endif
077c9d
 
077c9d
 # Command to run after every final link (executable or shared object).
077c9d
@@ -426,7 +428,7 @@ ifndef +link-pie
077c9d
 	     $(link-extra-libs)
077c9d
 +link-pie-after-libc = $(+postctorS) $(+postinit)
077c9d
 define +link-pie
077c9d
-$(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-libc) $(+link-pie-after-libc)
077c9d
+$(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
077c9d
 $(call after-link,$@)
077c9d
 endef
077c9d
 define +link-pie-tests
077c9d
@@ -454,7 +456,7 @@ ifndef +link-static
077c9d
 	      $(link-extra-libs-static)
077c9d
 +link-static-after-libc = $(+postctorT) $(+postinit)
077c9d
 define +link-static
077c9d
-$(+link-static-before-libc) $(link-libc-static) $(+link-static-after-libc)
077c9d
+$(+link-static-before-libc) $(link-extra-flags) $(link-libc-static) $(+link-static-after-libc)
077c9d
 $(call after-link,$@)
077c9d
 endef
077c9d
 define +link-static-tests
077c9d
@@ -485,7 +487,7 @@ else  # not build-pie-default
077c9d
 	      $(link-extra-libs)
077c9d
 +link-after-libc = $(+postctor) $(+postinit)
077c9d
 define +link
077c9d
-$(+link-before-libc) $(rtld-LDFLAGS) $(link-libc) $(+link-after-libc)
077c9d
+$(+link-before-libc) $(rtld-LDFLAGS) $(link-extra-flags) $(link-libc) $(+link-after-libc)
077c9d
 $(call after-link,$@)
077c9d
 endef
077c9d
 define +link-tests
077c9d
diff --git a/manual/install.texi b/manual/install.texi
077c9d
index e757891dc2eebb2e..351d67c68b255f62 100644
077c9d
--- a/manual/install.texi
077c9d
+++ b/manual/install.texi
077c9d
@@ -199,10 +199,10 @@ number of routines called directly from assembler are excluded from this
077c9d
 protection.
077c9d
 
077c9d
 @item --enable-bind-now
077c9d
-Disable lazy binding for installed shared objects.  This provides
077c9d
-additional security hardening because it enables full RELRO and a
077c9d
-read-only global offset table (GOT), at the cost of slightly increased
077c9d
-program load times.
077c9d
+Disable lazy binding for installed shared objects and programs.  This
077c9d
+provides additional security hardening because it enables full RELRO
077c9d
+and a read-only global offset table (GOT), at the cost of slightly
077c9d
+increased program load times.
077c9d
 
077c9d
 @pindex pt_chown
077c9d
 @findex grantpt