Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7101867ybi; Mon, 8 Jul 2019 14:37:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6dDs2GNjk+lKldVVJxsxW9Qw/8gUxpHXKFfMW8EU6j20yUBgSKTCyf4ePRI1xfUQcjDDc X-Received: by 2002:a17:90a:601:: with SMTP id j1mr27838421pjj.96.1562621852251; Mon, 08 Jul 2019 14:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562621852; cv=none; d=google.com; s=arc-20160816; b=Xu3XSg1i9w5SSi8JVG32BCu04LBmZcZLh9x1cFp0Rr0W9iZ4ehvrdfH9D2sFquOmsX z+ITworb6/hbQke0x8XExZum2oORIEwada8aBd89TcHVxrlb9D/agGP/bPhhkE+l7kwh LRpsNj0LMSlwD9XVuuJgKvKnP2De0wUfkQxfgUurDHaokamx2M5DedznLGo/s1W1x7by jY14XzhpRLsVTzB6M6yG9iWDbQ17cyKOx+XmuLhKklSkgYz8OXx78krI80pWFn9fn7od 6J+ZXj3JM39X6gPQxGwgBiS5gT0E1BK0jzzJgMEyto6BHoS+prUYIwRgzdi4dUUApHui AvqQ== 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=v6nG+vxRpOwQfFQSJEzPCB6kLwAUrVZBk7wwO8u7TKQ=; b=Nf1rnO80wtICO/c6MOEdN7LMVPnB+5X8+lSbSToX01gtyaQtrxtcMg51kHgbls7fgc vlZXF0+kmDjcSnTcPkOtNN40dNUlWQODj4f7tbgOG0sagM/Ry7EHZHWRGCuRbz2f4MQi yR8kCJeIjO9KvI6nvdybDGrujFlnSaz+naFzUIrX/jykM4zcVW61NqLHr+GjRLb6wk5b ODSaY+hdt9YlVw3lolmHJu9Pu+Dd37nBht+2E95LQb0rQUBDs3cWV5SP8ElmPa7o+DM7 QH7dk+NS+/CiRTILP3jwmC2V7/vU9M3s2pzvBNzmfknGnYM7ZYPf5VCi17e5zlAZMJX2 EMGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LFjROdHl; 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 z186si20623219pgd.162.2019.07.08.14.37.17; Mon, 08 Jul 2019 14:37:32 -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=LFjROdHl; 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 S1732857AbfGHPRi (ORCPT + 99 others); Mon, 8 Jul 2019 11:17:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:40974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732842AbfGHPRd (ORCPT ); Mon, 8 Jul 2019 11:17:33 -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 8DFD0216C4; Mon, 8 Jul 2019 15:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599053; bh=yeybfoY3aX4WhdcmzO9PBFQXE+dk9vasnGbliLQV7hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFjROdHlHZ3Oglfo6nPQHB4sFvcoLSc2Q9vOFIa+KSDg/B/X0FuE8z/KNaF5iUDCC EFOmLfsiO+GiJLyllFJpUCuLIO9UbVhAqDUeyosf4UualzhittlcF7DK1LVbSHd3Pg sUBcnIKfuB6E3pRRk+Lh4TYY821JDUcQWUnrZSWk= 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.4 62/73] ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME Date: Mon, 8 Jul 2019 17:13:12 +0200 Message-Id: <20190708150524.578927600@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150513.136580595@linuxfoundation.org> References: <20190708150513.136580595@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 @@ -45,9 +45,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()); } /**