* [PATCH] nfs: prevent truncate on active swapfile
@ 2014-12-19 6:29 Omar Sandoval
2014-12-19 6:48 ` Omar Sandoval
0 siblings, 1 reply; 2+ messages in thread
From: Omar Sandoval @ 2014-12-19 6:29 UTC (permalink / raw)
To: Trond Myklebust, linux-nfs-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Cc: Al Viro, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA, Omar Sandoval
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-nWWhXC5lh1RBDgjK7y7TUQ@public.gmane.org>
---
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
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] nfs: prevent truncate on active swapfile
2014-12-19 6:29 [PATCH] nfs: prevent truncate on active swapfile Omar Sandoval
@ 2014-12-19 6:48 ` Omar Sandoval
0 siblings, 0 replies; 2+ messages in thread
From: Omar Sandoval @ 2014-12-19 6:48 UTC (permalink / raw)
To: Trond Myklebust, linux-nfs, linux-kernel; +Cc: Al Viro, linux-fsdevel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-19 6:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-19 6:29 [PATCH] nfs: prevent truncate on active swapfile Omar Sandoval
2014-12-19 6:48 ` Omar Sandoval
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).