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