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