linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Trond Myklebust <trond.myklebust@primarydata.com>,
	linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Al Viro <viro@ZenIV.linux.org.uk>, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] nfs: prevent truncate on active swapfile
Date: Thu, 18 Dec 2014 22:48:20 -0800	[thread overview]
Message-ID: <20141219064820.GA12864@mew> (raw)
In-Reply-To: <13e8abe52a18c4e46ce497ff299774700cd7e1d0.1418970310.git.osandov@osandov.com>

On Thu, Dec 18, 2014 at 10:29:18PM -0800, Omar Sandoval wrote:
> Most filesystems prevent truncation of an active swapfile by way of
> inode_newsize_ok, called from inode_change_ok. NFS doesn't call either
> from nfs_setattr, presumably because most of these checks are expected
> to be done server-side. However, the IS_SWAPFILE check can only be done
> client-side, and not doing so is dangerous.
> 
> Signed-off-by: Omar Sandoval <osandov@osandov.com>
> ---
>  fs/nfs/inode.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
> index 4bffe63..9205513 100644
> --- a/fs/nfs/inode.c
> +++ b/fs/nfs/inode.c
> @@ -506,10 +506,15 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
>  		attr->ia_valid &= ~ATTR_MODE;
>  
>  	if (attr->ia_valid & ATTR_SIZE) {
> +		loff_t i_size;
> +
>  		BUG_ON(!S_ISREG(inode->i_mode));
>  
> -		if (attr->ia_size == i_size_read(inode))
> +		i_size = i_size_read(inode);
> +		if (attr->ia_size == i_size)
>  			attr->ia_valid &= ~ATTR_SIZE;
> +		else if (attr->ia_size < i_size && IS_SWAPFILE(inode))
> +			return -ETXTBSY;
>  	}
>  
>  	/* Optimization: if the end result is no change, don't RPC */
> -- 
> 2.2.0
> 
Sorry, forgot to mention that this applies to Linus' tree as of today.

-- 
Omar

      reply	other threads:[~2014-12-19  6:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-19  6:29 [PATCH] nfs: prevent truncate on active swapfile Omar Sandoval
2014-12-19  6:48 ` Omar Sandoval [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=20141219064820.GA12864@mew \
    --to=osandov@osandov.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    --cc=viro@ZenIV.linux.org.uk \
    /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).