]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commit
ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME
authorJann Horn <jannh@google.com>
Thu, 18 Jul 2019 22:22:59 +0000 (22:22 +0000)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 30 Jul 2019 10:58:17 +0000 (12:58 +0200)
commitf92e1d33b6b3b67c82d1da31a95765cdc5c90777
tree4e84628ed61d9b20159255cb32ee6d1ef635fb94
parentdc8b7e306e06b7a9054f78764d5733d2929f95e2
ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME

Fix two issues:

When called for PTRACE_TRACEME, ptrace_link() would obtain an RCU
reference to the parent's objective credentials, then give that pointer
to get_cred().  However, the object lifetime rules for things like
struct cred do not permit unconditionally turning an RCU reference into
a stable reference.

PTRACE_TRACEME records the parent's credentials as if the parent was
acting as the subject, but that's not the case.  If a malicious
unprivileged child uses PTRACE_TRACEME and the parent is privileged, and
at a later point, the parent process becomes attacker-controlled
(because it drops privileges and calls execve()), the attacker ends up
with control over two processes with a privileged ptrace relationship,
which can be abused to ptrace a suid binary and obtain root privileges.

Fix both of these by always recording the credentials of the process
that is requesting the creation of the ptrace relationship:
current_cred() can't change under us, and current is the proper subject
for access control.

This change is theoretically userspace-visible, but I am not aware of
any code that it will actually break.

Fixes: 64b875f7ac8a ("ptrace: Capture the ptracer's creds not PT_PTRACE_CAP")
Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
CVE-2019-13272

(cherry picked from commit 6994eefb0053799d2e07cd140df6c2ea106c41ee)
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Kamal Mostafa <kamal@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
kernel/ptrace.c