From patchwork Tue Sep 29 10:58:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 263136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3565C47423 for ; Tue, 29 Sep 2020 12:03:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A8242074B for ; Tue, 29 Sep 2020 12:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601381001; bh=1mIj69/AdI66ecJ3kzCGsxsb13fML65mPCSlmdkpGvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GADBGups/RzB1ROGroSJpqMuUd+c48XdrJE2LXSRzEyffJ/2Lesjt0vH5SDAdvAPx 0bX3rLftQHd1xSGNQecBIKgX5B/aqqGLQyOlIQuEBrEffn7aL+uN472gcW5ptEkOER xCqLXFU6Yr3mHU/NPOXHZkyn2rSWD4OmrJufRJws= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729943AbgI2Lif (ORCPT ); Tue, 29 Sep 2020 07:38:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729101AbgI2Lif (ORCPT ); Tue, 29 Sep 2020 07:38:35 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 9935F22574; Tue, 29 Sep 2020 11:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379510; bh=1mIj69/AdI66ecJ3kzCGsxsb13fML65mPCSlmdkpGvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DpzvnA7vY9lSDcdL/s0nfFw6yHRi7goWQ1LoAWRwaxhGFgybtBGx5zu+nLqJ2//Mx Fwa/XO3xPf/ctpVoga7EHZ6gZYsgNH2DHi/p+nochWnz1TgWMXABe0n6MUHmPj0aPu /F815LkuUfiuL4fgKMHKKFvj4sHN9eWWD78MSPLc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bernd Edlinger , "Eric W. Biederman" , Sasha Levin Subject: [PATCH 5.4 196/388] proc: Use new infrastructure to fix deadlocks in execve Date: Tue, 29 Sep 2020 12:58:47 +0200 Message-Id: <20200929110019.967823686@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Bernd Edlinger [ Upstream commit 2db9dbf71bf98d02a0bf33e798e5bfd2a9944696 ] This changes lock_trace to use the new exec_update_mutex instead of cred_guard_mutex. This fixes possible deadlocks when the trace is accessing /proc/$pid/stack for instance. This should be safe, as the credentials are only used for reading, and task->mm is updated on execve under the new exec_update_mutex. Signed-off-by: Bernd Edlinger Signed-off-by: Eric W. Biederman Signed-off-by: Sasha Levin --- fs/proc/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index ebea9501afb84..4fdfe4faa74ee 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -403,11 +403,11 @@ print0: static int lock_trace(struct task_struct *task) { - int err = mutex_lock_killable(&task->signal->cred_guard_mutex); + int err = mutex_lock_killable(&task->signal->exec_update_mutex); if (err) return err; if (!ptrace_may_access(task, PTRACE_MODE_ATTACH_FSCREDS)) { - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); return -EPERM; } return 0; @@ -415,7 +415,7 @@ static int lock_trace(struct task_struct *task) static void unlock_trace(struct task_struct *task) { - mutex_unlock(&task->signal->cred_guard_mutex); + mutex_unlock(&task->signal->exec_update_mutex); } #ifdef CONFIG_STACKTRACE