Bug 587843

Summary: rpm: Default %install macro can wipe arbitrary directories
Product: [Fedora] Fedora Reporter: Joel Becker <joel.becker>
Component: redhat-rpm-configAssignee: Panu Matilainen <pmatilai>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: low    
Version: 11CC: security-response-team
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-06-28 15:44:04 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joel Becker 2010-05-01 02:32:22 UTC
Description of problem:

While playing around with the RHEL6 beta and Fedora 11, we ran into a problem with one of our packages.  Our package currently builds multiple versions of the same software in one %build section, like so (pseudocode):

-------------------------------------------------------
%install
    for config in $CONFIG; do
        configure --config=$CONFIG
        make
        make install DESTDIR=$RPM_BULID_ROOT/usr/lib/ourpackage/$CONFIG
        make clean
    done
-------------------------------------------------------

Our %install section does some final housekeeping, and our %files contains /usr/lib/ourpackage.

This worked great on previous versions of RHEL and Fedora (I filed against Fedora because I think this should be fixed ASAP).  It broke against RHEL6 and Fedora 11, because of the following snippet in /usr/lib/rpm/redhat/macros:

-------------------------------------------------------
 81 %__spec_install_pre %{___build_pre}\
 82     [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"\
 83     mkdir -p `dirname "$RPM_BUILD_ROOT"`\
 84     mkdir "$RPM_BUILD_ROOT"\
 85 %{nil}
-------------------------------------------------------

Note the second line.  It's obvious why our spec file breaks - we've installed files in RPM_BUILD_ROOT during %build, and they are erased at the start of %install.  We can certainly work around that, but that's not the point.

ANYONE TRICKED INTO REBUILDING A MALICIOUS SPECFILE CAN WIPE ARBITRARY DIRECTORIES.


Any specfile that defines a BuildRoot other than '/' will remove that directory, permissions willing.  People who do "rpmbuild -ta malicious.tar.gz" can have their home directory wiped.  Some people naively do RPM builds as root, using /usr/src/redhat.  This gives the attacker a way to remove /usr or /etc.

Comment 1 Tomas Hoger 2010-05-03 07:00:52 UTC
(In reply to comment #0)

> ANYONE TRICKED INTO REBUILDING A MALICIOUS SPECFILE CAN WIPE ARBITRARY
> DIRECTORIES.

If you are tricked into rebuilding a malicious specfile, you have bigger problems than accidental removal of some directory (think of various spec-file-author chosen commands that are run in various build steps).  I fail to see the security implications here.

Part of the packaging guidelines related to this:
  http://fedoraproject.org/wiki/Packaging/Guidelines#BuildRoot_tag

Which says:
  "Fedora (as of F-10) does not require the presence of the BuildRoot tag in
  the spec and if one is defined it will be ignored."

Some related discussion on the packaging list:
  http://lists.fedoraproject.org/pipermail/packaging/2009-May/006025.html

Comment 2 Tomas Hoger 2010-05-03 07:05:26 UTC
(In reply to comment #0)

> Note the second line.  It's obvious why our spec file breaks - we've installed
> files in RPM_BUILD_ROOT during %build, and they are erased at the start of
> %install.

Maybe your example in comment #0 is not a good example of what your spec file really does, as it shows all work being done in %install and hence should not be broken by pre-%install build root removal.

Comment 3 Joel Becker 2010-05-03 18:37:43 UTC
In reverse order:

Argh!  Yes, I meant %build in my example.  You probably figured that out.  Of course it is affected by the pre-%install rm.  As I stated, we can work around this, and isn't a reason for a bug report on its own.  We'll either store our objects somewhere in the build tree or we'll do "mv $RPM_BUILD_ROOT $RPM_BUILD_ROOT.tmp" and then move it back in %install.

I didn't know that BuildRoot was now ignored.  I usually specify one for predictability and control, but my shell snippets always use $RPM_BUILD_ROOT and wouldn't notice if you had changed that behavior ;-)  Clearly, if BuildRoot is ignored then the pre-%install rm cannot be tricked by it.  So that concern is addressed.

That said, I would guess that less than one out of every 10,000 people downloading an SRPM reads the specfile before rebuilding the sucker.  Especially if they found it via rpmfind or the like.  It think it is fair to consider this reality.  What made me extra concerned was that this hidden rm would have surprised even people that actually did look at the specfile and verified no malicious commands existed in the shell snippets.  Thankfully, the BuildRoot deprecation seems to make it safe.

Comment 4 Bug Zapper 2010-06-28 15:44:04 UTC
Fedora 11 changed to end-of-life (EOL) status on 2010-06-25. Fedora 11 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.