Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 182428

Summary: sys-apps/portage: quickpkg leaks information
Product: Gentoo Linux Reporter: Finn Thain <fthain>
Component: [OLD] Core systemAssignee: Portage team <dev-portage>
Status: RESOLVED FIXED    
Severity: minor CC: security
Priority: High    
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=890823
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 181949    
Attachments: set default umask to 0077 and allow QUICKPKG_DEFAULT_OPTS to override

Description Finn Thain 2007-06-18 07:09:13 UTC
tgbz packages are created group and world readable because they are created with the wrong umask (should be 600). "quickpkg baselayout" (run as root by necessity) makes /etc/shadow available to everyone, for example.

Reproducible: Always
Comment 1 Raphael Marichez (Falco) (RETIRED) gentoo-dev 2007-06-18 08:46:05 UTC
I agree leaking /etc/shadow is bad. But i can't reproduce what you're claiming with baselayout.

[sleipnir:/usr/portage/packages/All] tar tvjf baselayout-1.12.9-r2.tbz2|grep '\./etc/[^/]\+$'
-rw-r--r-- root/root        34 2007-06-18 10:34 ./etc/gentoo-release
-rw-r----- root/root      1494 2007-06-18 10:34 ./etc/sysctl.conf
-rw-r--r-- root/root       108 2007-06-18 10:34 ./etc/shells
-rw-r--r-- root/root     35842 2007-06-18 10:34 ./etc/services
-rw-r--r-- root/root      1641 2007-06-18 10:34 ./etc/rc.conf
-rw-r--r-- root/root      1623 2007-06-18 10:34 ./etc/protocols
-rw-r--r-- root/root      2141 2007-06-18 10:34 ./etc/profile
-rw-r--r-- root/root       196 2007-06-18 10:34 ./etc/networks
-rw-r--r-- root/root       701 2007-06-18 10:34 ./etc/issue.logo
-rw-r--r-- root/root        30 2007-06-18 10:34 ./etc/issue
-rw-r--r-- root/root      1658 2007-06-18 10:34 ./etc/inputrc
-rw-r--r-- root/root       399 2007-06-18 10:34 ./etc/filesystems

bzip2: (stdin): trailing garbage after EOF ignored



BTW 600 may break some rsync scripts which take advantage of the binary packages feature, 640 portage:portage or root:portage should be preferred.


Have you found a real information leakage? If not, i would close it as Invalid. Oh, and don't play with the severity with too much coffee.
Comment 2 Zac Medico gentoo-dev 2007-06-18 09:43:24 UTC
The umask should not matter since quickpkg is supposed to put the files directly into the tar archive with the existing permissions.  Permissions should not change  in any way.
Comment 3 Finn Thain 2007-06-18 10:43:00 UTC
Raphael: I can't reproduce it either. I mentioned shadow because I had a tbz2 that contained it (or so I thought, but I removed it and now I can't double check). In the listing you posted, /etc/sysctl.conf is leaked instead. Of course, the nature of the leak will depend on which package you try it on.

640 root:portage isn't a safe default. If 600 "might break" scripts, then break them. How can you confidently presume that the portage group is empty? Perhaps you could change quickpkg to allow it to set the group to portage and mode bits to 640 if run as root and a new option is passed.

As to severity, running quickpkg as root really is a major feature if you maintain production servers. It provides a back-out plan for upgrades, and it has saved me before (and yes, I use test boxes too). But I don't care too much whether others appreciate quickpkg or not. As a workaround, I changed the perms on /usr/portage/packages to 700, but I suspect that there are temporary files involved that aren't protected by that workaround.

Zac: what existing permissions? The problem relates to the new tbz2 file, not the source files. As to umask, tightening the umask may not fix the bug unless it covers temporary files are created by quickpkg or tar as well.

PS. umask would be 077, so the mode bits go to 600. The bug report wasn't clear on that. And no I don't know what "tgbz" is either. Yes, coffee would help...
Comment 4 SpanKY gentoo-dev 2007-06-18 17:01:34 UTC
while you might be able to make an argument about the default perms on the tbz2s, but /etc/shadow is not leaked anywhere regardless

we specifically do not have baselayout record it in CONTENTS so that when a tarball is made, it is not added ... same goes for groups and passwd and ...

