git: c2b39a756fe7 - stable/14 - OpenZFS: Ensure that zfs_getattr() initializes the va_rdev field

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Sun, 10 Dec 2023 17:47:19 UTC
The branch stable/14 has been updated by emaste:

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

commit c2b39a756fe7463cff5c715c2375700efef1e799
Author:     Mark Johnston <markjdb@gmail.com>
AuthorDate: 2023-12-07 16:20:11 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-12-10 17:46:57 +0000

    OpenZFS: Ensure that zfs_getattr() initializes the va_rdev field
    
    Otherwise the field is left uninitialized, leading to a possible kernel
    memory disclosure to userspace or to the network.  Use the same
    initialization value we use in zfsctl_common_getattr().
    
    Reported-by: KMSAN
    Sponsored-by: The FreeBSD Foundation
    Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
    Reviewed-by: Ed Maste <emaste@FreeBSD.org>
    Signed-off-by: Mark Johnston <markj@FreeBSD.org>
    
    (cherry picked from commit 11656234b560c401dec6a16e1bf048b20fd31aac)
---
 sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
index 3302f043620a..93bbfa8e3ef2 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
@@ -2007,6 +2007,8 @@ zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr)
 	vap->va_size = zp->z_size;
 	if (vp->v_type == VBLK || vp->v_type == VCHR)
 		vap->va_rdev = zfs_cmpldev(rdev);
+	else
+		vap->va_rdev = 0;
 	vap->va_gen = zp->z_gen;
 	vap->va_flags = 0;	/* FreeBSD: Reset chflags(2) flags. */
 	vap->va_filerev = zp->z_seq;