From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-efi@vger.kernel.org, linux-btrfs@vger.kernel.org,
yuchao0@huawei.com, linux-mm@kvack.org, clm@fb.com,
adilger.kernel@dilger.ca, matthew.garrett@nebula.com,
linux-nilfs@vger.kernel.org, hch@infradead.org,
linux-ext4@vger.kernel.org, devel@lists.orangefs.org,
josef@toxicpanda.com, reiserfs-devel@vger.kernel.org,
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
Subject: Re: [PATCH 5/5] vfs: don't allow writes to swap files
Date: Wed, 26 Jun 2019 09:28:31 -0700 [thread overview]
Message-ID: <20190626162831.GF5171@magnolia> (raw)
In-Reply-To: <20190626035151.GA10613@ZenIV.linux.org.uk>
On Wed, Jun 26, 2019 at 04:51:51AM +0100, Al Viro wrote:
> On Tue, Jun 25, 2019 at 07:33:31PM -0700, Darrick J. Wong wrote:
> > --- a/fs/attr.c
> > +++ b/fs/attr.c
> > @@ -236,6 +236,9 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
> > if (IS_IMMUTABLE(inode))
> > return -EPERM;
> >
> > + if (IS_SWAPFILE(inode))
> > + return -ETXTBSY;
> > +
> > if ((ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) &&
> > IS_APPEND(inode))
> > return -EPERM;
>
> Er... So why exactly is e.g. chmod(2) forbidden for swapfiles? Or touch(1),
> for that matter...
Oops, that check is overly broad; I think the only attribute change we
need to filter here is ATTR_SIZE.... which we could do unconditionally
in inode_newsize_ok.
What's the use case for allowing userspace to increase the size of an
active swapfile? I don't see any; the kernel has a permanent lease on
the file space mapping (at least until swapoff)...
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index 596ac98051c5..1ca4ee8c2d60 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -3165,6 +3165,19 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> > if (error)
> > goto bad_swap;
> >
> > + /*
> > + * Flush any pending IO and dirty mappings before we start using this
> > + * swap file.
> > + */
> > + if (S_ISREG(inode->i_mode)) {
> > + inode->i_flags |= S_SWAPFILE;
> > + error = inode_drain_writes(inode);
> > + if (error) {
> > + inode->i_flags &= ~S_SWAPFILE;
> > + goto bad_swap;
> > + }
> > + }
>
> Why are swap partitions any less worthy of protection?
Hmm, yeah, S_SWAPFILE should apply to block devices too. I figured that
the mantra of "sane tools will open block devices with O_EXCL" should
have sufficed, but there's really no reason to allow that either.
--D
prev parent reply other threads:[~2019-06-26 16:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-26 2:32 [PATCH v5 0/5] vfs: make immutable files actually immutable Darrick J. Wong
2019-06-26 2:33 ` [PATCH 1/5] mm/fs: don't allow writes to immutable files Darrick J. Wong
2019-06-26 2:33 ` [PATCH 2/5] vfs: flush and wait for io when setting the immutable flag via SETFLAGS Darrick J. Wong
2019-06-26 2:33 ` [PATCH 3/5] vfs: flush and wait for io when setting the immutable flag via FSSETXATTR Darrick J. Wong
2019-06-26 2:33 ` [PATCH 4/5] vfs: don't allow most setxattr to immutable files Darrick J. Wong
2019-06-26 2:33 ` [PATCH 5/5] vfs: don't allow writes to swap files Darrick J. Wong
2019-06-26 3:51 ` Al Viro
2019-06-26 16:28 ` Darrick J. Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190626162831.GF5171@magnolia \
--to=darrick.wong@oracle.com \
--cc=adilger.kernel@dilger.ca \
--cc=ard.biesheuvel@linaro.org \
--cc=clm@fb.com \
--cc=devel@lists.orangefs.org \
--cc=dsterba@suse.com \
--cc=hch@infradead.org \
--cc=jack@suse.com \
--cc=jaegeuk@kernel.org \
--cc=jk@ozlabs.org \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=matthew.garrett@nebula.com \
--cc=ocfs2-devel@oss.oracle.com \
--cc=reiserfs-devel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=yuchao0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).