Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp448190imm; Wed, 17 Oct 2018 02:54:29 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Rde1T6BIMXW7QCSLlxAaa89Q1cytyZ3LTC1hp934sjwy25hdqWESi05vSmDLtwOr/XUed X-Received: by 2002:a62:1a92:: with SMTP id a140-v6mr25600584pfa.219.1539770069776; Wed, 17 Oct 2018 02:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539770069; cv=none; d=google.com; s=arc-20160816; b=F1OAzNCwS6IjcXBbsNX3B9MnfgE7O+TyECOYQCI5t0a/DMp+tzn/z9+fkEGLn0zTDh 6IJXe5wXuMnEs3ioBE8f5sg6zzN7FZxIpI3Jo+sbzDm4Wj0MxYqd6OpxQVHr6T4d+FX4 pvYAIb1a5iMBS1d66jAL6saNgakkTu4vfG1rsNyRvG1IWxyOS6JPErbuv5BtP4UZPyk7 NU7XFweGPK80MyetqjcGVJeMOBn6qT3pn1nBQAk9f8/UfkHq/KEQsR8ELWyPYL5jrRuW XLsN8JYcQI6laMbzzsTy/9H6K5xWQv257OcPCeMVMWOsi8rbXkzf+OyWNKSnAy073cpw 27ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vrlzfuBdGYThbkt5/Dl0UF+Kh8QDAIWULWWa5+4RWMs=; b=HRWCxPTXR0ssKTT7soMqBz37zaTY4ZXJiVS2fYzWDxFKXR1NMdVguJkDy+HSu/qCNC lpN+3uJH3spgu4Ui2Ni8Oj3bPlJPkfV5bHb2Sln6KpjFodyslEzTClx5vpSMr+9VH8Ar ryuf8qF68qu9c5wGUAXIR3bJ3Wsacc5hXdrKZA+2sdixXcNKBsCqBpeQwIqZKFQovmH0 ORPKzNHmKPEyDIV/x+95QJT7tEUUGkLXuxs8RQWvQofsptZH99rtYQ/XJdRamydaFsLV o332QlVDW5leIhKZ0jKhx7BLMim3xZrcR7PkPy0lIB30M7FUnADkZcKLuBU+/DUdbf1Q 3mvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=oQCkdoiC; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3-v6si1612012pgl.516.2018.10.17.02.54.14; Wed, 17 Oct 2018 02:54:29 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=oQCkdoiC; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727213AbeJQRqu (ORCPT + 99 others); Wed, 17 Oct 2018 13:46:50 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:60028 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726994AbeJQRqu (ORCPT ); Wed, 17 Oct 2018 13:46:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vrlzfuBdGYThbkt5/Dl0UF+Kh8QDAIWULWWa5+4RWMs=; b=oQCkdoiCCct0VLXVGE2dZoTlB BEyUtwVATal6prOLgWk6bvg3ESpkbSnjeC/xdu3bwylsTXofrT1JfblaFi6yTjn+c05dA9046X+bR 8XCtflxOLEZYK0IJxTR9EP3sY6euwvm52iL+oXzdTqSZCyw+V0mU7cfAThZ+z8Ek7ebvQYlNlWwRH RPVE3qsMlzKRN0E0mSH/LClkbC5jben2L//OMucrLjaxfN/MFGUtiK1pfiSabaIqr0qQKBENubVvL EWeA0amZjfTGwCZQudI5SwRfeIi19+r8fVCoFoVkFz4g3g3AKPkbQ4NeRManRDtMi7RZc/VUm2g65 YPX291IQw==; Received: from hch by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCiUd-0001zQ-Bf; Wed, 17 Oct 2018 09:51:55 +0000 Date: Wed, 17 Oct 2018 02:51:55 -0700 From: Christoph Hellwig To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, jreck@google.com, john.stultz@linaro.org, tkjos@google.com, gregkh@linuxfoundation.org, Andrew Morton , dancol@google.com, "J. Bruce Fields" , Jeff Layton , Khalid Aziz , linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Mike Kravetz , minchan@google.com, Shuah Khan Subject: Re: [PATCH v2 1/2] mm: Add an F_SEAL_FS_WRITE seal to memfd Message-ID: <20181017095155.GA354@infradead.org> References: <20181009222042.9781-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181009222042.9781-1-joel@joelfernandes.org> User-Agent: Mutt/1.9.2 (2017-12-15) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 09, 2018 at 03:20:41PM -0700, Joel Fernandes (Google) wrote: > One of the main usecases Android has is the ability to create a region > and mmap it as writeable, then drop its protection for "future" writes > while keeping the existing already mmap'ed writeable-region active. s/drop/add/ ? Otherwise this doesn't make much sense to me. > This usecase cannot be implemented with the existing F_SEAL_WRITE seal. > To support the usecase, this patch adds a new F_SEAL_FS_WRITE seal which > prevents any future mmap and write syscalls from succeeding while > keeping the existing mmap active. The following program shows the seal > working in action: Where does the FS come from? I'd rather expect this to be implemented as a 'force' style flag that applies the seal even if the otherwise required precondition is not met. > Note: This seal will also prevent growing and shrinking of the memfd. > This is not something we do in Android so it does not affect us, however > I have mentioned this behavior of the seal in the manpage. This seems odd, as that is otherwise split into the F_SEAL_SHRINK / F_SEAL_GROW flags. > static int memfd_add_seals(struct file *file, unsigned int seals) > { > @@ -219,6 +220,9 @@ static int memfd_add_seals(struct file *file, unsigned int seals) > } > } > > + if ((seals & F_SEAL_FS_WRITE) && !(*file_seals & F_SEAL_FS_WRITE)) > + file->f_mode &= ~(FMODE_WRITE | FMODE_PWRITE); > + This seems to lack any synchronization for f_mode.