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 E0D64C2BAEE for ; Wed, 11 Mar 2020 19:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC26B20749 for ; Wed, 11 Mar 2020 19:08:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ezUxUUOX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731014AbgCKTIM (ORCPT ); Wed, 11 Mar 2020 15:08:12 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39730 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730926AbgCKTIM (ORCPT ); Wed, 11 Mar 2020 15:08:12 -0400 Received: by mail-pl1-f193.google.com with SMTP id j20so1525506pll.6 for ; Wed, 11 Mar 2020 12:08:11 -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=DbOSuRE3mJHRT6NEoUnJAt4STBzgkZE2dyC9jqZCCLc=; b=ezUxUUOXDCiz09sL7ns9GljqAjBmqhyjSwvJorFlESxa+y3+f/0qlxnha+BOKyFFyf ERAU18z6eUiNgcbSjL1jsVciaLtO3QRYSLsFs8TwKJvof5riGga9gNTN9V0/psEVhU2x V/bi7iIGw3G5TZdWYOJ4NUQjucYxGZhfQRnwo= 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=DbOSuRE3mJHRT6NEoUnJAt4STBzgkZE2dyC9jqZCCLc=; b=hj0C+/96IMMX3ke+RiYrpQ/6gNzaQT0XB0iU9bHoU+1JqVLzP8wNB/25YeV31c9/lZ t1pfO7hL+ATzSfQcYEyDRYuOh/u/EZrNi6I+RiClx5tQBgibfeTTVzd7AzIDObdMNS4W gevul1PSieN+D2SVBZg3hIm9NXW/GGRy14oP3rxePh4EbP215W2d+qoGRLcZWO/ENZHN OwxgrxtlEuJreM1kKWXl14V5n7k9cdZleifFpM1QMjRptWOJU1WZcfrXYJgfHRV554eA VHO3AA7ntR6HLEpI/bVjz6p+jnPhItGUNJkVV7AqO7EYpAAythYnncHcz1X92S4yU4S8 DULA== X-Gm-Message-State: ANhLgQ2JtEMb8J8hA6PtYY7Tt86xubfq1XKxX4bV3unkwmssyO37IYUy kLiwvedQjF36mfKnKnXGRBo+Dg== X-Google-Smtp-Source: ADFU+vu1bU3k2S+HEZmBvCgVu915jbj4h0AdjuUzNnkHJx+FiemZBhEAG7aEg6xbQtj5ITkHsDfXoA== X-Received: by 2002:a17:90a:da01:: with SMTP id e1mr225598pjv.100.1583953691168; Wed, 11 Mar 2020 12:08:11 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y207sm1468232pfb.189.2020.03.11.12.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 12:08:09 -0700 (PDT) Date: Wed, 11 Mar 2020 12:08:08 -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 3/4] proc: io_accounting: Use new infrastructure to fix deadlocks in execve Message-ID: <202003111203.738487D@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:47PM +0100, Bernd Edlinger wrote: > This changes do_io_accounting to use the new exec_update_mutex > instead of cred_guard_mutex. > > This fixes possible deadlocks when the trace is accessing > /proc/$pid/io for instance. > > This should be safe, as the credentials are only used for reading. I'd like to see the rationale described better here for why it should be safe. I'm still not seeing why this is safe here, as we might check ptrace_may_access() with one cred and then iterate io accounting with a different credential... What am I missing? -Kees > > Signed-off-by: Bernd Edlinger > --- > fs/proc/base.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 4fdfe4f..529d0c6 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -2770,7 +2770,7 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh > unsigned long flags; > int result; > > - result = mutex_lock_killable(&task->signal->cred_guard_mutex); > + result = mutex_lock_killable(&task->signal->exec_update_mutex); > if (result) > return result; > > @@ -2806,7 +2806,7 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh > result = 0; > > out_unlock: > - mutex_unlock(&task->signal->cred_guard_mutex); > + mutex_unlock(&task->signal->exec_update_mutex); > return result; > } > > -- > 1.9.1 -- Kees Cook