Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 147572 - sys-apps/sysvinit sysctl doesn't respect "cap-bound"?
Summary: sys-apps/sysvinit sysctl doesn't respect "cap-bound"?
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: High minor
Assignee: Gentoo Security
URL:
Whiteboard: ?? [noglsa] jaervosz
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-14 07:43 UTC by Sune Kloppenborg Jeppesen (RETIRED)
Modified: 2019-12-28 12:34 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 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-09-14 07:43:14 UTC
#### Test case ####

A simple test case for this would be to run the following as root, on a system 
running a capability-enabled 2.6 kernel (either through the default 
commoncap, or the capability LSM with CONFIG_SECURITY and 
CONFIG_SECURITY_CAPABILITIES) :
sysctl kernel.cap-bound=0xfffefeff (drop CAP_SYS_MODULE)
modprobe <some module>
That works on gentoo, since processes under uid 0 keep a full capability set 
no matter what cap-bound says. On other distributions (and on gentoo with the 
fix proposed in this mail), it shows the expected behavior of not permitting 
module insertion. This can be verified with 'cat /proc/self/status' as root, 
which on Gentoo shows all three capability sets (CapInh, CapPrm, and CapEff) 
at 0xfffffeff (the full set, i.e. everything except CAP_SET_PCAP which is 
disabled by the kernel), and this holds true whatever cap-bound may be set 
to. Same goes for setuid-root executables launched by any non-privileged user.

#### Impact ####

As I said earlier, this is not really a vulnerability, and shouldn't have any 
impact on desktop systems (where cap-bound isn't much use, as CAP_SYS_RAWIO 
is needed for X11). It might however be an issue for hardened servers, where 
it is highly recommended to drop CAP_SYS_MODULE and CAP_SYS_RAWIO at least, 
as a protection against kernel-level rootkits (see e.g. what happened to the 
Debian servers in 2003, and how it could have been prevented :  
http://www.wiggy.net/debian/developer-securing/ ). Since Gentoo voids this 
protection (without documenting it, as far as I can tell), such systems might 
be at risk.

#### Analysis ####

The culprit for this unexpected Gentoo behavior is a patch to 
sys-apps/sysvinit (tested here on versions 2.86-r3 through -r5), that was 
applied based on bug #5818 in the gentoo bugzilla. The patch, 
sysvinit-2.86-POSIX-1003.1e.patch, has init set its inheritable capability to 
its current effective capability (which is the full set as defined in 
include/linux/capability.h, 0xfffffeff on 2.6 kernels). 
This is then inherited by all processes spawned by init, whether root or not, 
since the inheritable capability is never modified by the kernel (see 
cap_emulate_setxuid() in security/commoncap.c in the kernel source tree : 
only the effective and permitted sets are cleared on setuid()). 

Looking at cap_bprm_apply_creds() in security/commoncap.c in the kernel source 
shows that when exec'ing a new binary, the new effective capability is

E(c) = E(b) <i> [ ( P(b) <i> cap-bound ) <u> ( I(b) <i> I(c) ) ]

where E(),P(),I() denote the Effective, Permitted, and Inheritable capability 
sets of (c) the Current task or (b) the executed Binary, and <i> is for 
Intersection (bitwise AND) and <u> for Union (bitwise OR).  
The intersection of inherited capabilities completely bypasses the cap-bound 
limit. This is correct with regards to the POSIX capability model, and is 
supposed to provide a way for file-attached capabilities to work. However, 
such file capabilities are not supported by Linux, which thus sets I(b) to 
CAP_FULL_SET if either the current task is executing as root or the binary is 
setuid root (see cap_bprm_set_security() in security/commoncap.c), and 0 
otherwise. Once again this is expected, documented behavior, and works 
correctly as long as I(c) is 0, which is supposed to be the case (see the 
definition of CAP_INIT_INH_SET in include/linux/capability.h).

Gentoo's patch to init, however, wreaks havoc with this logic, and completely 
bypasses the capability bounding set mechanism as it is supposed to work in 
Linux.

#### Fix ####

Simply removing the sysvinit-2.86-POSIX-1003.1e.patch fixes this strange 
behavior, with no negative impact as far as I can tell. This seems the best 
fix, as the patch does not do anything useful (again, as far as I can tell, 
please correct me if I'm wrong). Short of that, a strong warning in the 
ebuild and in online docs would be appreciated, and possibly a USE flag to 
selectively disable the patch.
Comment 1 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-09-14 08:16:27 UTC
Got this report earlier today.

Solar/Vapier could you have a look?
Comment 2 SpanKY gentoo-dev 2006-09-14 09:04:12 UTC
i have no problems punting said patch if, by design, the desired behavior cannot be obtained at this time
Comment 3 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-09-14 12:59:22 UTC
Adding reporter.
Comment 4 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-09-19 00:44:34 UTC
SpanKY, do you want confirmation from another team member or are you going to drop the patch?
Comment 5 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-09-26 13:05:23 UTC
SpanKY, do you want confirmation from another team member or are you going to
drop the patch?
Comment 6 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-11-16 06:31:24 UTC
SpanKY, do you want confirmation from another team member or are you going to
drop the patch?
Comment 7 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-11-24 12:55:29 UTC
SpanKY, do you want confirmation from another team member or are you going to
drop the patch?
Comment 8 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-12-11 08:31:45 UTC
SpanKY, do you want confirmation from another team member or are you going to
drop the patch?
Comment 9 SpanKY gentoo-dev 2006-12-27 01:15:19 UTC
sysvinit-2.86-r7 no longer applies the patch
Comment 10 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-12-27 09:03:02 UTC
Thx Vapier. Is 2.86-r6 ready to be marked stable?
Comment 11 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-12-27 09:04:29 UTC
Bah, is r6 or r7 ready for stable marking?
Comment 12 SpanKY gentoo-dev 2007-03-08 20:41:07 UTC
sysvinit-2.86-r7 is being moved to stable already for unrelated reasons, so if you wanted to push it that'd be fine ...
Comment 13 Raphael Marichez (Falco) (RETIRED) gentoo-dev 2007-03-09 22:14:43 UTC
(In reply to comment #12)
> sysvinit-2.86-r7 is being moved to stable already for unrelated reasons, so if
> you wanted to push it that'd be fine ...
> 


Hi Mike,

this bug has been waiting for a long time now, i don't think it worth pushing -r7 into stable for security purpose, and given that -r6 doesn't apply the patch now.
It was just about a Posix consistency, hardly a security issue.

Vincent, feel free to disclose that bug by unchecking the below boxes as soon as you want (or when the bug is totally resolved).
Comment 14 Raphael Marichez (Falco) (RETIRED) gentoo-dev 2007-03-20 12:13:51 UTC
sysvinit -r7 is now marked stable on most arches (except Alpha and AMD64).

Now opening this bug with the agreement of Vincent, original reporter.

I'll close it when Alpha and AMD64 mark stable >=sysvinit-2.86-r7
Comment 15 Matt Drew (RETIRED) gentoo-dev 2007-04-05 01:00:43 UTC
cc'ing those two arches - I can't find a bug for sysvinit-2.86-r7 stabilization, so I suspect that it is related to other packages.

Alpha and amd64 - any word on what is blocking this stabilization?  Thanks.
Comment 16 Peter Weller (RETIRED) gentoo-dev 2007-04-06 16:10:50 UTC
-7 and -8 stable on amd64, sorry about the delay...
Comment 17 Raphael Marichez (Falco) (RETIRED) gentoo-dev 2007-04-09 19:00:49 UTC
ok so closing now with noglsa.  Feel free to reopen if you disagree.