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