git: 2e46b4dab6e9 - stable/13 - filesystems: return error from vn_rlimit_fsize() instead of EFBIG

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 08 Oct 2022 00:39:04 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2e46b4dab6e9c74d9607b17879b301fb69ba0be2

commit 2e46b4dab6e9c74d9607b17879b301fb69ba0be2
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-09-18 14:44:49 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-08 00:29:35 +0000

    filesystems: return error from vn_rlimit_fsize() instead of EFBIG
    
    (cherry picked from commit cc65a412ae226136e6207bdc8db4722dab99982f)
---
 sys/fs/ext2fs/ext2_vnops.c     |  5 +++--
 sys/fs/fuse/fuse_io.c          | 10 ++++++----
 sys/fs/msdosfs/msdosfs_vnops.c |  5 +++--
 sys/fs/nfsclient/nfs_clbio.c   |  5 +++--
 sys/fs/smbfs/smbfs_io.c        |  5 +++--
 sys/fs/tmpfs/tmpfs_vnops.c     |  6 ++++--
 sys/kern/vfs_vnops.c           |  2 --
 sys/ufs/ffs/ffs_vnops.c        |  5 +++--
 8 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c
index 724690403809..51119ed8d52f 100644
--- a/sys/fs/ext2fs/ext2_vnops.c
+++ b/sys/fs/ext2fs/ext2_vnops.c
@@ -2212,8 +2212,9 @@ ext2_write(struct vop_write_args *ap)
 	 * Maybe this should be above the vnode op call, but so long as
 	 * file servers have no limits, I don't think it matters.
 	 */
-	if (vn_rlimit_fsize(vp, uio, uio->uio_td))
-		return (EFBIG);
+	error = vn_rlimit_fsize(vp, uio, uio->uio_td);
+	if (error != 0)
+		return (error);
 
 	resid = uio->uio_resid;
 	osize = ip->i_size;
diff --git a/sys/fs/fuse/fuse_io.c b/sys/fs/fuse/fuse_io.c
index c70eca17ec29..179ee9e94f43 100644
--- a/sys/fs/fuse/fuse_io.c
+++ b/sys/fs/fuse/fuse_io.c
@@ -338,8 +338,9 @@ fuse_write_directbackend(struct vnode *vp, struct uio *uio,
 	if (ioflag & IO_APPEND)
 		uio_setoffset(uio, filesize);
 
-	if (vn_rlimit_fsize(vp, uio, uio->uio_td))
-		return (EFBIG);
+	err = vn_rlimit_fsize(vp, uio, uio->uio_td);
+	if (err != 0)
+		return (err);
 
 	fdisp_init(&fdi, 0);
 
@@ -493,8 +494,9 @@ fuse_write_biobackend(struct vnode *vp, struct uio *uio,
 	if (ioflag & IO_APPEND)
 		uio_setoffset(uio, filesize);
 
-	if (vn_rlimit_fsize(vp, uio, uio->uio_td))
-		return (EFBIG);
+	err = vn_rlimit_fsize(vp, uio, uio->uio_td);
+	if (err != 0)
+		return (err);
 
 	do {
 		bool direct_append, extending;
diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index 58f7f2876523..86af14784f5b 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -667,8 +667,9 @@ msdosfs_write(struct vop_write_args *ap)
 	/*
 	 * If they've exceeded their filesize limit, tell them about it.
 	 */
-	if (vn_rlimit_fsize(vp, uio, uio->uio_td))
-		return (EFBIG);
+	error = vn_rlimit_fsize(vp, uio, uio->uio_td);
+	if (error != 0)
+		return (error);
 
 	/*
 	 * If the offset we are starting the write at is beyond the end of
diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c
index c89d6796ea00..54943bcdf68b 100644
--- a/sys/fs/nfsclient/nfs_clbio.c
+++ b/sys/fs/nfsclient/nfs_clbio.c
@@ -1034,8 +1034,9 @@ ncl_write(struct vop_write_args *ap)
 	 * Maybe this should be above the vnode op call, but so long as
 	 * file servers have no limits, i don't think it matters
 	 */
-	if (vn_rlimit_fsize(vp, uio, td))
-		return (EFBIG);
+	error = vn_rlimit_fsize(vp, uio, td);
+	if (error != 0)
+		return (error);
 
 	save2 = curthread_pflags2_set(TDP2_SBPAGES);
 	biosize = vp->v_bufobj.bo_bsize;
diff --git a/sys/fs/smbfs/smbfs_io.c b/sys/fs/smbfs/smbfs_io.c
index dd12d1276438..f92fe50ccd99 100644
--- a/sys/fs/smbfs/smbfs_io.c
+++ b/sys/fs/smbfs/smbfs_io.c
@@ -285,8 +285,9 @@ smbfs_writevnode(struct vnode *vp, struct uio *uiop,
 	if (uiop->uio_resid == 0)
 		return 0;
 
-	if (vn_rlimit_fsize(vp, uiop, td))
-		return (EFBIG);
+	error = vn_rlimit_fsize(vp, uiop, td);
+	if (error != 0)
+		return (error);
 
 	scred = smbfs_malloc_scred();
 	smb_makescred(scred, td, cred);
diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index 326a5132990d..c1133cdaa1db 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -665,8 +665,10 @@ tmpfs_write(struct vop_write_args *v)
 	if (uio->uio_offset + uio->uio_resid >
 	  VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize)
 		return (EFBIG);
-	if (vn_rlimit_fsize(vp, uio, uio->uio_td))
-		return (EFBIG);
+	error = vn_rlimit_fsize(vp, uio, uio->uio_td);
+	if (error != 0)
+		return (error);
+
 	if (uio->uio_offset + uio->uio_resid > node->tn_size) {
 		error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid,
 		    FALSE);
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index b82db887b241..3089aca3468f 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -3195,8 +3195,6 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp,
 			io.uio_offset = *outoffp;
 			io.uio_resid = len;
 			error = vn_rlimit_fsize(outvp, &io, fsize_td);
-			if (error != 0)
-				error = EFBIG;
 		}
 		if (VOP_PATHCONF(outvp, _PC_MIN_HOLE_SIZE, &holeout) != 0)
 			holeout = 0;
diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index 1dc712f1d52a..a37b0f6e679c 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -893,8 +893,9 @@ ffs_write(
 	 * Maybe this should be above the vnode op call, but so long as
 	 * file servers have no limits, I don't think it matters.
 	 */
-	if (vn_rlimit_fsize(vp, uio, uio->uio_td))
-		return (EFBIG);
+	error = vn_rlimit_fsize(vp, uio, uio->uio_td);
+	if (error != 0)
+		return (error);
 
 	resid = uio->uio_resid;
 	osize = ip->i_size;