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=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable 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 435F2C43613 for ; Mon, 24 Jun 2019 11:14:05 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10CB2208E3; Mon, 24 Jun 2019 11:14:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="XzxLXYZb"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="Z+3O98ao" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10CB2208E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1hfMv6-0007uA-HN; Mon, 24 Jun 2019 11:13:56 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hfMv5-0007u1-Uc for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2019 11:13:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; 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=4ohSn2mg7XvN0khmY8SV975QiTEy30oR4Ocu/GECpYg=; b=XzxLXYZbGZQNsVE4hMDYGs5txW HJ2lo03COvxhWo6N4yZP/KSECQ3UFsT7PeIETI1Ph0NtuPMUz9Vc6xPl21JsAICC14qL5ro/99quK upkrn2d+v8zGbSslqwjz42lVs3hgnkMjSXZcrYvUJ1eTbVM/qNI8ZM/L9jGJAzaRz0Xg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; 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=4ohSn2mg7XvN0khmY8SV975QiTEy30oR4Ocu/GECpYg=; b=Z+3O98aoD/1I1qSdalgCJRdyZA QGPDC++RQLZgx+43PJIYV1rkebJvhKiYbfiXn40WH1GFylDWoTt/mh0iRj+z9LrG762RoVWY2VI9g Agld6JyZiN5qHwGC/43adSi/CfbV5E/wz77geFssAPLk114wFxaGV3l5w/BnHvDBDHcY=; Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1hfMvA-007i1g-3m for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jun 2019 11:14:02 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EE700AC20; Mon, 24 Jun 2019 11:13:51 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6211D1E2F23; Mon, 24 Jun 2019 13:13:49 +0200 (CEST) Date: Mon, 24 Jun 2019 13:13:49 +0200 From: Jan Kara To: "Darrick J. Wong" Message-ID: <20190624111349.GF32376@quack2.suse.cz> References: <156116141046.1664939.11424021489724835645.stgit@magnolia> <156116141836.1664939.12249697737780481978.stgit@magnolia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <156116141836.1664939.12249697737780481978.stgit@magnolia> User-Agent: Mutt/1.10.1 (2018-07-13) X-Headers-End: 1hfMvA-007i1g-3m Subject: Re: [f2fs-dev] [PATCH 1/7] mm/fs: don't allow writes to immutable files X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, clm@fb.com, adilger.kernel@dilger.ca, matthew.garrett@nebula.com, linux-nilfs@vger.kernel.org, linux-ext4@vger.kernel.org, devel@lists.orangefs.org, josef@toxicpanda.com, reiserfs-devel@vger.kernel.org, viro@zeniv.linux.org.uk, dsterba@suse.com, jaegeuk@kernel.org, tytso@mit.edu, ard.biesheuvel@linaro.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, jk@ozlabs.org, jack@suse.com, linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org, ocfs2-devel@oss.oracle.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Fri 21-06-19 16:56:58, 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 Looks good to me. You can add: Reviewed-by: Jan Kara Honza > --- > fs/attr.c | 13 ++++++------- > mm/filemap.c | 3 +++ > mm/memory.c | 3 +++ > mm/mmap.c | 8 ++++++-- > 4 files changed, 18 insertions(+), 9 deletions(-) > > > diff --git a/fs/attr.c b/fs/attr.c > index d22e8187477f..1fcfdcc5b367 100644 > --- a/fs/attr.c > +++ b/fs/attr.c > @@ -233,19 +233,18 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de > > WARN_ON_ONCE(!inode_is_locked(inode)); > > - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) { > - if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) > - return -EPERM; > - } > + if (IS_IMMUTABLE(inode)) > + return -EPERM; > + > + if ((ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) && > + IS_APPEND(inode)) > + return -EPERM; > > /* > * If utimes(2) and friends are called with times == NULL (or both > * times are UTIME_NOW), then we need to check for write permission > */ > if (ia_valid & ATTR_TOUCH) { > - if (IS_IMMUTABLE(inode)) > - return -EPERM; > - > if (!inode_owner_or_capable(inode)) { > error = inode_permission(inode, MAY_WRITE); > if (error) > diff --git a/mm/filemap.c b/mm/filemap.c > index aac71aef4c61..dad85e10f5f8 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2935,6 +2935,9 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) > loff_t count; > int ret; > > + if (IS_IMMUTABLE(inode)) > + return -EPERM; > + > if (!iov_iter_count(from)) > return 0; > > diff --git a/mm/memory.c b/mm/memory.c > index ddf20bd0c317..4311cfdade90 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2235,6 +2235,9 @@ static vm_fault_t do_page_mkwrite(struct vm_fault *vmf) > > vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE; > > + if (vmf->vma->vm_file && IS_IMMUTABLE(file_inode(vmf->vma->vm_file))) > + return VM_FAULT_SIGBUS; > + > ret = vmf->vma->vm_ops->page_mkwrite(vmf); > /* Restore original flags so that caller is not surprised */ > vmf->flags = old_flags; > diff --git a/mm/mmap.c b/mm/mmap.c > index 7e8c3e8ae75f..ac1e32205237 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1483,8 +1483,12 @@ unsigned long do_mmap(struct file *file, unsigned long addr, > case MAP_SHARED_VALIDATE: > if (flags & ~flags_mask) > return -EOPNOTSUPP; > - if ((prot&PROT_WRITE) && !(file->f_mode&FMODE_WRITE)) > - return -EACCES; > + if (prot & PROT_WRITE) { > + if (!(file->f_mode & FMODE_WRITE)) > + return -EACCES; > + if (IS_IMMUTABLE(file_inode(file))) > + return -EPERM; > + } > > /* > * Make sure we don't allow writing to an append-only > > -- Jan Kara SUSE Labs, CR _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel