diff mbox series

ceph: add proper offset validation check to ceph_setattr()

Message ID 20180805113301.6230-1-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show
Series ceph: add proper offset validation check to ceph_setattr() | expand

Commit Message

Chengguang Xu Aug. 5, 2018, 11:33 a.m. UTC
ceph_setattr() finally calls vfs function inode_newsize_ok()
to do offset validation and that is based on sb->s_maxbytes.
Because we set sb->s_maxbytes to MAX_LFS_FILESIZE to through
VFS check and do proper offset validation in cephfs level,
we need adding proper offset validation before calling
inode_newsize_ok().

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/ceph/inode.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 7a7b76ad876a..bea5f5e9e0f9 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2165,11 +2165,16 @@  int __ceph_setattr(struct inode *inode, struct iattr *attr)
 int ceph_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
+	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
 	int err;
 
 	if (ceph_snap(inode) != CEPH_NOSNAP)
 		return -EROFS;
 
+	if ((attr->ia_valid & ATTR_SIZE) &&
+		(attr->ia_size > max(inode->i_size, fsc->max_file_size)))
+		return -EFBIG;
+
 	err = setattr_prepare(dentry, attr);
 	if (err != 0)
 		return err;