Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7148830ybi; Mon, 8 Jul 2019 15:37:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFWrInQUTWbZHNKTjYhhPrKrKAkf/r0GOcMrxfZHfjYn9nuyX849Oj7pXiLM4Taxt3+F+a X-Received: by 2002:a65:6406:: with SMTP id a6mr25784837pgv.393.1562625446210; Mon, 08 Jul 2019 15:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625446; cv=none; d=google.com; s=arc-20160816; b=YpTGld+Dy+e52vmHxLm6tBVIjKyMOdKBCxodE/jERKfmoADzPEiD/Ug+dDZ9hBVZqm Zo8YL5UIIhr9EuYXOxnQ6zd33WvDIbjbUS9lJT2RbhhMfL4cxKvl3D1Tbw0tEIDrR9L/ h6NzkVn0eYupmzpLLfTpYVzUI3qkuTBXyk/wevx8Nqqg3FO2BBHFD5cPBMKOULUHLMTv wimob5q4NDsH5lppZUSvM/uv6vJuSKEbcKs9UxPrqP9fA5H78vETrkG/+b0G+VurJpjT OEWUHDA7PsvqcmoGUyNXbY8Ap1m55uHvs2zukuaoUTGpL8gZ+VzHcqo36kO5AixyCnxa 75jg== 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=b3dUqrAZn2R4kjUZp14uALMOWO5t67EfZaOfMuQujew=; b=oLPhjSWYohHY01egjMl7S7R3mEMQ36jLIMqlgN4dyfBMe04rjuehTVOyhKLYXAHgxD kYlXJUdqIgCQZ52A1G9ZngSNNXK541BDbDaPLnshNK4VZFfl0fv0Zg9WEUq58tDPRWIw AsODtnKqTwnCAR+k9VPHjgHClGO8iPcd9rubocjs4aN+VrXghgB0w9h1gKB/k1WMYtvJ 75rt1M5WSHOhOG/yvhZAYAt1W7OghiDXdisIeMSjbn/nQxrru4bvO2G9v4ShrfJ1Hrrq 5/oSXZ1nZH90LgBadvLn98kxLpuPseAtGBb9YpRBWh2Z6Izp/69uxgmIyPvnOZFcGxEz XZtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2f1vYw60; 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 k15si19110533pgh.331.2019.07.08.15.37.11; Mon, 08 Jul 2019 15:37:26 -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=2f1vYw60; 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 S1731175AbfGHPWd (ORCPT + 99 others); Mon, 8 Jul 2019 11:22:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:48990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387959AbfGHPW3 (ORCPT ); Mon, 8 Jul 2019 11:22:29 -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 2AC65216C4; Mon, 8 Jul 2019 15:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599348; bh=Tr7jjzslEElrJBvAeJh/1qHlH0gkRwbCfJetvKKd06o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2f1vYw60q/VCR2Ql1puIIMEzBsnVTW6kWrcsGOkpQ522TZbW+nz/UoFDzj5rD1OXd iTNKf5g7lPRp7ahEa1nurduyEsyJg5jV/hpigViP/4M8SlADF7tNIg5KMl6NrlA2ZB ErW+N3DL54aKY8NqDK2P0Bl8OzM7lI4/ihAP3aJ8= 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.9 086/102] ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME Date: Mon, 8 Jul 2019 17:13:19 +0200 Message-Id: <20190708150530.917139845@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150525.973820964@linuxfoundation.org> References: <20190708150525.973820964@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 @@ -74,9 +74,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()); } /**