Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 811105 - fcaps.eclass: fcaps should not default the non-caps mode to suid
Summary: fcaps.eclass: fcaps should not default the non-caps mode to suid
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-30 11:38 UTC by tastytea
Modified: 2021-08-30 15:16 UTC (History)
1 user (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 tastytea 2021-08-30 11:38:13 UTC
When I call fcaps_pkg_postinst from pkg_postinst, the SETUID-bit is set with USE="-filecaps". It only happens when I call fcaps_pkg_postinst explicitly. When my ebuild does not override pkg_postinst, the bit is not set.

Reproducible: Always

Steps to Reproduce:
1. USE="-filecaps" emerge '=www-apps/gitea-1.14.6'
2. ls -l /usr/bin/gitea
Comment 1 Mike Gilbert gentoo-dev 2021-08-30 13:19:19 UTC
(In reply to tastytea from comment #0)
> When I call fcaps_pkg_postinst from pkg_postinst, the SETUID-bit is set with
> USE="-filecaps".

That is the intended behavior.

> It only happens when I call fcaps_pkg_postinst explicitly.
> When my ebuild does not override pkg_postinst, the bit is not set.

www-apps/gitea inherits fcaps and go-module. Both of these eclasses export the pkg_postinst function. The last eclass to export the function wins.
Comment 2 tastytea 2021-08-30 13:30:17 UTC
(In reply to Mike Gilbert from comment #1)
> (In reply to tastytea from comment #0)
> > When I call fcaps_pkg_postinst from pkg_postinst, the SETUID-bit is set with
> > USE="-filecaps".
> 
> That is the intended behavior.

Even so it is unexpected. Why would the eclass do anything if the functionality it provides is turned off via use-flag?

I don't think many users are aware that they are getting suid binaries if they turn the flag off.
Comment 3 Ionen Wolkens gentoo-dev 2021-08-30 14:44:33 UTC
(In reply to tastytea from comment #2)
> Even so it is unexpected. Why would the eclass do anything if the
> functionality it provides is turned off via use-flag?
Well, behavior is documented[1] so I wouldn't call it unexpected. Can debate that the behavior is not great, but please read docs of eclasses you use.

[1] https://devmanual.gentoo.org/eclass-reference/fcaps.eclass/index.html
Comment 4 Mike Gilbert gentoo-dev 2021-08-30 14:48:46 UTC
This has been the documented behavior of the eclass for many years.

fcaps is typically used for binaries that would normally be installed suid on a traditional UNIX system. On Linux, file-based capabilities allow us to reduce the privilege level from full superuser access.

gitea is using fcaps.eclass for a somewhat different purpose: it is giving additional permissions to the gitea binary instead of taking them away. You would not normally install a web application with the suid bit set and a root owner.

If you don't want to default the non-caps mode to 4711, set FILECAPS like so:

FILECAPS=(
    -m 0755 cap_net_bind_service+ep usr/bin/gitea
)
Comment 5 tastytea 2021-08-30 15:01:36 UTC
(In reply to Mike Gilbert from comment #4)
> This has been the documented behavior of the eclass for many years.

It is documented for the function fcaps. It was not clear to me (and apparently the original author of that ebuild) that fcaps_pkg_postinst calls fcaps with USE="-filecaps".

> fcaps is typically used for binaries that would normally be installed suid
> on a traditional UNIX system. On Linux, file-based capabilities allow us to
> reduce the privilege level from full superuser access.

From a users perspective, it is confusing that a binary will have more privileges when I tell portage to not add extra privileges. Especially since we have a suid useflag.
Comment 6 Larry the Git Cow gentoo-dev 2021-08-30 15:07:48 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e798e0e9c7a13b2004cb492901a8e2873388cbe9

commit e798e0e9c7a13b2004cb492901a8e2873388cbe9
Author:     Mike Gilbert <floppym@gentoo.org>
AuthorDate: 2021-08-30 15:05:55 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2021-08-30 15:05:55 +0000

    www-apps/gitea: set non-caps mode to 0755
    
    Running a web application as root is insane.
    
    Bug: https://bugs.gentoo.org/811105
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>

 www-apps/gitea/gitea-1.14.6.ebuild | 2 +-
 www-apps/gitea/gitea-9999.ebuild   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Comment 7 Mike Gilbert gentoo-dev 2021-08-30 15:16:55 UTC
I suppose it might be safer to have the eclass default to a non-suid mode, and override that in ebuilds that require suid fallback behavior for USE=-filecaps.