From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id B41666B0732 for ; Fri, 9 Nov 2018 18:14:06 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id 87-v6so2619118pfq.8 for ; Fri, 09 Nov 2018 15:14:06 -0800 (PST) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u16-v6sor11059049plq.14.2018.11.09.15.14.05 for (Google Transport Security); Fri, 09 Nov 2018 15:14:05 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v3 resend 1/2] mm: Add an F_SEAL_FUTURE_WRITE seal to memfd From: Andy Lutomirski In-Reply-To: Date: Fri, 9 Nov 2018 15:14:02 -0800 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20181108041537.39694-1-joel@joelfernandes.org> Sender: owner-linux-mm@kvack.org List-ID: To: Daniel Colascione Cc: Jann Horn , Joel Fernandes , kernel list , John Reck , John Stultz , Todd Kjos , Greg Kroah-Hartman , Christoph Hellwig , Al Viro , Andrew Morton , Bruce Fields , Jeff Layton , Khalid Aziz , Lei.Yang@windriver.com, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Linux-MM , marcandre.lureau@redhat.com, Mike Kravetz , Minchan Kim , Shuah Khan , valdis.kletnieks@vt.edu, Hugh Dickins , Linux API > On Nov 9, 2018, at 2:42 PM, Daniel Colascione wrote: >=20 > On Fri, Nov 9, 2018 at 2:37 PM, Andy Lutomirski wrot= e: >>> Another, more general fix might be to prevent /proc/pid/fd/N opens >>> from "upgrading" access modes. But that'd be a bigger ABI break. >>=20 >> I think we should fix that, too. I consider it a bug fix, not an ABI bre= ak, personally. >=20 > Someone, somewhere is probably relying on it though, and that means > that we probably can't change it unless it's actually causing > problems. >=20 > spacebar heating I think it has caused problems in the past. It=E2=80=99s certainly extremely= surprising behavior. I=E2=80=99d say it should be fixed and, if needed, a s= ysctl to unfix it might be okay. >=20 >>>> That aside: I wonder whether a better API would be something that >>>> allows you to create a new readonly file descriptor, instead of >>>> fiddling with the writability of an existing fd. >>>=20 >>> That doesn't work, unfortunately. The ashmem API we're replacing with >>> memfd requires file descriptor continuity. I also looked into opening >>> a new FD and dup2(2)ing atop the old one, but this approach doesn't >>> work in the case that the old FD has already leaked to some other >>> context (e.g., another dup, SCM_RIGHTS). See >>> https://developer.android.com/ndk/reference/group/memory. We can't >>> break ASharedMemory_setProt. >>=20 >>=20 >> Hmm. If we fix the general reopen bug, a way to drop write access from a= n existing struct file would do what Android needs, right? I don=E2=80=99t k= now if there are general VFS issues with that. >=20 > I also proposed that. :-) Maybe it'd work best as a special case of > the perennial revoke(2) that people keep proposing. You'd be able to > selectively revoke all access or just write access. Sounds good to me, modulo possible races, but that shouldn=E2=80=99t be too h= ard to deal with.=