Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp992475ybh; Tue, 10 Mar 2020 12:18:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt44/DLPegGdWGhhdZ2V/QVzE3/YunKIm8nd+6jkI6kVUBmC4xELaR5lHeVQoZf8j0VScTj X-Received: by 2002:a05:6830:c5:: with SMTP id x5mr4889007oto.302.1583867889534; Tue, 10 Mar 2020 12:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583867889; cv=none; d=google.com; s=arc-20160816; b=k7BkRkm+zrHwsTzn9P80cRzL6lqdfGQqlkuKUVvMsiJHFjWzHlvsqRC4TedP5fofrZ h6Pu6DJw3+nsvqBw1wwn0jObB/e8UvPAoVozmsqp2nQe9W+ot0AVRKwsLWbEV1UdndE4 t5Waca5genxL0qHKuJ0JQVwoYD6VZqpb5+CiBXoqiloZKuk2DNEd2f6LqGowpSI/4uQH PZp0cbNGhqVrjqdd+yWMm8UfjBUUsND/seFiImypc8KqKEwtMEiz+MkoH8TyPg5ubbmy mlLspOwbeZTds4jieJeph9ZGf1TfuZ53WM13yzK8BkdVuM1/HAm/NNAjIx+Z00kAtfOk 7L5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TW/yj+hWXnFZH+cIOV6JEAyfHAcoNuoZqAljLHFkJp0=; b=bhtKbtVvTuTBteSQO84IMzvLLNx0n2bzsE8QKVJAj4QE5XmB22pGpBvaXoAW2Ipv1/ 9WSwyUhO7dHW+KMXEUoPc6a+5dMn4i/yUl61W4curazf+4DBAJL03UJvoBYVz7a2Tt2k 3SYumrKlh830uLMGnf/Ss+SzWat7gTGQwjIlQY4RXqPo5vdbmE6GoY22jy7sBDWiF7gW XjFnzvs9gM1ez57q5Za6udv7xs+qK3ibWRtDo1LP7ohfKH52uNDPzLokP28Lupz5wBn9 RNmOFY8IW+i1efADMseI9X3SyXi4y1ZY4gAHdqgdzK6uhkTSIk27x+YtaQy6NKY3ymx/ uwJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qnpTPsDr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si8438523otq.123.2020.03.10.12.17.56; Tue, 10 Mar 2020 12:18:09 -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=@google.com header.s=20161025 header.b=qnpTPsDr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727280AbgCJTRQ (ORCPT + 99 others); Tue, 10 Mar 2020 15:17:16 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:36327 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727146AbgCJTRP (ORCPT ); Tue, 10 Mar 2020 15:17:15 -0400 Received: by mail-oi1-f196.google.com with SMTP id k18so2022620oib.3 for ; Tue, 10 Mar 2020 12:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TW/yj+hWXnFZH+cIOV6JEAyfHAcoNuoZqAljLHFkJp0=; b=qnpTPsDrlbR61cP6qwOtvwRo6RX3RcguUv4e0B4EPRv3lMbVxx87PrzuIty/LAuNGA 1augL8bDQC+2Hgp+i4+8bOjr36RGS51J8cskswpHGlA6X6Tcgu5QhsxIBNt8a1DjhDkx BflQMoX3sKZF6vKlpOp4Q97mWTc0WRVR8sXyHC1HD8HOM++D8ZkJC/DxWDBawgvB0eG0 c7CN/j7N/lduGOb8USG++EB+qLuRZ5ZmGvJgDndqyRfs2ncknuXH1XtvbZj9HyS3FKMN yJpRs7vrTdLLLXQsmXyrmLPA/+5a86cpumsh0BJi7WdP9qmCX8c1nFHsp7pZZKTS/iA3 E1Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TW/yj+hWXnFZH+cIOV6JEAyfHAcoNuoZqAljLHFkJp0=; b=tyYPKlwQhu27fY6vA+telfhP1Es7o6Kvy4s7Iai5qjbn4etM9XSP+BLJRYN4WyfA+b 2fQIAKJNd987NqkCl+fTS2zvwByQ2MTnWZG2hsgRnPodbzJjgPzQ25sVJvRVpyiePu5y K9O1QsNkgEg5yhmNJeBUgrokFFjOtXPQQbdkAvJeZPnd0nqXhko3feGb/AIgHX9cKhSM H++2ppIvcRR9XJEKJPyr+9UjHAaGxmib3AeL/iXIcJb1FkyXFCahqRSuxd1VmMm9U122 iXnAxBoqiVD7XgmYxdKTv6CRGDHfgMk2694LPk1sYCTeTLWdoFFgocSBbb+zgQ8f/Z+o CT3g== X-Gm-Message-State: ANhLgQ0LhUWfi7byZvZov/w3ab16mbPnhpMX3BeYy8+KWnzGTmJ3Jd8t idkr/lwP1WYh3DKiyGD7ZTMSE48/H+sD7jXCCCGBww== X-Received: by 2002:aca:bac1:: with SMTP id k184mr1869239oif.157.1583867833858; Tue, 10 Mar 2020 12:17:13 -0700 (PDT) MIME-Version: 1.0 References: <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87eeu25y14.fsf_-_@x220.int.ebiederm.org> <20200309195909.h2lv5uawce5wgryx@wittgenstein> <877dztz415.fsf@x220.int.ebiederm.org> <20200309201729.yk5sd26v4bz4gtou@wittgenstein> <87k13txnig.fsf@x220.int.ebiederm.org> <20200310085540.pztaty2mj62xt2nm@wittgenstein> <87wo7svy96.fsf_-_@x220.int.ebiederm.org> In-Reply-To: <87wo7svy96.fsf_-_@x220.int.ebiederm.org> From: Jann Horn Date: Tue, 10 Mar 2020 20:16:47 +0100 Message-ID: Subject: Re: [PATCH] pidfd: Stop taking cred_guard_mutex To: "Eric W. Biederman" Cc: Christian Brauner , Bernd Edlinger , Kees Cook , 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" , Arnd Bergmann , Sargun Dhillon Content-Type: text/plain; charset="UTF-8" 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 7:54 PM Eric W. Biederman wrote: > During exec some file descriptors are closed and the files struct is > unshared. But all of that can happen at other times and it has the > same protections during exec as at ordinary times. So stop taking the > cred_guard_mutex as it is useless. > > Furthermore he cred_guard_mutex is a bad idea because it is deadlock > prone, as it is held in serveral while waiting possibly indefinitely > for userspace to do something. Please don't. Just use the new exec_update_mutex like everywhere else. > Cc: Sargun Dhillon > Cc: Christian Brauner > Cc: Arnd Bergmann > Fixes: 8649c322f75c ("pid: Implement pidfd_getfd syscall") > Signed-off-by: "Eric W. Biederman" > --- > kernel/pid.c | 6 ------ > 1 file changed, 6 deletions(-) > > Christian if you don't have any objections I will take this one through > my tree. > > I tried to figure out why this code path takes the cred_guard_mutex and > the archive on lore.kernel.org was not helpful in finding that part of > the conversation. That was my suggestion. > diff --git a/kernel/pid.c b/kernel/pid.c > index 60820e72634c..53646d5616d2 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -577,17 +577,11 @@ static struct file *__pidfd_fget(struct task_struct *task, int fd) > struct file *file; > int ret; > > - ret = mutex_lock_killable(&task->signal->cred_guard_mutex); > - if (ret) > - return ERR_PTR(ret); > - > if (ptrace_may_access(task, PTRACE_MODE_ATTACH_REALCREDS)) > file = fget_task(task, fd); > else > file = ERR_PTR(-EPERM); > > - mutex_unlock(&task->signal->cred_guard_mutex); > - > return file ?: ERR_PTR(-EBADF); > } If you make this change, then if this races with execution of a setuid program that afterwards e.g. opens a unix domain socket, an attacker will be able to steal that socket and inject messages into communication with things like DBus. procfs currently has the same race, and that still needs to be fixed, but at least procfs doesn't let you open things like sockets because they don't have a working ->open handler, and it enforces the normal permission check for opening files.