This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 853199 - daemon programs should be compiled with PIE and full RELRO flags
daemon programs should be compiled with PIE and full RELRO flags
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: NetworkManager (Show other bugs)
18
Unspecified Unspecified
high Severity unspecified
: ---
: ---
Assigned To: Dan Williams
Fedora Extras Quality Assurance
:
Depends On: 892837 958290
Blocks: 853068
  Show dependency treegraph
 
Reported: 2012-08-30 13:19 EDT by Steve Grubb
Modified: 2013-05-24 16:16 EDT (History)
2 users (show)

See Also:
Fixed In Version: NetworkManager-0.9.8.1-4.git20130515.fc19
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-05-24 16:16:52 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)
Patch that adds PIE and full RELRO (1.39 KB, patch)
2013-03-07 14:18 EST, Steve Grubb
no flags Details | Diff
fix-gtk-doc-issue-with-hardened-build.patch (760 bytes, patch)
2013-04-30 16:29 EDT, Dan Williams
no flags Details | Diff


External Trackers
Tracker ID Priority Status Summary Last Updated
GNOME Desktop 700093 None None None Never

  None (edit)
Description Steve Grubb 2012-08-30 13:19:13 EDT
Description of problem:
Daemon programs should have full RELRO support enabled for extra protection. They should also have gcc's PIE flag enabled, too.

FILE                                                TYPE        RELRO    PIE 
/usr/bin/nm-online                                  daemon      partial  no  
/usr/sbin/NetworkManager                            daemon      partial  no  


You can use this program for testing:
http://people.redhat.com/sgrubb/files/rpm-chksec
Comment 1 Steve Grubb 2013-03-07 11:49:51 EST
Checking to see if there is any progress on updating the compile flags. We'd like to close this bug if its already done. Thanks.
Comment 2 Dan Williams 2013-03-07 13:05:12 EST
Does this mean we should be overriding the Fedora default compiler flags?  NM's specfile doesn't do anything special to whatever Fedora rpm macros set as the default.
Comment 3 Steve Grubb 2013-03-07 14:16:13 EST
Yes it would be overriding Fedora's defaults. Daemons need more protection than a user program, especially if they run as root. The PIE flags will randomize the address space for the daemon every start so that certain classes of attacks are not possible. The relro flags make certain writable spots in memory read only. This also helps prevent attacks.
Comment 4 Steve Grubb 2013-03-07 14:18:16 EST
Created attachment 706771 [details]
Patch that adds PIE and full RELRO

This patch solves the immediate problem. Perhaps a longer term solution is to detect support in configure and carry the flags to these two programs.
Comment 5 Dan Williams 2013-03-07 17:29:55 EST
Is there a downside to making all the binaries PIE?
Comment 6 Steve Grubb 2013-03-07 19:06:45 EST
The only downside is slower startup time. If its something used a lot in shell scripting, then it will be noticeable. That is why we are only asking for daemons - which are started on bootup and never again - to be PIE and full RELRO. The startup time difference is on the scale of milliseconds rather than whole seconds.

If you do something different than the patch above then please follow this note. Anything that has PIE flags set, should also be full RELRO, meaning its also passed the -Wl,-z,now linker flags. This is because when something is PIE, there is an extra segment added to the program that contains a lookup table for the functions. Full RELRO makes that readonly so that it cannot be attacked. Thanks.
Comment 7 Dan Williams 2013-03-08 10:32:50 EST
Are the linker flags compatible with different linkers too, not just gcc's linker?  I know we've gotten patches from Debian people for 'gold' support.  I'm just trying to figure out whether we can just enable by default upstream or whether we need to some configure-time magic to detect what compiler you've got so we can enable the options by default.
Comment 8 Steve Grubb 2013-03-08 12:10:59 EST
These flags are probably gcc specific. But I've seen other packages detect settings on the fly. For example, the suricata package does this:

        #forces all relocations to be resolved at run-time
        AC_MSG_CHECKING(for -z now)
        TMPLDFLAGS="${LDFLAGS}"
        LDFLAGS="${LDFLAGS} -z now"
        AC_TRY_LINK(,,SECLDFLAGS="${SECLDFLAGS} -z now"
        AC_MSG_RESULT(yes),
        AC_MSG_RESULT(no))
        LDFLAGS="${TMPLDFLAGS}"

This can be extended for the PIE flags. RELRO and PIE have been around since RHEL5. So almost everyone should have it if they use gcc.
Comment 10 Dan Williams 2013-03-19 17:53:53 EDT
Was just reading the Fedora packaging guidelines, which say:

----

PIE adds security to executables by composing them entirely of position-independent code. Position-independent code (PIC) is machine instruction code that executes properly regardless of where in memory it resides. PIE allows Exec Shield to use address space layout randomization to prevent attackers from knowing where existing executable code is during a security attack using exploits that rely on knowing the offset of the executable code in the binary, such as return-to-libc attacks.

To use this in your spec, add:

%global _hardened_build 1

