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