Bug 587843 - rpm: Default %install macro can wipe arbitrary directories
rpm: Default %install macro can wipe arbitrary directories
Status: CLOSED WONTFIX
Product: Fedora
Classification: Fedora
Component: redhat-rpm-config (Show other bugs)
11
All Linux
low Severity high
: ---
: ---
Assigned To: Panu Matilainen
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-04-30 22:32 EDT by Joel Becker
Modified: 2010-06-28 11:44 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-06-28 11:44:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Joel Becker 2010-04-30 22:32:22 EDT
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 03:00:52 EDT
(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 03:05:26 EDT
(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 14:37:43 EDT
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 11:44:04 EDT
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.

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