256ebe
From 2adb5d540e9344149ae2591811ad34928775e6fd Mon Sep 17 00:00:00 2001
256ebe
From: Atin Mukherjee <amukherj@redhat.com>
256ebe
Date: Wed, 3 Jun 2015 11:09:21 +0530
256ebe
Subject: [PATCH 09/52] build: introduce security hardening flags in gluster
256ebe
256ebe
This patch introduces two of the security hardening compiler flags RELRO & PIE
256ebe
in gluster codebase. Using _hardened_build as 1 doesn't guarantee the existance
256ebe
of these flags in the compilation as different versions of RHEL have different
256ebe
redhat-rpm-config macro. So the idea is to export these flags at spec file
256ebe
level.
256ebe
256ebe
Label: DOWNSTREAM ONLY
256ebe
256ebe
Change-Id: I0a1a56d0a8f54f110d306ba5e55e39b1b073dc84
256ebe
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
256ebe
Reviewed-on: https://code.engineering.redhat.com/gerrit/49780
256ebe
Reviewed-by: Balamurugan Arumugam <barumuga@redhat.com>
256ebe
Tested-by: Balamurugan Arumugam <barumuga@redhat.com>
256ebe
Reviewed-on: https://code.engineering.redhat.com/gerrit/60137
256ebe
Tested-by: Milind Changire <mchangir@redhat.com>
256ebe
---
256ebe
 glusterfs.spec.in | 19 +++++++++++++++++++
256ebe
 1 file changed, 19 insertions(+)
256ebe
256ebe
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
256ebe
index eb04491..8a31a98 100644
256ebe
--- a/glusterfs.spec.in
256ebe
+++ b/glusterfs.spec.in
256ebe
@@ -736,6 +736,25 @@ done
256ebe
 
256ebe
 %build
256ebe
 
256ebe
+# In RHEL7 few hardening flags are available by default, however the RELRO
256ebe
+# default behaviour is partial, convert to full
256ebe
+%if ( 0%{?rhel} && 0%{?rhel} >= 7 )
256ebe
+LDFLAGS="$RPM_LD_FLAGS -Wl,-z,relro,-z,now"
256ebe
+export LDFLAGS
256ebe
+%else
256ebe
+%if ( 0%{?rhel} && 0%{?rhel} == 6 )
256ebe
+CFLAGS="$RPM_OPT_FLAGS -fPIE -DPIE"
256ebe
+LDFLAGS="$RPM_LD_FLAGS -pie -Wl,-z,relro,-z,now"
256ebe
+%else
256ebe
+#It appears that with gcc-4.1.2 in RHEL5 there is an issue using both -fPIC and
256ebe
+ # -fPIE that makes -z relro not work; -fPIE seems to undo what -fPIC does
256ebe
+CFLAGS="$CFLAGS $RPM_OPT_FLAGS"
256ebe
+LDFLAGS="$RPM_LD_FLAGS -Wl,-z,relro,-z,now"
256ebe
+%endif
256ebe
+export CFLAGS
256ebe
+export LDFLAGS
256ebe
+%endif
256ebe
+
256ebe
 ./autogen.sh && %configure \
256ebe
         %{?_with_asan} \
256ebe
         %{?_with_cmocka} \
256ebe
-- 
256ebe
1.8.3.1
256ebe