Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 225007 (CVE-2008-3797) - Some scm eclasses set incorrect permissions on DISTDIR (CVE-2008-3797)
Summary: Some scm eclasses set incorrect permissions on DISTDIR (CVE-2008-3797)
Status: RESOLVED OBSOLETE
Alias: CVE-2008-3797
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All All
: High critical (vote)
Assignee: Gentoo Security
URL:
Whiteboard: B1 [ebuild]
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-05 16:09 UTC by Fernando J. Pereda (RETIRED)
Modified: 2016-07-13 19:14 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to check for world-writable directory (vcs-eclasses.patch,2.13 KB, patch)
2008-10-06 06:49 UTC, Ulrich Müller
no flags Details | Diff
Patch to check for world-writable directory (vcs-eclasses.patch,2.13 KB, patch)
2008-10-06 07:49 UTC, Ulrich Müller
no flags Details | Diff
Patch to check for world-writable directory, including bzr.eclass (vcs-eclasses.patch,2.84 KB, patch)
2008-10-25 14:49 UTC, Ulrich Müller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fernando J. Pereda (RETIRED) gentoo-dev 2008-06-05 16:09:33 UTC
While converting git.eclass to git.exlib for exherbo, zlin discovered that subversion.eclass, mercurial.eclass and git.eclass have been setting o+rw permissions on DISTDIR/{svn,git}-src for a long time. The bug started in subversion.eclass and slipped into git.eclass when we converted it.

subversion: Bug entered in revision 1.5. Gone in r1.33.
git: Entered in revision 1.1. Gone in 1.10.
mercurial: Entered in revision 1.1. Gone: See bug #151063

I checked darcs, tla and cvs. They all seem ok.

This opens a wide range of attacks. People shoudn't trust anything beneath the DISTDIR/*-src directories created by those eclasses.

- ferdy
Comment 1 Matt Fleming (RETIRED) gentoo-dev 2008-06-06 15:57:14 UTC
GLSA filed.
Comment 2 Robert Buchholz (RETIRED) gentoo-dev 2008-06-06 16:49:07 UTC
As for a GLSA, I would have expected there are no stable packages affected by this. Unfortunately, they exist, which is really bad. Only for SVN:
=sci-chemistry/pymol/pymol-0.99_rc10

And a lot of MythTV is checked out from SVN, I did not yet check all of them.
media-plugins/mytharchive/mytharchive-0.20.2_p14807
media-plugins/mytharchive/mytharchive-0.20.2_p14877
media-plugins/mythweather/mythweather-0.20.2_p14282
media-plugins/mythweather/mythweather-0.21_p16468
media-plugins/mythweather/mythweather-0.21_p17105
media-plugins/mythbrowser/mythbrowser-0.20.2_p14807
media-plugins/mythbrowser/mythbrowser-0.20.2_p14282
media-plugins/mythdvd/mythdvd-0.20.2_p14282
media-plugins/mythmovies/mythmovies-0.21_beta16366
media-plugins/mythmovies/mythmovies-0.21_p16468
media-plugins/mythcontrols/mythcontrols-0.20.2_p14282
media-plugins/mythmusic/mythmusic-0.20.2_p14282
media-plugins/mythmusic/mythmusic-0.21_p16468
media-plugins/mythmusic/mythmusic-0.21_p17015
media-plugins/mythphone/mythphone-0.20.2_p14282
media-plugins/mythphone/mythphone-0.21_p16468
media-plugins/mythphone/mythphone-0.21_p17105
media-plugins/mythvideo/mythvideo-0.20.2_p14684
media-plugins/mythvideo/mythvideo-0.20.2_p15087
media-plugins/mythgallery/mythgallery-0.20.2_p14282
media-plugins/mythflix/mythflix-0.20.2_p14282
media-plugins/mythflix/mythflix-0.20.2_p15488
media-plugins/mythgame/mythgame-0.20.2_p14282
media-plugins/mythnews/mythnews-0.20.2_p14282
media-plugins/mythnews/mythnews-0.21_p16468
media-plugins/mythnews/mythnews-0.21_p17105
media-tv/mythtv/mythtv-0.20.2_p14972
media-tv/mythtv/mythtv-0.20.2_p15634
www-apps/mythweb/mythweb-0.20.2_p14282
www-apps/mythweb/mythweb-0.20.2_p15488
www-apps/mythweb/mythweb-0.21_p16468
www-apps/mythweb/mythweb-0.21_p16809
x11-themes/mythtv-themes/mythtv-themes-0.20.2_p14301

