From e897a23eb13bafcf9c38d2fc37ae57a7729d9a02 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 24 Sep 2018 17:11:25 -0700 Subject: Fix statfs(2) for 32-bit user space When handling a 32-bit statfs() system call the returned fields, although 64-bit in the kernel, must be limited to 32-bits or an EOVERFLOW error will be returned. This is less of an issue for block counts since the default reported block size in 128KiB. But since it is possible to set a smaller block size, these values will be scaled as needed to fit in a 32-bit unsigned long. Unlike most other filesystems the total possible file counts are more likely to overflow because they are calculated based on the available free space in the pool. In order to prevent this the reported value must be capped at 2^32-1. This is only for statfs(2) reporting, there are no changes to the internal ZFS limits. Reviewed-by: Andreas Dilger Reviewed-by: Richard Yao Signed-off-by: Brian Behlendorf Issue #7927 Closes #7122 Closes #7937 --- module/zfs/zfs_vfsops.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'module/zfs/zfs_vfsops.c') diff --git a/module/zfs/zfs_vfsops.c b/module/zfs/zfs_vfsops.c index 8ae2ef929..205773ef3 100644 --- a/module/zfs/zfs_vfsops.c +++ b/module/zfs/zfs_vfsops.c @@ -1422,8 +1422,6 @@ zfs_statvfs(struct dentry *dentry, struct kstatfs *statp) { zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info; uint64_t refdbytes, availbytes, usedobjs, availobjs; - uint64_t fsid; - uint32_t bshift; int err = 0; ZFS_ENTER(zfsvfs); @@ -1431,7 +1429,7 @@ zfs_statvfs(struct dentry *dentry, struct kstatfs *statp) dmu_objset_space(zfsvfs->z_os, &refdbytes, &availbytes, &usedobjs, &availobjs); - fsid = dmu_objset_fsid_guid(zfsvfs->z_os); + uint64_t fsid = dmu_objset_fsid_guid(zfsvfs->z_os); /* * The underlying storage pool actually uses multiple block * size. Under Solaris frsize (fragment size) is reported as @@ -1443,7 +1441,7 @@ zfs_statvfs(struct dentry *dentry, struct kstatfs *statp) */ statp->f_frsize = zfsvfs->z_max_blksz; statp->f_bsize = zfsvfs->z_max_blksz; - bshift = fls(statp->f_bsize) - 1; + uint32_t bshift = fls(statp->f_bsize) - 1; /* * The following report "total" blocks of various kinds in @@ -1460,7 +1458,7 @@ zfs_statvfs(struct dentry *dentry, struct kstatfs *statp) * static metadata. ZFS doesn't preallocate files, so the best * we can do is report the max that could possibly fit in f_files, * and that minus the number actually used in f_ffree. - * For f_ffree, report the smaller of the number of object available + * For f_ffree, report the smaller of the number of objects available * and the number of blocks (each object will take at least a block). */ statp->f_ffree = MIN(availobjs, availbytes >> DNODE_SHIFT); -- cgit v1.2.3