Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp855509ybh; Wed, 11 Mar 2020 12:11:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv4GWVa6Yhub/trBg8SEE9dzUiWnuqEbak/SovsWPeBzm8kh6GMdr7FeX5o/uq1BM9VGao1 X-Received: by 2002:a9d:882:: with SMTP id 2mr3652378otf.198.1583953885444; Wed, 11 Mar 2020 12:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583953885; cv=none; d=google.com; s=arc-20160816; b=JW7Uu/AOaZUb2y0V31h3PmeDVzAJ+/Pp4P8PX97Z08S+BCszP0jnj6h3YzhHH5ePIh Ze1go3pANg1V1iWboJbVcf82nHCqya0ZEPsqyj4XqJJ7Z5oXj4Uzn+0csMeMPeWmVd7Q Kbz+7UhnS6QQYbPuY+NDJVH9JXlCNTZypvC9oy+bZUujJqtrAK8B8n9yH8ZYkM512UVK MFB1k3wSHw7swMuPxs8mb1E3xIO3QbS74E1xZg7dfylAufL1305KntUPUFENwK6bS8JK Ntw5MJXqaFydi1bM4/pC1a6Bkxhc0GRR0KRdwz1KgRsognYSh9ktPyZmLpSNP3PKRZX7 bYDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KcVIrCgeM2L71oQ0HCuZKZl5I3Zr+0M/E39SQWV0gp4=; b=PW7pNmT4Ug9k1RvWwZdWWRAXWGp1SqJB7F6Trksco9mg5SbjlH3A3BsVKfxYBy3ZDW KzkLNQec+slabH1SPRFnQ+ozvanYuHl8E7Ux/Oozs8FEOmhJiQ6BIJECAmuHW1zd6GjH wj7SdOKrOTQqJdgOvlNVFXPJOLcN+oGSMthOq9yC5PdnYPp9BZVbdKN9UADDyGRH+ttn OkevgZL122CVqNqiggm3nvk7Q2bQexOw/ZyD0DzFIrp3MzR5ipSDF8Yl0yX7k7axU21w lVOGWMhLXDE5EE9cu5ryzHu0owLCsIq6xB2q2dCZlhTC/cBYE+c3jrWEuNC2bB1dW5uf zM3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aAhh+xSk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si1492027oiv.143.2020.03.11.12.10.45; Wed, 11 Mar 2020 12:11:25 -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=@chromium.org header.s=google header.b=aAhh+xSk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731025AbgCKTKV (ORCPT + 99 others); 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-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