/etc/sysctl.conf is hardly a leaky file
Comment 5 Zac Medico gentoo-dev 2007-06-18 18:51:29 UTC
(In reply to comment #3)
> As a workaround, I changed the perms
> on /usr/portage/packages to 700, but I suspect that there are temporary files
> involved that aren't protected by that workaround.

The temporary file is kept inside $PKGDIR, so your workaround completely protects it.

The 022 umask in quickpkg was added for bug #143340 so that users without superuser privileges could do --pretend commands with binary packages.  We can add an environment variable to control that if necessary.  I've never noticed any sensitive information being stored in packages, so the idea of restricting read privileges there never occurred to me.
Comment 6 Zac Medico gentoo-dev 2007-06-18 20:30:10 UTC
Created attachment 122450 [details, diff]
set default umask to 0077 and allow QUICKPKG_DEFAULT_OPTS to override

This patch applies against portage-2.1.3_rc4.
Comment 7 Finn Thain 2007-06-19 03:32:14 UTC
Zac: Thanks for the patch.

Mike: sysctl.conf is a leak.
$ sysctl -a
...
error: permission denied on key 'kernel.cap-bound'
And yes, I used to set kernel.cap-bound in that file (though these days I patch the kernel instead).

Simply grepping the tree for chmod indicates that there are other files installed without world-read perms. Besides which, you can't claim a file isn't leaky without knowing what it is in it. Once quickpkg makes it world readable, _then_ you can look at and tell me I didn't leak anything. ;-)
Comment 8 SpanKY gentoo-dev 2007-06-19 07:31:09 UTC
what i meant is the contents of sysctl.conf are rarely (ever?) an issue if made world readable, unlike the shadow file
Comment 9 Finn Thain 2007-06-19 10:10:45 UTC
That's what I thought you meant. By implication you are also saying that /proc/sys/kernel/cap-bound would be equally secure if it were 644 rather than 600. I can't really argue that point. I presume that there is a reason that the kernel makes it 600 and not 644, but I don't really know for sure.

That debate is off-topic anyway, since the bug isn't confined to baselayout (e.g. net-nds/openldap has to deny read to /etc/openldap/slapd.conf to protect the rootdn password).
Comment 10 SpanKY gentoo-dev 2007-06-19 18:30:47 UTC
it isnt really off topic ... this bug is assigned to the security team which means once the issue is solved in portage, they need to determine whether to issue a glsa

unless there is a true risk here (which i dont think sysctl.conf qualifies for), then there's no need for a glsa

any package that may have passwords in them should not be listed in CONTENTS ... i think i should get this spelled out in our docs

in the meantime, i think you should file a sep bug report against openldap
Comment 11 Finn Thain 2007-06-20 02:28:13 UTC
> unless there is a true risk here (which i dont think sysctl.conf qualifies
> for), then there's no need for a glsa

I don't understand. Why is cap-bounds not sensitive? Upstream seems to think it is.
And even if it is not sensitive, surely there ought to be a glsa against portage anyway?

> any package that may have passwords in them should not be listed in CONTENTS
> ... i think i should get this spelled out in our docs

I don't understand. How is that relevant to this bug (against portage) unless the
criterion is file permissions, rather than file contents (passwords)?

> in the meantime, i think you should file a sep bug report against openldap

Shouldn't I file a bug against baselayout also? Is this bug (against portage) really invalid?

Look, I'm happy to file more bugs, but what are the bugs exactly? Why should I
be asking for more stuff stripped from CONTENTS? I actually _like_ being able to
do "equery belongs /etc/foo"...
Comment 12 SpanKY gentoo-dev 2007-06-20 04:37:11 UTC
because users will blindly distribute packages without realizing they've packaged up sensitive information

as i mentioned, baselayout is not affected because the sensitive files are not listed in CONTENTS
Comment 13 SpanKY gentoo-dev 2007-06-20 21:45:03 UTC
i think the proposed patch here for quickpkg plus the comments on gentoo-dev wrt CONFIG_PROTECT+quickpkg (which i'll handle) are the way to go
Comment 14 Finn Thain 2007-06-21 03:49:07 UTC
I think so, too.
Comment 15 Marius Mauch (RETIRED) gentoo-dev 2007-06-21 10:50:59 UTC
(In reply to comment #13)
> i think the proposed patch here for quickpkg plus the comments on gentoo-dev
> wrt CONFIG_PROTECT+quickpkg (which i'll handle) are the way to go

Hmm, how about checking the md5sum and only skip the files if they were modified? Or are there any potential leaks with vanilla config files?
Comment 16 Zac Medico gentoo-dev 2007-06-23 05:37:21 UTC
(In reply to comment #15)
> Hmm, how about checking the md5sum and only skip the files if they were
> modified? Or are there any potential leaks with vanilla config files?

If the quicpkg with --include-config=y is used to create a package and that package is then merged onto a system, the merge process will recalculate the md5sum for every file.  After that, even files containing sensitive data could have their md5 recorded in the contents.

In portage-2.1.3_rc5, quickpkg supports --include-config and --include-unmodified-config options.  Both options are disabled by default.  Set QUICKPKG_DEFAULT_OPTS in make.conf if you want to change the default options.
Comment 17 Tavis Ormandy (RETIRED) gentoo-dev 2007-07-11 09:37:27 UTC
Re-assigning to portage-team
Comment 18 Marius Mauch (RETIRED) gentoo-dev 2007-07-11 12:16:09 UTC
(In reply to comment #17)
> Re-assigning to portage-team

So you don't consider this to be a security issue?