Bug 646472 - Replace SETUID in spec file with the correct file capabilities.
Summary: Replace SETUID in spec file with the correct file capabilities.
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: httpd
Version: rawhide
Hardware: Unspecified
OS: Unspecified
low
medium
Target Milestone: ---
Assignee: Joe Orton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: removesetuid
TreeView+ depends on / blocked
 
Reported: 2010-10-25 13:23 UTC by Daniel Walsh
Modified: 2011-04-05 13:10 UTC (History)
6 users (show)

Fixed In Version:
Clone Of: 646443
Environment:
Last Closed: 2011-04-05 13:03:14 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Daniel Walsh 2010-10-25 13:23:09 UTC
+++ This bug was initially created as a clone of Bug #646443 +++

Description of problem:

Please remove setuid setup of files in your package with file capabilities.

This is to satisfy the F15 feature.

https://fedoraproject.org/wiki/Features/RemoveSETUID

An example of how this was done for X is.


%if 0%{?fedora} < 15
%define Xorgperms %attr(4711, root, root)
%else
%define Xorgperms %attr(0711,root,root) %caps(cap_sys_admin,cap_sys_rawio,cap_dac_override=pe)
%endif

Comment 1 Joe Orton 2010-11-17 14:46:03 UTC
Where are the docs on how to use %caps in spec files?

Comment 2 Daniel Walsh 2010-11-17 15:45:43 UTC
Panu does such a document exist?

Comment 3 Panu Matilainen 2010-11-18 07:51:49 UTC
Not really, other than rpm 4.7.0 release notes which says:
It's now possible to specify file capabilities in %files section of spec files using %caps(<capabilities>) attribute. <capabilities> is simply the textual representation of capabilities as specified in the draft. 

And that's pretty much all there is to say about it, as rpm does no processing of its own on the capability string, ie its the same format as setcap(8) accepts.

Comment 4 Joe Orton 2010-11-18 11:28:12 UTC
It might have been nice to come up with some good docs before throwing bugs at us, no?  What "draft" is referred to there, Panu?

I've read a bunch of man pages, and am trying to understand how this will work.  It looks like capability of

   cap_setuid,cap_setuid+pe

will do the expected thing for suexec, but it is pretty complicated following through the rules.  Particularly we need to be sure that the process which suexec itself execve's will not be executing with the SETUID/SETGID capabilities.  (at least, in the "effective" set, I think).  

Q: Does it matter much if a less-privileged app executes with the SETUID capability set in "permitted" but not "effective"?

Possibly suexec should either be clearing its capability sets (or merely its bounding set?), or possibly checking the capability sets of file it execves.

The rule for execve in capabilities(7):

           P’(permitted) = (P(inheritable) & F(inheritable)) |
                           (F(permitted) & cap_bset)

surprised me.  What is the point of the "inheritable" capset if it is binary ORed with the permitted capset in the file, rather than a binary AND?  (i.e. the inheritable capset does not impose an limit on what capabilities can be inherited, only the bounding set does that)

1) What is the "capability bounding set" going to be in the httpd parent?  It looks like this is up to userspace/init (and hence up to Fedora policy?).

2) Similarly, can the httpd parent expect to be executed with all three capsets (permitted, inheritable, effective) set to all-1s?

It would be nice/necessary to get these things documented so admins can understand what is going on as well as humble packagers.

Comment 5 Joe Orton 2010-11-18 11:28:12 UTC
It might have been nice to come up with some good docs before throwing bugs at us, no?  What "draft" is referred to there, Panu?

I've read a bunch of man pages, and am trying to understand how this will work.  It looks like capability of

   cap_setuid,cap_setuid+pe

will do the expected thing for suexec, but it is pretty complicated following through the rules.  Particularly we need to be sure that the process which suexec itself execve's will not be executing with the SETUID/SETGID capabilities.  (at least, in the "effective" set, I think).  

Q: Does it matter much if a less-privileged app executes with the SETUID capability set in "permitted" but not "effective"?

Possibly suexec should either be clearing its capability sets (or merely its bounding set?), or possibly checking the capability sets of file it execves.

The rule for execve in capabilities(7):

           P’(permitted) = (P(inheritable) & F(inheritable)) |
                           (F(permitted) & cap_bset)

surprised me.  What is the point of the "inheritable" capset if it is binary ORed with the permitted capset in the file, rather than a binary AND?  (i.e. the inheritable capset does not impose an limit on what capabilities can be inherited, only the bounding set does that)

1) What is the "capability bounding set" going to be in the httpd parent?  It looks like this is up to userspace/init (and hence up to Fedora policy?).

2) Similarly, can the httpd parent expect to be executed with all three capsets (permitted, inheritable, effective) set to all-1s?

It would be nice/necessary to get these things documented so admins can understand what is going on as well as humble packagers.

Comment 6 Joe Orton 2010-11-18 12:30:12 UTC
I meant a capability of:

   cap_setuid,cap_setgid+pe

there, and sorry for the double-post.

Comment 7 Daniel Walsh 2010-11-18 13:40:42 UTC
Well one of the reasons for opening this feature is to collect information on what we are missing.

Steve Grubb would be the best source of info on your question.  Steve?

I think you should be dropping your capabilities after you change your uid/gid, whether or not you are using setuid or file cababilities in normal course, although people might code up suexec in such a way that they expect full capability access when running the command.

SELinux policy only has 

allow httpd_suexec_t self:capability { setuid setgid };

Which means we have not witnessed the need for additional capabilities.

Comment 8 Steve Grubb 2010-11-18 14:10:59 UTC
Joe, You can make suexev run captest to see what capabilities the child process gets. The Bounding set is the new inheritance flags in 2.6.26 and later kernels. 

You need to have permitted == effective. There was a misguided notion that permitted would be all the capabilities that a process can have and the effective be the ones in effect. The process could swing in capabilities as needed so that its least privileged. However, an attack can do that too, so its useless to not have permitted == effective.

Just set the file based capabilities as you mentioned and try running captest. I think you'll see that everything works out OK. If captest has any capabilities listed, let us know what it reports.


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