git: 8bee7ea63a6a - main - vfs: fail VOP_ALLOCATE passes that make no progress

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 21:11:26 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=8bee7ea63a6a0d65a95df781504d445486fd7dd4

commit 8bee7ea63a6a0d65a95df781504d445486fd7dd4
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-11-17 21:10:38 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-11-17 21:11:05 +0000

    vfs: fail VOP_ALLOCATE passes that make no progress
    
    vn_fallocate() loops over VOP_ALLOCATE until the requested range has
    been allocated, permitting partial results.  It only asserts that each
    pass makes progress, so on a non-INVARIANTS kernel a filesystem that
    returns success without shrinking the remaining length leaves the caller
    spinning forever.
    
    Drop the assertion and just return EIO in that case, as was just done
    for vn_deallocate_impl().  The NFS server already does the same in its
    own VOP_ALLOCATE loop.
    
    Document the progress requirement in VOP_ALLOCATE(9) and the new EIO
    condition in posix_fallocate(2).
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D61497
---
 lib/libsys/posix_fallocate.2  |  4 +++-
 share/man/man9/VOP_ALLOCATE.9 |  9 +++++++--
 sys/kern/vfs_vnops.c          | 13 ++++++++++++-
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lib/libsys/posix_fallocate.2 b/lib/libsys/posix_fallocate.2
index 94858c4a0f90..ae1fdc035480 100644
--- a/lib/libsys/posix_fallocate.2
+++ b/lib/libsys/posix_fallocate.2
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd November 2, 2025
+.Dd November 12, 2026
 .Dt POSIX_FALLOCATE 2
 .Os
 .Sh NAME
@@ -108,6 +108,8 @@ argument was less than or equal to zero, the
 argument was less than zero.
 .It Bq Er EIO
 An I/O error occurred while reading from or writing to a file system.
+.It Bq Er EIO
+The file system failed to make progress on the requested allocation.
 .It Bq Er EINTEGRITY
 Corrupted data was detected while reading from the file system.
 .It Bq Er ENODEV
diff --git a/share/man/man9/VOP_ALLOCATE.9 b/share/man/man9/VOP_ALLOCATE.9
index 4fcbe773f236..956800d643d7 100644
--- a/share/man/man9/VOP_ALLOCATE.9
+++ b/share/man/man9/VOP_ALLOCATE.9
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd November 8, 2021
+.Dd November 12, 2026
 .Dt VOP_ALLOCATE 9
 .Os
 .Sh NAME
@@ -68,7 +68,12 @@ and
 .Fa len
 arguments are updated to reflect the portion of the range that
 still needs to be allocated on return.
-A partial allocation is considered a successful operation.
+A partial allocation is considered a successful operation, provided that
+some progress was made:
+a successful return must decrease
+.Fa *len ,
+or the caller will fail the request with
+.Er EIO .
 The file's contents are not changed.
 .Sh LOCKS
 The file should be exclusively locked on entry and will still be locked on exit.
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index fa579de2b83a..dbef4b520717 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -3996,7 +3996,18 @@ vn_fallocate(struct file *fp, off_t offset, off_t len, struct thread *td)
 		}
 		if (error != 0 || len == 0)
 			break;
-		KASSERT(olen > len, ("Iteration did not make progress?"));
+
+		/*
+		 * A partial result is permitted, but each pass must make some
+		 * progress or we would spin here forever.
+		 */
+		if (len >= olen) {
+			error = EXTERROR(EIO,
+			    "no progress on vp %p (off %jd)",
+			    vp, (intmax_t)ooffset);
+			break;
+		}
+
 		maybe_yield();
 	}