Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp638909ybh; Wed, 11 Mar 2020 07:57:52 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt9nUIJqVzxTFpy68V9tECS1xR4lkMLU0U0Ft2tt8lnr3isuOQZg9lvdwehhWIKCqxkspWU X-Received: by 2002:aca:c70f:: with SMTP id x15mr2204096oif.80.1583938671952; Wed, 11 Mar 2020 07:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583938671; cv=none; d=google.com; s=arc-20160816; b=DKVNdwBwe6nFxN2gR+RbIfv9qb2OX2IZXHo+fS2NQ4emGCp2o2m355C1AdLgojWVbm vXOt6miI4qav/xfkj8EA5yPCppfq4O9PSCLffTn4M4cUUkw/WMBJY78Y7zFHsKypVgO/ 9gO2OlPFaB9MhRZdPQ8FnGhofELlj8eBGdg86OBgPWvu+7y5axljxRJs14+tEd0gZqUW LrUajZKBcIwcFAw000klvBeLiXm0oV21ErSQmje49xF2f1b79Wp4qtR5FkSweikh1MVH PiySQ//jDxhfa0Pcu4qAGLkmYeuy7gihfP8ozktmhfhyOyKuk2JabxU/nB69nZ3XTrmr tMYA== 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=ouxKLWRXOtqbKDl0q+UmOju78v5owF0LnUPYL3Cn3Kg=; b=eDPadObNBX/TH2lEa7G/4AuKAitDMc7JSxzFBnlC1fopPKx54bkvdGRdmStt48+87Z gRzVKbmHy6YFn6EOOQl5SpwRJ+DSTWVxPy3u3FOttWQbYG5mzpR4ECEphL7P8zOFlUEl R2uYllz/5L4OD49ZofGYX+VEaz+2SFL8oemowfB+dK2bcB6mMJbVBni9JGnLY05dT4K1 281Sqzjb5piPLFVyyD7eCPcwItHSTnAR3Hpe8xnhyZ6vodAf3u054XGa+O9bhP7TmWvS W/B4OcdW1UgYG9mm+vB062IXLB1M+sKzm6XumQtNuFaasWq5v2NyeoFj27vhyE4wHPvn cFxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Xc7KTwBm; 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 t18si1305451otd.269.2020.03.11.07.57.40; Wed, 11 Mar 2020 07:57:51 -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=Xc7KTwBm; 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 S1729954AbgCKO4f (ORCPT + 99 others); Wed, 11 Mar 2020 10:56:35 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:40705 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729844AbgCKO4e (ORCPT ); Wed, 11 Mar 2020 10:56:34 -0400 Received: by mail-ot1-f65.google.com with SMTP id h17so2239101otn.7 for ; Wed, 11 Mar 2020 07:56:34 -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=ouxKLWRXOtqbKDl0q+UmOju78v5owF0LnUPYL3Cn3Kg=; b=Xc7KTwBmSvnyR04w7xAsoM4QolF0XcaryYGGSqywW6r0XlqYx9XvikGX4w7bLlxxLJ 7Q9AwD+7i/TJ2mStAI9eb2ob9VCt6KgwBw+LR3gAYpgM3S9uQWoNLD+xlKhWnCsJiDsd gQ/4BkYOpVHRSRCowJu6XRQFruet41lwL6gwC6z3ZSErV3n8O+X2f+eZSuo5E01C3UV8 tyeHf9B1wPr69eyCIlYMAQR5+WIsB75Z+R5FBKu1iRw02ws17iiqnH3dVPNo9lJU7J88 tpacvkSbf6Ri5ZPR6z68IF56hdGSxpTT8rbI4/vpexPf/ozipoU+b1l6PAcyKYZfa7Y6 rVAg== 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=ouxKLWRXOtqbKDl0q+UmOju78v5owF0LnUPYL3Cn3Kg=; b=EhWBB/lMmsQMLIs1luamco0Qcugt5H7+EljwbsnnWY9VFrv07aAAwlxOfTuGp7EYZ/ hEgUC/HmHy24XL5g7Vojs6RP54wfQ4+tx1WcglxSTUS3HlisNrrbqbvch//bH9nwJvxs +Nh8pLjAS21m0QjCwje/kuoJMWsfzMXf0LypNNN6vr49VLFeUZpTnk521wqbVllO7vF6 lU3OSx17c+obJL45nYtARRvxMimh7QVEVt9dHxE8hUNToIPaRkVsM3tvqNFZiAkfTHi3 yyl0ePuepQey5btUMVdR6fLElkDKs3qZ09ecb2jDbH/WJJukNZonghJDoZpMRatite0x /iVg== X-Gm-Message-State: ANhLgQ3HRvo5L+0Vug0bcEE1RaXwsh/6+JLkjJOjseMuz88iQC3fB8+F 0qDL2Q1xfaYwSbus/28lBT9tXQk+B+Z/8jVy/u3Mdw== X-Received: by 2002:a4a:a8c6:: with SMTP id r6mr553536oom.21.1583938593523; Wed, 11 Mar 2020 07:56:33 -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> <87k13sui1p.fsf@x220.int.ebiederm.org> <5a8b2794-b498-af33-1327-ff2861cff83f@hotmail.de> In-Reply-To: <5a8b2794-b498-af33-1327-ff2861cff83f@hotmail.de> From: Jann Horn Date: Wed, 11 Mar 2020 15:56:07 +0100 Message-ID: Subject: Re: [PATCH] pidfd: Stop taking cred_guard_mutex To: Bernd Edlinger Cc: "Eric W. Biederman" , Christian Brauner , Kees Cook , Jonathan Corbet , Alexander Viro , Andrew Morton , "adobriyan@gmail.com" , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , "avagin@gmail.com" , Ingo Molnar , "Peter Zijlstra (Intel)" , "duyuyang@gmail.com" , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , "gregkh@linuxfoundation.org" , Shakeel Butt , Jason Gunthorpe , "christian@kellner.me" , 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@sargun.me" 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 Wed, Mar 11, 2020 at 7:12 AM Bernd Edlinger wrote: > On 3/10/20 9:22 PM, Bernd Edlinger wrote: > > On 3/10/20 9:10 PM, Jann Horn wrote: > >> On Tue, Mar 10, 2020 at 9:00 PM Jann Horn wrote: > >>> On Tue, Mar 10, 2020 at 8:29 PM Eric W. Biederman wrote: > >>>> Jann Horn writes: > >>>>> 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. > >> [...] > >>>>> 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. > >>>> > >>>> It isn't only exec that can change credentials. Do we need a lock for > >>>> changing credentials? > >> [...] > >>>> If we need a lock around credential change let's design and build that. > >>>> Having a mismatch between what a lock is designed to do, and what > >>>> people use it for can only result in other bugs as people get confused. > >>> > >>> Hmm... what benefits do we get from making it a separate lock? I guess > >>> it would allow us to make it a per-task lock instead of a > >>> signal_struct-wide one? That might be helpful... > >> > >> But actually, isn't the core purpose of the cred_guard_mutex to guard > >> against concurrent credential changes anyway? That's what almost > >> everyone uses it for, and it's in the name... > >> > > > > The main reason d'etre of exec_update_mutex is to get a consitent > > view of task->mm and task credentials. > > > The reason why you want the cred_guard_mutex, is that some action > > is changing the resulting credentials that the execve is about > > to install, and that is the data flow in the opposite direction. > > > > So in other words, you need the exec_update_mutex when you > access another thread's credentials and possibly the mmap at the > same time. Or the file descriptor table, or register state, ... > You need no mutex at all when you are just accessing or > even changing the credentials of the current thread. (If another > thread is doing execve, your task will be killed, and wether > or not the credentials were changed does not matter any more) Only if the only access checks you care about are those related to mm access.