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=-14.4 required=3.0 tests=DKIMWL_WL_MED,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, USER_IN_DEF_DKIM_WL 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 10113C10F27 for ; Tue, 10 Mar 2020 19:17:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BDEB321D56 for ; Tue, 10 Mar 2020 19:17:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qnpTPsDr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDEB321D56 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 674346B0070; Tue, 10 Mar 2020 15:17:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 624426B0071; Tue, 10 Mar 2020 15:17:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5397B6B0072; Tue, 10 Mar 2020 15:17:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 3B0606B0070 for ; Tue, 10 Mar 2020 15:17:18 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BCDF1181AC9CB for ; Tue, 10 Mar 2020 19:17:17 +0000 (UTC) X-FDA: 76580410914.14.name62_79d95aa5fd359 X-HE-Tag: name62_79d95aa5fd359 X-Filterd-Recvd-Size: 6939 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 19:17:17 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id p125so15057953oif.10 for ; Tue, 10 Mar 2020 12:17:17 -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=QmfPqk62079xcKMiUwSWIXTfBYR6w9b8paCvhU0Jyu3nYO/KwkDDfK/OYpW9ql6tXV IiPVRpAXW+r6/YSDHuY4IXcnm7HFb0SlXsXQqccMoZGR7xcjk0XoIgKcZq5/ULV1JLv1 p5nM6DQlMb/usrTPkL53GrVP+kjtiRoqKhLq6QuZa99Sb7ukgDHIn5pk6sd1cdz0hwrE 611NS1WdOfO7ONQ5Ytg0EGQ1RugnrCINuhOMH44uNL2DMLuW1KiMEJGQzzjcP1efODCC kEafr6uW8xc2aiemva/mKtEUt5kbknrDvXpBcmEJrIMMGmoKJ2rx/3RrNEyVg7DQ054t IGzw== X-Gm-Message-State: ANhLgQ1OnLfYlYll+3hA8NJ+N/rr6Af7pcwEXZYUnnRgTlNJ6F1jb1Uz tTMT8uDxUK4N24fed0HNxENlM6m6pznTu0KpSyw/tw== X-Google-Smtp-Source: ADFU+vsLvhXTBZ0tYPXPJFbFEFKJ1zpqw9g6M/LvL7QhBPk7VyK2ei/FKMF/yhX24G0+fYimQ7ZdrPegjHcj9wiKoYo= 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.