Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 531788 - Stage3 includes packages relying on caps but doesn't include caps for them
Summary: Stage3 includes packages relying on caps but doesn't include caps for them
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Release Media
Classification: Unclassified
Component: Stages (show other bugs)
Hardware: All Linux
: Normal major (vote)
Assignee: Gentoo Release Team
URL:
Whiteboard:
Keywords: InVCS
: 540842 (view as bug list)
Depends on: 608058
Blocks:
  Show dependency tree
 
Reported: 2014-12-06 10:39 UTC by Michał Górny
Modified: 2022-04-17 23:49 UTC (History)
7 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-12-06 10:39:59 UTC
Long story short:

# tar -xf stage3-amd64-20141204.tar.bz2 ./bin/ping
# ls -lh bin/ping
-rwx--x--x 1 root root 39K Dec  4 04:21 bin/ping
# getcap bin/ping
[empty]

So the stage includes net-misc/iputils[filecaps] which means files are built for capabilities use and without setuid. However, the tarball doesn't include their caps so you get ping both without caps and without setuid.
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-12-06 10:50:36 UTC
And this is because fcaps.eclass has IUSE=+filecaps.
Comment 2 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2014-12-06 15:02:48 UTC
I've had ping fail for users other than root because of caps recently, which might have been caused by this.
I'm wondering if we need to update the tar call to preserve caps.
Comment 3 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2014-12-06 16:22:49 UTC
I believe we need something along the following applied to catalyst:

diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py
index 8112ed0..0e9faac 100644
--- a/modules/catalyst_support.py
+++ b/modules/catalyst_support.py
@@ -108,9 +108,9 @@ contents_map={
 	# 'find' is disabled because it requires the source path, which is not
 	# always available
 	#"find"		:[calc_contents,"find %(path)s"],
-	"tar-tv":[calc_contents,"tar tvf %(file)s"],
-	"tar-tvz":[calc_contents,"tar tvzf %(file)s"],
-	"tar-tvj":[calc_contents,"tar -I lbzip2 -tvf %(file)s"],
+	"tar-tv":[calc_contents,"tar --xattrs --acls tvf %(file)s"],
+	"tar-tvz":[calc_contents,"tar --xattrs --acls tvzf %(file)s"],
+	"tar-tvj":[calc_contents,"tar --xattrs --acls -I lbzip2 -tvf %(file)s"],
 	"isoinfo-l":[calc_contents,"isoinfo -l -i %(file)s"],
 	# isoinfo-f should be a last resort only
 	"isoinfo-f":[calc_contents,"isoinfo -f -i %(file)s"],

I suspect we don't need --acls at this point, but I don't think it hurts and it could help in the future.
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-12-06 19:31:23 UTC
I think it would be actually safer to build with USE=-filecaps for now. This way the stage will work fine for people without capability/xattr support. People can rebuild iputils afterwards getting caps tested properly. Otherwise, there's still risk that the filecaps will be lost at unpack stage and effectively people will have 'broken' ping.
Comment 5 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2014-12-06 20:00:25 UTC
(In reply to Michał Górny from comment #4)
> I think it would be actually safer to build with USE=-filecaps for now. This
> way the stage will work fine for people without capability/xattr support.
> People can rebuild iputils afterwards getting caps tested properly.
> Otherwise, there's still risk that the filecaps will be lost at unpack stage
> and effectively people will have 'broken' ping.

We (releng) don't control the use flags, so unless you can convince maintainers to drop the IUSE defaults, we'll have to fix catalyst and update the docs.
I'm already testing a patch to catalyst (committed to the 2.X branch), that should fix catalyst.
Comment 6 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-12-06 20:07:14 UTC
Well, that's a big problem since as I see it, the proper solution would be to use USE=-filecaps for stage build but default to USE=filecaps afterwards, since the flag depends on runtime capabilities of target filesystem. But I don't care that much.
Comment 7 Jason Zaman gentoo-dev 2014-12-07 10:31:55 UTC
I'd like to note that the Hardened project uses Xattrs to save the PaX marks sometimes (it currently defaults to writing them in the elf header but will change to xattrs by default) so building with USE=-filecaps does not help whereas adding xattr's to hte tarballs fixes any issues the hardened project would have too.
Comment 8 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2014-12-17 22:43:01 UTC
(In reply to Michał Górny from comment #6)
> Well, that's a big problem since as I see it, the proper solution would be
> to use USE=-filecaps for stage build but default to USE=filecaps afterwards,
> since the flag depends on runtime capabilities of target filesystem. But I
> don't care that much.

As this has proven to be harder to fix than I expected, I'm going to disable USE="filecaps" for the default stages.
We're also going to continue testing with catalyst to fix it there.
Comment 9 Anthony Basile gentoo-dev 2015-01-17 11:55:05 UTC
See also bug #536762 about tar --acls.
Comment 10 Ben Kohler gentoo-dev 2015-02-20 19:18:33 UTC
*** Bug 540842 has been marked as a duplicate of this bug. ***
Comment 11 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2015-02-22 17:12:11 UTC
commit b6ca4792761dde68e20a46fc259e8b9e88717d18
Author: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>
Date:   Sun Feb 22 16:51:41 2015 +0000

    Disable caps/filecaps for iputils - one more fix for bug 531788.
    
    Signed-off-by: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>


This together with some updates to get stages building again, should fix this issue as soon as we have new stages.
Comment 12 Mike Gilbert gentoo-dev 2015-02-22 17:21:31 UTC
(In reply to Jorge Manuel B. S. Vicetto from comment #11)
> commit b6ca4792761dde68e20a46fc259e8b9e88717d18
> Author: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>
> Date:   Sun Feb 22 16:51:41 2015 +0000
> 
>     Disable caps/filecaps for iputils - one more fix for bug 531788.

I do not think it is necessary to explicitly disable "caps" -- this just links agains libcap for caps manipulation at runtime. Stage tarball packing/unpacking should have no effect on this.

All we care about here is "filecaps".
Comment 13 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2015-06-15 02:52:43 UTC
This change has added a few more issues we need to fix (providing non-empty /etc/portage/package* dirs), but the bug issues should be fixed now, so I'm going to close this bug.
Comment 14 Ben Kohler gentoo-dev 2017-10-12 17:50:00 UTC
I'd like to reopen this to track this bug to proper completion.  The caps flag doesn't need to be turned off, and once we are building stages with catalyst-3 the -filecaps workaround will no longer be needed either.
Comment 15 Xiami 2017-11-22 08:20:21 UTC
I have just tested tar's behavior with xattrs (=app-arch/tar-1.29-r1)

TL;DR

To extract filecaps info from a tarball. Run tar with --xattrs-include='*' .

tar supports --xattrs-include since 1.27 (year 2013) according to its NEWS file.

------

On creating archives:
    without --xattrs: Archive none of file's xattrs
    with --xattrs: Archive all file's xattrs
On extracting archives:
    without --xattrs: Extract none of file's xattrs
    with --xattrs: Extract file's xattrs under user namespace (aka user.*)
    with --xattrs-include='*': Extract all file's xattrs archived

Notes:
1. pax marks are under user namespace. So --xattrs fulfills hardened profile's need.
   Dump of my /usr/bin/python3.4 xattrs shows user.pax.flags="E"
2. tar(1) says --xattrs-include accepts a value of POSIX regexp. Actually it accepts globbing patterns. :'(
3. when --xattrs-include present, --xattrs seems redundant.

Source can be found at src/xattrs.c:xattrs_kw_included()

------

Test script #1:

(Preserving full $PS1 to avoid confusion with getfattr's output)
localhost tmp # tar -xf test.tar --xattrs
localhost tmp # getfattr -dm. test
# file: test
user.xiami="user"

localhost tmp # tar -xf test.tar --xattrs-include='*'
localhost tmp # getfattr -dm. test
# file: test
security.xiami="security"
trusted.xiami="trusted"
user.xiami="user"


Test script #2:

# tar -xf ping.tar --xattrs
# getcap ping
(empty)
# tar -xf ping.tar --xattrs-include 'security.*'
# getcap ping
ping = cap_net_raw+ep
Comment 16 Brian Dolbec (RETIRED) gentoo-dev 2017-11-22 17:35:11 UTC
catalyst3 uses pyDeComp, a lib I created to handle all different kinds of tarballs while maintaining a simple common python interface.

see the xattrs options here:

https://github.com/dol-sen/pyDeComp/blob/master/DeComp/definitions.py#L70

If you recommend setting them differently, than please make a pull request, and I'll make another release.
Comment 17 Xiami 2017-11-30 09:02:01 UTC
Emmm.. I mean we can store file capabilities into stage3 tarball and guide users to extract them correctly by adding --xattrs-include='*' to Handbook/Installation.
Comment 18 Ben Kohler gentoo-dev 2017-11-30 12:25:23 UTC
We can/should get the proper xattrs-include option added to the handbook asap.  As soon as we get a catalyst-3 on the releng autobuild setup, the xattrs/caps will make it to the tarball, and things will work.
Comment 19 Brian Dolbec (RETIRED) gentoo-dev 2017-12-03 14:51:53 UTC
Catalyst-3.0.0 and pydecomp-0.2 have been released.  These have all the required code to include xattrs.
Comment 20 Ben Kohler gentoo-dev 2018-01-11 15:26:45 UTC
A quick update-- we have the right handbook command, we have catalyst support.  All that's left to do is remove the package.use entry/entries disabling this.
Comment 21 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-01-11 15:29:41 UTC
...except it is infinitely silly to have stages that are broken on systems that do not have capabilities enabled.
Comment 22 Ben Kohler gentoo-dev 2018-01-11 15:33:00 UTC
That's a valid point, but then isn't it infinitely silly to have profile & package defaults turning this on?
Comment 23 Ben Kohler gentoo-dev 2018-01-11 15:36:25 UTC
I should be a bit more constructive.  If we're happy with the status quo where stage3 is shipped with packages having filecaps OFF, but with a pending USE change that will turn them back on @ next world upgrade, I'm ok with that and we can close this bug.

I assumed we wanted to get filecaps out there on the stage3 itself.
Comment 24 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-01-11 15:38:47 UTC
I don't have a strong opinion on what the default should be. However, the difference is that USE=filecaps involves a fallback if the system doesn't support them whereas stage3 unpacking has no clear fallback and involves straightaway broken system.
Comment 25 Ben Kohler gentoo-dev 2018-01-11 15:42:24 UTC
That itself might be enough reason to maintain the -filecaps setting longterm for stage3 builds, even globally like bindist, and not consider it to be a temporary workaround.

That is, to let the filecaps introduction happen later where the ebuild/eclass/PM logic can make sure it's handled properly.
Comment 26 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2018-01-11 22:37:26 UTC
(In reply to Ben Kohler from comment #23)
> I should be a bit more constructive.  If we're happy with the status quo
> where stage3 is shipped with packages having filecaps OFF, but with a
> pending USE change that will turn them back on @ next world upgrade, I'm ok
> with that and we can close this bug.
> 
> I assumed we wanted to get filecaps out there on the stage3 itself.

I think until caps get more "mainstream" support from tar and friends, we should keep things as they are.
Comment 27 Andreas K. Hüttel archtester gentoo-dev 2022-04-17 23:49:53 UTC
(In reply to Ben Kohler from comment #23)
> If we're happy with the status quo
> where stage3 is shipped with packages having filecaps OFF, but with a
> pending USE change that will turn them back on @ next world upgrade, I'm ok
> with that and we can close this bug.

And that's how it is for ages now. :)