We have to revbump every single ebuild* that might be affected by this before we even think about sending a GLSA.
* or check the ebuild was created after the eclass was bumped.
Comment 3 Fernando J. Pereda (RETIRED) gentoo-dev 2008-06-07 10:16:45 UTC
Well, since that might take time. Why don't you just advise people to reinstall those packages after having:

a) deleted their svn-src directories
b) run emerge --sync

?

Serves the same purpose and it is kind of faster (and this should be announced fairly soon IMHO).

- ferdy
Comment 4 Robert Buchholz (RETIRED) gentoo-dev 2008-06-07 17:39:58 UTC
(In reply to comment #3)
> Well, since that might take time. Why don't you just advise people to reinstall
> those packages after having:

If *we* don't know which packages, how should we expect users to know which "those" are to reinstall? 
Comment 5 Fernando J. Pereda (RETIRED) gentoo-dev 2008-06-07 22:18:50 UTC
We do. Any package installed that uses git.eclass, subversion.eclass or mercurial.eclass. Those are quite easy to find with a one-liner script.

Checking dates is pointless. The {svn,git,mercurial}-src directories are created the first time any package uses the eclass.

- ferdy
Comment 6 Robert Buchholz (RETIRED) gentoo-dev 2008-06-08 22:15:19 UTC
(In reply to comment #5)
> We do. Any package installed that uses git.eclass, subversion.eclass or
> mercurial.eclass. Those are quite easy to find with a one-liner script.

My research has generated a lot of false positives, because inheritance can be conditional, or the _src_unpack() might not be called. Once we have a list of all ebuilds that were vulnerable, filtering out those that were stable should be fairly easy. If you want to speed up the process, please help by generating the list as I already did for subversion.eclass.

We should also need go back and look for ebuilds that do not exist anymore. Furthermore, all of these ebuilds have to be revbumped, because telling people to reemerge a package does not fit into the GLSA format, and everyone using tools like glsa-check will miss out the updates.

As a step to increase overall security, and for those working on old distdirs, and not reading the GLSA description about deleting those directories: Shouldn't Portage bail out when it is asked to work on o+w directories? (Adding Zac and Marius)
Comment 7 Zac Medico gentoo-dev 2008-06-09 03:21:00 UTC
(In reply to comment #6)
> Shouldn't Portage bail out when it is asked to work on o+w directories? (Adding
> Zac and Marius)

If there's some way to extract the path of the directory from the package metadata (like SRC_URI) then we can do that. Without that, would we have check recursive contents of ${DISTDIR}? Doing anything recursive on ${DISTDIR} can be prohibitively expensive, particularly when it contains large source trees. It would have to be a one time adjustment and after that you'd just have to assume that the permissions are ok. An alternative would be to make the top level ${DISTDIR} o-rx so that attackers can never access the subdirectories.
Comment 8 Fernando J. Pereda (RETIRED) gentoo-dev 2008-06-09 07:22:00 UTC
(In reply to comment #6)
> We should also need go back and look for ebuilds that do not exist anymore.
> Furthermore, all of these ebuilds have to be revbumped, because telling people
> to reemerge a package does not fit into the GLSA format, and everyone using
> tools like glsa-check will miss out the updates.

How do you revbump ebuilds that don't exist?

> As a step to increase overall security, and for those working on old distdirs,
> and not reading the GLSA description about deleting those directories:
> Shouldn't Portage bail out when it is asked to work on o+w directories? (Adding
> Zac and Marius)

It'd be even easier to add that hack to the eclasses, however, that adds 0 security to the matter because people will do 'chmod o-rwx foo' and an attacker might have modified foo already.

- ferdy
Comment 9 Fernando J. Pereda (RETIRED) gentoo-dev 2008-06-23 11:33:48 UTC
Is there anything that can be done to speed this up?

- ferdy
Comment 10 Robert Buchholz (RETIRED) gentoo-dev 2008-07-06 22:21:26 UTC
Yes. The best case we need is a list of all vulnerable ebuilds that could still be installed on user's systems. That is ebuilds
A) using the eclasses during a vulnerable timeframe
B) have not been p.masked at that time and are not masked / removed now
C) have not been superseded by newer ebuilds

