Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7148447ybi; Mon, 8 Jul 2019 15:37:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFNHKUNnlqlJRGoIJuZBOxPS/ACaVE42Q3SCTedxhGyZ3kenuVU2tuX9OA4UYyDul/5eH2 X-Received: by 2002:a65:5348:: with SMTP id w8mr26229588pgr.176.1562625419982; Mon, 08 Jul 2019 15:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625419; cv=none; d=google.com; s=arc-20160816; b=M0eAb0ZhZ1fqZD/by7kpY2jV0fl2147ii3Cq7WZD2Ad4QSuERsmy8Dr2JPIpZujnPs g9BEQRv/u9YjlHscsPF7HnbdQlVj5gaRdocIubn5N8czpP4pxbQIXZQde8tH8t06EIfQ Ts5hILYtYfOQm6YKgHAnvSETcidw6P5nLVL7TDBLzik8AjPYDwvYif6xVwjPyAy0lrPf Zdq+jH9iIVZ87JxJQrdHZd1TQuKIfAZTeSJvx+vb3M4Yr85tHE2APJtXH2l1SNg2aAYq 2di3kckbjYJz+hD7dL5A6YNKCy+W0UxCt+hX3L+woIZo/grf3Ctgadk3KxRJmTgIN1A8 AP+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TIbNvDjOZoiCD8HEIBWkF9f0YLclWLbed4isZSPNB44=; b=TnJal4cLTttyoBnVcswm7IVQLPFqgeRKacXCo3QK1MGi1apvv4wod4SumnVeKURqL1 S2vJluxlyepr03D9ZWDz/di8qSYG/DFa4XiJQGUEbxoUuQxtJbKq7ZqQRlG4LLBmVBW7 gy5mqMoLOfXMhkKQy1LuYdMlAovh23ss8xN9y9kujwQroi9q8r1APYm6JxtsMZ5NCoSE CQSu2aNMi0KwrbvIVP1SBowzocSEAWnRxmxdnE02lsUcLrAKG4tP0RAlYm4n9SwLMIez 2ueUNh0O+a6hiEamIOSG8rQ2OOkd8J3LUxmOivgAPkBnkF/9PbYjJ68SYmbA/+12GR5x iSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="lge/ErUN"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e123si21037590pfa.252.2019.07.08.15.36.44; Mon, 08 Jul 2019 15:36:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="lge/ErUN"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388346AbfGHPYX (ORCPT + 99 others); Mon, 8 Jul 2019 11:24:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:51596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731376AbfGHPYU (ORCPT ); Mon, 8 Jul 2019 11:24:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 98F4121738; Mon, 8 Jul 2019 15:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599460; bh=w/C1KY7DwgILP0qzGNFTrFsId6j3M+yqpLgt9370w2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lge/ErUNje40tVHmOjidFQL45t26g5CiegUDOYrAEaE67GTpQ6jmbWRvKUg9dXQiv fPsBuCABmmSjTPlADSZrfk+3P4Kf/wuqwu37x/0xwcBPiBo4DLPy6LH0YppNjSJTrX NaiX/qkKpN0SjzYUoAdP6akEAAsIsKIYtS5c5QQc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Oleg Nesterov , Linus Torvalds Subject: [PATCH 4.14 23/56] ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME Date: Mon, 8 Jul 2019 17:13:15 +0200 Message-Id: <20190708150521.427133141@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150514.376317156@linuxfoundation.org> References: <20190708150514.376317156@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jann Horn commit 6994eefb0053799d2e07cd140df6c2ea106c41ee upstream. 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 Acked-by: Oleg Nesterov Cc: stable@vger.kernel.org Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/ptrace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -78,9 +78,7 @@ void __ptrace_link(struct task_struct *c */ static void ptrace_link(struct task_struct *child, struct task_struct *new_parent) { - rcu_read_lock(); - __ptrace_link(child, new_parent, __task_cred(new_parent)); - rcu_read_unlock(); + __ptrace_link(child, new_parent, current_cred()); } /**