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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 84741C10F25 for ; Fri, 6 Mar 2020 22:32:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4692A206E6 for ; Fri, 6 Mar 2020 22:32:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4692A206E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xmission.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DC06B6B0003; Fri, 6 Mar 2020 17:32:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D702E6B0006; Fri, 6 Mar 2020 17:32:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C38236B0007; Fri, 6 Mar 2020 17:32:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id AC1346B0003 for ; Fri, 6 Mar 2020 17:32:09 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6FC0F180AD804 for ; Fri, 6 Mar 2020 22:32:09 +0000 (UTC) X-FDA: 76566386778.07.tiger14_872efa9af5825 X-HE-Tag: tiger14_872efa9af5825 X-Filterd-Recvd-Size: 7709 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Mar 2020 22:32:08 +0000 (UTC) Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jALVa-00024g-VC; Fri, 06 Mar 2020 15:31:55 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jALVa-0002B2-6m; Fri, 06 Mar 2020 15:31:54 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Bernd Edlinger Cc: Christian Brauner , Kees Cook , 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" References: <202003021531.C77EF10@keescook> <20200303085802.eqn6jbhwxtmz4j2x@wittgenstein> <87v9nlii0b.fsf@x220.int.ebiederm.org> <87a74xi4kz.fsf@x220.int.ebiederm.org> <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87imjicxjw.fsf_-_@x220.int.ebiederm.org> <87k13yawpp.fsf@x220.int.ebiederm.org> <87sgil87s3.fsf@x220.int.ebiederm.org> Date: Fri, 06 Mar 2020 16:29:39 -0600 In-Reply-To: <87sgil87s3.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Fri, 06 Mar 2020 15:58:52 -0600") Message-ID: <87a74t86cs.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1jALVa-0002B2-6m;;;mid=<87a74t86cs.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+eje1q6R54wdjNfMaNYFoLyq/4r+j8hDE= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH 2/2] exec: Add a exec_update_mutex to replace cred_guard_mutex X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) 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: ebiederm@xmission.com (Eric W. Biederman) writes: > Bernd Edlinger writes: > >> On 3/6/20 6:17 AM, Eric W. Biederman wrote: >>> Bernd Edlinger writes: >>> >>>> On 3/5/20 10:16 PM, Eric W. Biederman wrote: >>>>> >>>>> The cred_guard_mutex is problematic. The cred_guard_mutex is held >>>>> over the userspace accesses as the arguments from userspace are read. >>>>> The cred_guard_mutex is held of PTRACE_EVENT_EXIT as the the other >>>>> threads are killed. The cred_guard_mutex is held over >>>>> "put_user(0, tsk->clear_child_tid)" in exit_mm(). >>>>> >> >> I am all for this patch, and the direction it is heading, Eric. >> >> I just wanted to add a note that I think it is >> possible that exec_mm_release can also invoke put_user(0, tsk->clear_child_tid), >> under the new exec_update_mutex, since vm_access increments the >> mm->mm_users, under the cred_update_mutex, but releases the mutex, >> and the caller can hold the reference for a while and then exec_mmap is not >> releasing the last reference. > > Good catch. I really appreciate your close look at the details. > > I am wondering if process_vm_readv and process_vm_writev could be > safely changed to use mmgrab and mmdrop, instead of mmget and mmput. > > That would resolve the potential issue you have pointed out. I just > haven't figured out if it is safe. The mm code has been seriously > refactored since I knew how it all worked. Nope, mmget can not be replaced by mmgrab. It might be possible to do something creative like store a cred in place of the userns on the mm and use that for mm_access permission checks. Still we are talking a pretty narrow window, and a case that no one has figured out how to trigger yet. So I will leave that corner case as something for future improvements. Eric