From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 309E8C43463 for ; Fri, 18 Sep 2020 03:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2ADD206B6 for ; Fri, 18 Sep 2020 03:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600398173; bh=1mIj69/AdI66ecJ3kzCGsxsb13fML65mPCSlmdkpGvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kpGmHJhH/PCYQ/gQ7zcAA6SwQBeqe/Rq9VoUFJb9Bc0XZTqNI1qMeb3kLVAWPa+N8 k+oG6CZd1v170WtR2o9k9ZD9Yk4oRkv5ohmAxdgcXDitycRqeq5wpKw67jVX6V4bZh RhKqEMrURXDiUJoWvO0P4TPBWul3iPuP6MoV3WsM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730536AbgIRDCv (ORCPT ); Thu, 17 Sep 2020 23:02:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:53518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbgIRCFS (ORCPT ); Thu, 17 Sep 2020 22:05:18 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D3B5F23718; Fri, 18 Sep 2020 02:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394718; bh=1mIj69/AdI66ecJ3kzCGsxsb13fML65mPCSlmdkpGvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oa22KzgkC5FUx3BEwtIBu+GyabC1Ya5xkW1AxuC78IQWsN6zCUZwX0ZsWhqA2+Lo4 cdnadsWiwp7F90a2q9N/7vYk6Zl9PaYYrMu7VMEgUiwktUJ0vwTebTkk+P0Jz1zWS/ qfKRWf5bVdLCZlw2e/30g/Dn6eZGZ1MZqCvAIQr8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bernd Edlinger , "Eric W . Biederman" , Sasha Levin Subject: [PATCH AUTOSEL 5.4 202/330] proc: Use new infrastructure to fix deadlocks in execve Date: Thu, 17 Sep 2020 21:59:02 -0400 Message-Id: <20200918020110.2063155-202-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 -- 2.25.1