Then we need to:
1) Figure out which were stable / testing
2) Bump each of those ebuilds
3) Get those that were stable back to stable.

Security is considering this to be a serious issue, but it only affects a minor set of packages. If you could assist in compiling such a list, that would be awesome.
Comment 11 Fernando J. Pereda (RETIRED) gentoo-dev 2008-08-14 21:42:28 UTC
(In reply to comment #10)
> Security is considering this to be a serious issue, but it only affects a minor
> set of packages. If you could assist in compiling such a list, that would be
> awesome.

Compiling such a list is unfeasible.

I suggest just publicly disclosing this bug, keeping it secret is just useless.

- ferdy
Comment 12 Raphael Marichez (Falco) (RETIRED) gentoo-dev 2008-08-27 17:23:22 UTC
Well...

- I agree with making public this issue. Indeed, finding insecure directories/files is one of the first things a local hacker will do if he is looking for root access. Restricting this information does not prevent a malicious user from exploiting the flaw.

- I would tend to minimize the seriousness of that issue. A good unix administrator, running a multi-user box, should already apply basic security practices. Regularly looking for world-writable directories or files and evaluating their impact (in crontabs, in /etc/init.d, ...) is one of the basic security practices if you're concerned about security of your multi-user box. I'm sure there are many other ways to root a box if you already have a local unix account, some time, and some skill. Still, this should be fixed, for sure.

About the fix, that plan sounds good to me:

- The new eclass will die when finding a vulnerable directory, asking the user to manually rm -rf it (or whatever). 
- No ebuild will be revbumped. The GLSA will have no ebuild associated. I'm not sure this will work, but this should.
- The GLSA will advise to delete the eclass cache, run emerge --sync, and manually check and fix the $DISTDIR/{svn,cvs,git}-src/ directories content (not only permissions), possibly simply deleting it.



Comment 13 Robert Buchholz (RETIRED) gentoo-dev 2008-08-28 00:40:23 UTC
CVE-2008-3797 has been reserved for this issue.
Comment 14 Robert Buchholz (RETIRED) gentoo-dev 2008-09-04 19:31:53 UTC
ferdy, any update on the patches?
Comment 15 Robert Buchholz (RETIRED) gentoo-dev 2008-10-05 18:37:22 UTC
I'm attaching ulm in light of the proposed bzr.eclass: Let's not reintroduce this issue again. Before moving the class into the tree, can we get a patch ready to bail out in case of improper permissions on DISTDIR?
Comment 16 Ulrich Müller gentoo-dev 2008-10-05 19:27:32 UTC
As discussed with rbu on irc.
I think something like the following should do the job:
    [ $(find "${DIR}" -maxdepth 0 -type d -perm -o+w) ] \
        && die "${DIR} is world-writable, please remove it"
Comment 17 Ulrich Müller gentoo-dev 2008-10-06 06:49:22 UTC
Created attachment 167417 [details, diff]
Patch to check for world-writable directory

Here is a patch for {git,mercurial,subversion}.eclass. I've tested it with subversion.eclass, but the logic is identical for all three eclasses.

For bzr.eclass I'll commit a patched version directly.
Comment 18 Ulrich Müller gentoo-dev 2008-10-06 07:49:39 UTC
Created attachment 167418 [details, diff]
Patch to check for world-writable directory

Take 2, adding some quotes.
Comment 19 Fernando J. Pereda (RETIRED) gentoo-dev 2008-10-06 09:08:07 UTC
That die message should point people to a page telling them to check their systems since they might have been compromised. That page can be the security advisory, for instance. Otherwise the check is not helping at all.

- ferdy

Comment 20 Ulrich Müller gentoo-dev 2008-10-06 10:34:37 UTC
(In reply to comment #19)
> That die message should point people to a page telling them to check their
> systems since they might have been compromised. That page can be the security
> advisory, for instance.

But that GLSA number or URL is not known yet, or could one be reserved? Or we could add the GLSA reference to the error message later.
Comment 21 Fernando J. Pereda (RETIRED) gentoo-dev 2008-10-06 11:05:05 UTC
Ideally, the patch would be committed the minute after the GLSA is released.

- ferdy

Comment 22 Robert Buchholz (RETIRED) gentoo-dev 2008-10-09 17:32:40 UTC
We usually discuss eclass changes on -dev. Halcy0n and dberkholz, can you review the diff and leave a comment please?
Comment 23 Ulrich Müller gentoo-dev 2008-10-12 20:23:47 UTC
I must admit that I did a stupid thing, namely I've accidentally committed a fixed bzr.eclass to the Emacs overlay (I wanted to commit another eclass but did a "svn ci" instead of "svn ci <filename>" in the directory).

I've immediately (10 minutes later) asked robbat2 to remove the offending changeset r1171, however, two users already had it at this point.
Comment 24 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2008-10-12 21:03:59 UTC
I nulled out r1171 in the emacs overlay that had the private changes, but left the revisions existing as empty. It shouldn't break user systems, but the fact remains that two systems have copies of r1171. Overlays SVN/apache was turned off while I did the removal to prevent more.

first user is 80.72.196.194, using a normal svn checkout.

The second looks like an aggregator, so I think we still need to consider this exposed:
34.195.138 - - [12/Oct/2008:20:09:03 +0000] "GET http://overlays.gentoo.org/proj/emacs/changeset/1171 HTTP/1.1" 200 12323 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1; aggregator:Tailrank (Spinn3r 2.3); http://spinn3r.com/robot) Gecko/20021130"

I don't see why this is confidential anyway, when anybody reading the CVS changes for the eclasses can find where it was previously fixed. I'm also pretty sure zlin wasn't the first to find it, I had a discussion with somebody before about it, 6-9 months ago. Might have been ferringb, in person, not 100% sure.
Comment 25 Ulrich Müller gentoo-dev 2008-10-22 06:01:39 UTC
Another two weeks have passed, without any visible progress.

If there are no substantial objections, I'm going to commit bzr.eclass (_without_ the check for an existing world-writable dir) end of this week.

AFAICS, this will not introduce any new problems, since the current version of bzr.eclass will not create the directory world-writable. And overlay users may already be affected by the issue, so this will not change.
Comment 26 Ulrich Müller gentoo-dev 2008-10-25 14:49:03 UTC
Created attachment 169812 [details, diff]
Patch to check for world-writable directory, including bzr.eclass

(In reply to comment #25)
> If there are no substantial objections, I'm going to commit bzr.eclass
> (_without_ the check for an existing world-writable dir) end of this week.

Done. An updated patch including bzr.eclass is attached.
Comment 27 Mark Loeser (RETIRED) gentoo-dev 2009-01-03 16:47:03 UTC
Sorry, I missed that I was even CC'd on this.  I don't see a problem with Ulrich's patch but this seems to me like something the package manager should enforce/check for.  Just my 2 cents :)  For now, whatever is the quickest and most efficient way to resolve this should be the way we go though.
Comment 28 Zac Medico gentoo-dev 2009-01-03 20:42:11 UTC
As explained in comment #7, it's too expensive for the package manager to check recursive permissions on all subdirectories that might exist inside $DISTDIR.
Comment 29 Ulrich Müller gentoo-dev 2009-02-12 16:51:23 UTC
I just want to bring to your attention that the inofficial "bzr-gentoo-overlay" again has a version of bzr.eclass that reintroduces the original issue: <http://bazaar.launchpad.net/~malept/bzr-gentoo-overlay/overlay-main/annotate>/head%3A/eclass/bzr-r9999.eclass>

And it was already suggested that we replace the version in Portage by it. Which cannot be done unless this bug gets fixed.
Comment 30 Ulrich Müller gentoo-dev 2009-02-12 16:53:14 UTC
Oops, broken URL. Here is the correct one: <http://bazaar.launchpad.net/~malept/bzr-gentoo-overlay/overlay-main/annotate/head%3A/eclass/bzr-r9999.eclass>
Comment 31 Ulrich Müller gentoo-dev 2016-07-06 21:15:02 UTC
Looks like there is no progress since 8 years.

I suggest to make this bug public and close the issue as obsolete. git.eclass is gone since a long time, as well as all the ebuilds listed in comment #2. The other three eclasses have been fixed years ago.
Comment 32 Aaron Bauman (RETIRED) gentoo-dev 2016-07-13 19:04:21 UTC
(In reply to Ulrich Müller from comment #31)
> Looks like there is no progress since 8 years.
> 
> I suggest to make this bug public and close the issue as obsolete.
> git.eclass is gone since a long time, as well as all the ebuilds listed in
> comment #2. The other three eclasses have been fixed years ago.

Concur.  Any other concerns from @security?