Bug 1387475 (RHEL-hardening-cflags) - Update compiler flags for hardened builds
Summary: Update compiler flags for hardened builds
Keywords:
Status: CLOSED WONTFIX
Alias: RHEL-hardening-cflags
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: redhat-rpm-config
Version: 7.3
Hardware: Unspecified
OS: Unspecified
high
medium
Target Milestone: rc
: ---
Assignee: Florian Festi
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On: 1406420 1406430 1406689 1406732 1409738 1409740 1409810 1410097 1420761 1420762 1420763 1420764 1420765 1420766 1420767 1420768 1420769 1420770 1420771 1420772 1420773 1420774 1420775 1420776 1420777 1420778 1420779 1420780 1420781 1420782 1420783 1420785 1420786 1420787 1420788 1420789
Blocks: 1377248 1380360 1393866
TreeView+ depends on / blocked
 
Reported: 2016-10-21 02:11 UTC by Steve Grubb
Modified: 2018-03-21 08:31 UTC (History)
6 users (show)

Fixed In Version: redhat-rpm-config-9.1.0-73.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-03-21 08:31:24 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Steve Grubb 2016-10-21 02:11:39 UTC
Description of problem:
Due to many advances in exploiting applications, we need to move RHEL 7 to using hardened builds across the board just like Fedora 23 and later. The expectation is every program is compiled with PIE flags.

While we cannot do a mass rebuild, the most important packages in RHEL will be getting updates. Each release we'll increase security as more and more packages are hardened.

The ask here is to backport the hardened macros so that everything is hardened like in Fedora. this would need to land early in the cycle and be put into the build root so that everything in the 7.4 release is hardened.

Additional info:
https://fedoraproject.org/wiki/Changes/Harden_All_Packages

Comment 1 Steve Grubb 2016-11-15 15:38:16 UTC
In terms of testing that the right things happened in the build system, we have to examine the elf flags of the resulting ELF files. Something along the lines of this would give you the flags:

#!/bin/sh

if [ $# -ne 1 ] ; then
  echo "You need to pass a file"
  exit 1
fi

/usr/bin/file $1 | grep 'ELF' >/dev/null 2>&1
if [ $? -ne 0 ] ; then
  echo "Not an ELF file"
  exit 1
fi

# Check PIE flags
if readelf -h $1 2>/dev/null | grep -q 'Type:[[:space:]]*EXEC'; then
  echo 'No PIE'
elif readelf -h $1 2>/dev/null | grep -q 'Type:[[:space:]]*DYN'; then
  if readelf -d $1 2>/dev/null | grep -q '(DEBUG)'; then
    echo 'PIE enabled'
  else
    echo 'Dynamic Shared Object'
  fi
fi

# Check RELRO flags
if readelf -l $1 2>/dev/null | grep -q 'GNU_RELRO'; then
  if readelf -d $1 2>/dev/null | grep -q 'BIND_NOW'; then
    echo 'Full RELRO'
  else
    echo 'Partial RELRO'
  fi
else
  echo 'No RELRO'
fi

You want either PIE Enabled or Dynamic Shared Object for the first line, and Full RELRO for the second line.

Comment 2 Steve Grubb 2016-11-15 16:59:41 UTC
Looking at the rhel7 file, we have this:
%_hardened_build        0

That should be changed to a 1. There is also some macro and script associated with %_configure_libtool_hardening_hack. I presume that should also be added. There's not much in the way of documenting what problem it solves. Also,
/usr/lib/rpm/redhat/redhat-hardened-cc1 and /usr/lib/rpm/redhat/redhat-hardened-ld are both slightly different. Again not much in the way of documenting why they were changed.


Note You need to log in before you can comment on or make changes to this bug.