exec: Ensure mm->user_ns contains the execed files
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 17 Nov 2016 04:06:51 +0000 (22:06 -0600)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 27 Feb 2019 02:13:12 +0000 (11:13 +0900)
commit8bbc12ac32d1674ae4141c2da32000df24e0f83f
treec72023a0fd2dd8030f8ba175388f7d72be215c07
parentc74e5873657b2422d060e426c108a14539c00256
exec: Ensure mm->user_ns contains the execed files

commit f84df2a6f268de584a201e8911384a2d244876e3 upstream.

When the user namespace support was merged the need to prevent
ptrace from revealing the contents of an unreadable executable
was overlooked.

Correct this oversight by ensuring that the executed file
or files are in mm->user_ns, by adjusting mm->user_ns.

Use the new function privileged_wrt_inode_uidgid to see if
the executable is a member of the user namespace, and as such
if having CAP_SYS_PTRACE in the user namespace should allow
tracing the executable.  If not update mm->user_ns to
the parent user namespace until an appropriate parent is found.

Reported-by: Jann Horn <jann@thejh.net>
Fixes: 9e4a36ece652 ("userns: Fail exec for suid and sgid binaries with ids outside our user namespace.")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: backport linux-4.4.y commit b35f34f66943 to resolve smack permission deny issue in cgroup_release_agent kthread]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Iafbc32f9c5cc7f4c963876bd30a65be87646b207
fs/exec.c
include/linux/capability.h
kernel/capability.c