git: 2bd3dbe3dd60 - stable/13 - tmpfs: truncate write if it would exceed the fs max file size or RLIMIT_FSIZE

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

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

commit 2bd3dbe3dd60aeb84ebc52f23f0f4205d3eb082d
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-09-18 13:27:28 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-08 00:29:36 +0000

    tmpfs: truncate write if it would exceed the fs max file size or RLIMIT_FSIZE
    
    PR:     164793
    
    (cherry picked from commit 8bdb2695d69710b7f2e7cc20820aab8b3f4668a6)
---
 sys/fs/tmpfs/tmpfs_vnops.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index c1133cdaa1db..ab5a99b1be66 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -646,6 +646,7 @@ tmpfs_write(struct vop_write_args *v)
 	struct uio *uio;
 	struct tmpfs_node *node;
 	off_t oldsize;
+	ssize_t r;
 	int error, ioflag;
 	mode_t newmode;
 
@@ -662,12 +663,12 @@ tmpfs_write(struct vop_write_args *v)
 		return (0);
 	if (ioflag & IO_APPEND)
 		uio->uio_offset = node->tn_size;
-	if (uio->uio_offset + uio->uio_resid >
-	  VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize)
-		return (EFBIG);
-	error = vn_rlimit_fsize(vp, uio, uio->uio_td);
-	if (error != 0)
+	error = vn_rlimit_fsizex(vp, uio, VFS_TO_TMPFS(vp->v_mount)->
+	    tm_maxfilesize, &r, uio->uio_td);
+	if (error != 0) {
+		vn_rlimit_fsizex_res(uio, r);
 		return (error);
+	}
 
 	if (uio->uio_offset + uio->uio_resid > node->tn_size) {
 		error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid,
@@ -694,6 +695,7 @@ out:
 	MPASS(IMPLIES(error == 0, uio->uio_resid == 0));
 	MPASS(IMPLIES(error != 0, oldsize == node->tn_size));
 
+	vn_rlimit_fsizex_res(uio, r);
 	return (error);
 }