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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 D4CD8C0044D for ; Wed, 11 Mar 2020 19:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B09A62074A for ; Wed, 11 Mar 2020 19:10:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aAhh+xSk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731035AbgCKTKV (ORCPT ); Wed, 11 Mar 2020 15:10:21 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34506 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730807AbgCKTKV (ORCPT ); Wed, 11 Mar 2020 15:10:21 -0400 Received: by mail-pf1-f195.google.com with SMTP id 23so1877142pfj.1 for ; Wed, 11 Mar 2020 12:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=KcVIrCgeM2L71oQ0HCuZKZl5I3Zr+0M/E39SQWV0gp4=; b=aAhh+xSkXE2t12sKK6saJVYSmf5MEARRfmtM9BDdPnG9hOhY9hMiwRX70zMMhmadP8 AEe0v12Bn33gajUeD1uQ8UKiOyi2zoq7FIlGGcSTWYQXUe84sEe6lGBVcgqvS8yfdCxA BqGVlEbMZdiVCE8GlL7i8viPdEpQyi+6TSziw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KcVIrCgeM2L71oQ0HCuZKZl5I3Zr+0M/E39SQWV0gp4=; b=o2n87Y2QwAs7VDApQVjtYwWF9elXJSHOAz5gvaq0wKVAfB9AZmmR8jnpROOQdnLOww RtlJ+JIdz/cDfHdn3HBQUQ+5YQmAZ7lE0GQAOzvgEk0jjT3TL2fjI8pwvSX2KA9iZBSX ZxpieSBroEti1K6O9sJ4FycTT7Vm4uj7vVBvSZmPPTf3qLqLtTyPbR28yqAt7KA5yOgN DK+g3JCihB8eFPeaXhazkiqGGPzIKcEx3tTKOWhyr0g98vLdTPe60CkAiXE83DyHLVlW /cZ2I0qx14EVXbOWRTnWpeZfWVGdy2X7ye9UxjGuu+gv2QzWc5wPnIJUK2KkBqJxFD5M tZlg== X-Gm-Message-State: ANhLgQ2v9ieUDUwde646j84frzcbNH25dlJQZwBCMXECh8foKOt+yWMX UNfKJVBGBerDVRjQal7icbKM+A== X-Google-Smtp-Source: ADFU+vt4NOtfCQB7oRTvrmQkPz4WbsEGCcbOLVTPV1BJcvkD6Dr4oGu+cuFqlafAZoPG2TJB9TQ2XQ== X-Received: by 2002:aa7:8687:: with SMTP id d7mr4225994pfo.247.1583953820089; Wed, 11 Mar 2020 12:10:20 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e10sm9854448pfm.121.2020.03.11.12.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 12:10:19 -0700 (PDT) Date: Wed, 11 Mar 2020 12:10:18 -0700 From: Kees Cook To: Bernd Edlinger Cc: "Eric W. Biederman" , Christian Brauner , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" Subject: Re: [PATCH 2/4] proc: Use new infrastructure to fix deadlocks in execve Message-ID: <202003111208.640025F75@keescook> References: <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> <875zfcxlwy.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 10, 2020 at 06:45:32PM +0100, Bernd Edlinger wrote: > 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 I have the same question here as in 3/4. I should probably rescind my Reviewed-by until I'm convinced about the security-safety of this -- why is this not a race against cred changes? -Kees > --- > 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 ebea950..4fdfe4f 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -403,11 +403,11 @@ static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns, > > 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 > -- > 1.9.1 -- Kees Cook