From: Omar Sandoval Date: Thu, 8 Jan 2015 09:18:30 +0000 (-0800) Subject: nfs: prevent truncate on active swapfile X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3a7ed3fff3bb22828f7d7ba6b75c7d22ee54df38;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git nfs: prevent truncate on active swapfile 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 truncating a swapfile can't possibly be good. Signed-off-by: Omar Sandoval Signed-off-by: Trond Myklebust --- diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 2211f6ba8736..d2398c193bda 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -507,10 +507,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 */