From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Darrick J. Wong" Subject: Re: [PATCH 1/6] mm/fs: don't allow writes to immutable files Date: Thu, 20 Jun 2019 15:13:06 -0700 Message-ID: <20190620221306.GD5375@magnolia> References: <156022836912.3227213.13598042497272336695.stgit@magnolia> <156022837711.3227213.11787906519006016743.stgit@magnolia> <20190620215212.GG4650@mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : message-id : references : mime-version : in-reply-to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : content-type : content-transfer-encoding : sender; s=corp-2018-07-02; bh=tqJz7v5/HLhf8O2de0JWt/FPzmqk70T7mGC+iPW7h9w=; b=pP5EViUuWkJDfC/tY9g/75vU/Wt+fro7Z7dA6mtbAPTwX9eFKAZt9BxAjOA/I0ZaBKym IuGBQW1Wmr6MdRgrjvRvmj4ddlOc/sn9bqVYNfRhb0vyIvLc/FO3PhMUN39yZlbGHKxa kHb0X5zWgo+9xkgCapdrByX3BgEPdA/tkYhsVCmHYE7Csn7KqRsXRElcd0okrI9wo3Sp XDUlGs1+3gdq+/4cJuJCSEUvQtxAVSLUSKtfwe7Zrp+DZ27RUo5ARaeR3Thly4hhBnks ploE2KucA8UwhI1u0Z6R6PUpOAGXjHMeRoTDVDtvBmImUHGXVuDyEBWE2CiOOLubDYcl GA== Content-Disposition: inline In-Reply-To: <20190620215212.GG4650@mit.edu> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com To: Theodore Ts'o , matthew.garrett@nebula.com, yuchao0@huawei.com, ard.biesheuvel@linaro.org, josef@toxicpanda.com, clm@fb.com, adilger.kernel@dilger.ca, viro@zeniv.linux.org.uk, jack@suse.com, dsterba@suse.com, jaegeuk@kernel.org, jk@ozlabs.org, reiserfs-devel@vger.kernel.org, linux-efi@vger.kernel.org, devel@lists.orangefs.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org On Thu, Jun 20, 2019 at 05:52:12PM -0400, Theodore Ts'o wrote: > On Mon, Jun 10, 2019 at 09:46:17PM -0700, Darrick J. Wong wrote: > > From: Darrick J. Wong > > > > The chattr manpage has this to say about immutable files: > > > > "A file with the 'i' attribute cannot be modified: it cannot be deleted > > or renamed, no link can be created to this file, most of the file's > > metadata can not be modified, and the file can not be opened in write > > mode." > > > > Once the flag is set, it is enforced for quite a few file operations, > > such as fallocate, fpunch, fzero, rm, touch, open, etc. However, we > > don't check for immutability when doing a write(), a PROT_WRITE mmap(), > > a truncate(), or a write to a previously established mmap. > > > > If a program has an open write fd to a file that the administrator > > subsequently marks immutable, the program still can change the file > > contents. Weird! > > > > The ability to write to an immutable file does not follow the manpage > > promise that immutable files cannot be modified. Worse yet it's > > inconsistent with the behavior of other syscalls which don't allow > > modifications of immutable files. > > > > Therefore, add the necessary checks to make the write, mmap, and > > truncate behavior consistent with what the manpage says and consistent > > with other syscalls on filesystems which support IMMUTABLE. > > > > Signed-off-by: Darrick J. Wong > > I note that this patch doesn't allow writes to swap files. So Amir's > generic/554 test will still fail for those file systems that don't use > copy_file_range. I didn't add any IS_SWAPFILE checks here, so I'm not sure to what you're referring? > I'm indifferent as to whether you add a new patch, or include that > change in this patch, but perhaps we should fix this while we're > making changes in these code paths? The swapfile patches should be in a separate patch, which I was planning to work on but hadn't really gotten around to it. --D > - Ted