This adds -fPIC (if -fPIE is not already present) to the compiler flags, and adds -z now to the linker flags.

If your package meets any of the following criteria you MUST enable the PIE compiler flags:

    Your package is long running. This means it's likely to be started and keep running until the machine is rebooted, not start on demand and quit on idle. 

    Your package has suid binaries, or binaries with capabilities. 

    Your package runs as root. 

If your package meets the following criteria you should consider enabling the PIE compiler flags:

    Your package accepts/processes untrusted input. 

FESCo maintains a list of packages that MUST have PIE turned on. Other packages may enable the flags at the maintainer's discretion.

There are some notable disadvantages to enabling PIE that should be considered in making the decision:

    Some code does not compile with PIE (or does not function properly). 

    You can not use prelink on PIE enabled binaries, resulting in a slower startup time. 

---

So perhaps for now we can just add this to the NetworkManager specfile, build a new NM, verify that NM is built with the right flags, and then work on the upstream bits in parallel?
Comment 11 Dan Williams 2013-04-30 16:27:35 EDT
I just tried building NM with "%global _hardened_build 1" on F18 and got:

gcc: fatal error: /usr/lib/rpm/redhat/redhat-hardened-cc1: attempt to rename spec 'cc1_options' to already defined spec 'rh_cc1_options_old'
compilation terminated.
Compilation of scanner failed: 
make[3]: *** [scan-build.stamp] Error 1

gtk-doc's standard makefile that gets copied into the project makes the new hardened flags stuff angry, see:

https://bugzilla.redhat.com/show_bug.cgi?id=955147#c2

I've filed bug 958290 for the gtk-doc fix.
Comment 12 Dan Williams 2013-04-30 16:29:06 EDT
Created attachment 741989 [details]
fix-gtk-doc-issue-with-hardened-build.patch
Comment 13 Dan Williams 2013-05-07 18:13:38 EDT
Patch fixes the issue locally, but apparently not on the buildsystem.  We really do want the redhat-rpm-config bug 892837 fixed.
Comment 14 Dan Williams 2013-05-09 17:02:29 EDT
Spent a bunch of time trying to get hardened_build to work and failed; we really do want the redhat-rpm-config bug fixed here.  Yes, we could theoretically work around it with a local patch to NM to stick pic/pie flags everywhere, but I'd rather get it fixed in redhat-rpm-config and use the standard Fedora construct.
Comment 15 Dan Williams 2013-05-10 12:01:21 EDT
Ok, got it working now I believe with some patches upstream to handle doc generation differently.  Are these results the ones we expect Steve?

FILE                                                     TYPE        RELRO    PIE 
/usr/bin/nm-online                                       daemon      full     yes 
/usr/bin/nm-tool                                         exec        full     yes 
/usr/bin/nmcli                                           exec        full     yes 
/usr/lib64/NetworkManager/libnm-settings-plugin-ifcfg-rh.so library     partial  DSO 
/usr/lib64/pppd/2.4.5/nm-pppd-plugin.so                  library     partial  DSO 
/usr/libexec/nm-avahi-autoipd.action                     exec        full     yes 
/usr/libexec/nm-dhcp-client.action                       exec        full     yes 
/usr/libexec/nm-dispatcher.action                        exec        full     yes 
/usr/sbin/NetworkManager                                 daemon      full     yes
Comment 16 Steve Grubb 2013-05-10 12:14:11 EDT
Thanks for the update. Yes, the two that needed to be PIE and Full RELRO are meeting the security requirements now. When you officially push it through the build system and schedule the updated package, feel free to close the bug. Thanks!
Comment 17 Dan Williams 2013-05-10 12:41:10 EDT
Will do; waiting for patch review upstream before I can build the snapshots for Fedora and RHEL.  https://bugzilla.gnome.org/show_bug.cgi?id=700093
Comment 18 Fedora Update System 2013-05-17 19:18:34 EDT
NetworkManager-0.9.8.1-4.git20130515.fc19,network-manager-applet-0.9.8.1-4.git20130514.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/NetworkManager-0.9.8.1-4.git20130515.fc19,network-manager-applet-0.9.8.1-4.git20130514.fc19
Comment 19 Fedora Update System 2013-05-18 13:57:20 EDT
Package NetworkManager-0.9.8.1-4.git20130515.fc19, network-manager-applet-0.9.8.1-4.git20130514.fc19:
* should fix your issue,
* was pushed to the Fedora 19 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing NetworkManager-0.9.8.1-4.git20130515.fc19 network-manager-applet-0.9.8.1-4.git20130514.fc19'
as soon as you are able to, then reboot.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2013-8509/NetworkManager-0.9.8.1-4.git20130515.fc19,network-manager-applet-0.9.8.1-4.git20130514.fc19
then log in and leave karma (feedback).
Comment 20 Fedora Update System 2013-05-24 16:16:52 EDT
NetworkManager-0.9.8.1-4.git20130515.fc19, network-manager-applet-0.9.8.1-4.git20130514.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.

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