git: 84b812d5b330 - stable/13 - zfs: fix up EINVAL from getdirentries on .zfs

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Mon, 24 Apr 2023 16:16:32 UTC
The branch stable/13 has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=84b812d5b330f6f20477da4f6577c3c84655b0a5

commit 84b812d5b330f6f20477da4f6577c3c84655b0a5
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-04-20 08:36:53 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-04-24 16:16:03 +0000

    zfs: fix up EINVAL from getdirentries on .zfs
    
    PR:     270909
    (cherry picked from commit 9c4e270822a3592bf122f9a8e4e815b4602329f1)
---
 sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c
index 5bd2e1510ddb..6e49fff9a110 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_ctldir.c
@@ -675,6 +675,17 @@ zfsctl_root_readdir(struct vop_readdir_args *ap)
 
 	ASSERT3S(vp->v_type, ==, VDIR);
 
+	/*
+	 * FIXME: this routine only ever emits 3 entries and does not tolerate
+	 * being called with a buffer too small to handle all of them.
+	 *
+	 * The check below facilitates the idiom of repeating calls until the
+	 * count to return is 0.
+	 */
+	if (zfs_uio_offset(&uio) == 3 * sizeof(entry)) {
+		return (0);
+	}
+
 	error = sfs_readdir_common(zfsvfs->z_root, ZFSCTL_INO_ROOT, ap, &uio,
 	    &dots_offset);
 	if (error != 0) {