linux-kernel-test/security
Eric W. Biederman 520d9eabce Fix cap_capable to only allow owners in the parent user namespace to have caps.
Andy Lutomirski pointed out that the current behavior of allowing the
owner of a user namespace to have all caps when that owner is not in a
parent user namespace is wrong.  Add a test to ensure the owner of a user
namespace is in the parent of the user namespace to fix this bug.

Thankfully this bug did not apply to the initial user namespace, keeping
the mischief that can be caused by this bug quite small.

This is bug was introduced in v3.5 by commit 783291e690
"Simplify the user_namespace by making userns->creator a kuid."
But did not matter until the permisions required to create
a user namespace were relaxed allowing a user namespace to be created
inside of a user namespace.

The bug made it possible for the owner of a user namespace to be
present in a child user namespace.  Since the owner of a user nameapce
is granted all capabilities it became possible for users in a
grandchild user namespace to have all privilges over their parent user
namspace.

Reorder the checks in cap_capable.  This should make the common case
faster and make it clear that nothing magic happens in the initial
user namespace.  The reordering is safe because cred->user_ns
can only be in targ_ns or targ_ns->parent but not both.

Add a comment a the top of the loop to make the logic of
the code clear.

Add a distinct variable ns that changes as we walk up
the user namespace hierarchy to make it clear which variable
is changing.

Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2012-12-14 13:50:32 -08:00
..
apparmor apparmor: fix IRQ stack overflow during free_profile 2012-10-25 02:12:50 +11:00
integrity ima: fix bug in argument order 2012-10-05 22:32:16 +10:00
keys Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
selinux fix a leak in replace_fd() users 2012-10-16 13:36:50 -04:00
smack consitify do_mount() arguments 2012-10-11 20:02:04 -04:00
tomoyo consitify do_mount() arguments 2012-10-11 20:02:04 -04:00
yama userns: Kill task_user_ns 2012-11-20 04:17:44 -08:00
capability.c consitify do_mount() arguments 2012-10-11 20:02:04 -04:00
commoncap.c Fix cap_capable to only allow owners in the parent user namespace to have caps. 2012-12-14 13:50:32 -08:00
device_cgroup.c device_cgroup: add proper checking when changing default behavior 2012-10-25 14:37:52 -07:00
inode.c securityfs: fix object creation races 2012-01-10 10:20:35 -05:00
Kconfig KEYS: Move the key config into security/keys/Kconfig 2012-05-11 10:56:56 +01:00
lsm_audit.c LSM: BUILD_BUG_ON if the common_audit_data union ever grows 2012-04-09 12:23:03 -04:00
Makefile security: Yama LSM 2012-02-10 09:18:52 +11:00
min_addr.c mmap_min_addr check CAP_SYS_RAWIO only for write 2010-04-23 08:56:31 +10:00
security.c consitify do_mount() arguments 2012-10-11 20:02:04 -04:00