git: eca9ac5a32e4 - main - vfs: Avoid a comparison with an uninitialized field in setutimes()

Mark Johnston markj at FreeBSD.org
Mon Aug 9 17:49:26 UTC 2021


The branch main has been updated by markj:

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

commit eca9ac5a32e432313b1c7f52f43dd11504fceef4
Author:     Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-08-09 17:27:20 +0000
Commit:     Mark Johnston <markj at FreeBSD.org>
CommitDate: 2021-08-09 17:27:20 +0000

    vfs: Avoid a comparison with an uninitialized field in setutimes()
    
    Some filesystems, e.g., devfs, do not populate va_birthtime in their
    GETATTR implementations.  To handle this, make sure that va_birthtime is
    initialized to the quasi-standard value of { VNOVAL, 0 } before calling
    VOP_GETATTR.
    
    Reported by:    KMSAN
    Reviewed by:    kib
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D31468
---
 sys/kern/vfs_syscalls.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 5701932a0163..f2ed8d2a9acb 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -3173,15 +3173,19 @@ setutimes(struct thread *td, struct vnode *vp, const struct timespec *ts,
 {
 	struct mount *mp;
 	struct vattr vattr;
-	int error, setbirthtime;
+	int error;
+	bool setbirthtime;
+
+	setbirthtime = false;
+	vattr.va_birthtime.tv_sec = VNOVAL;
+	vattr.va_birthtime.tv_nsec = 0;
 
 	if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
 		return (error);
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-	setbirthtime = 0;
-	if (numtimes < 3 && !VOP_GETATTR(vp, &vattr, td->td_ucred) &&
+	if (numtimes < 3 && VOP_GETATTR(vp, &vattr, td->td_ucred) == 0 &&
 	    timespeccmp(&ts[1], &vattr.va_birthtime, < ))
-		setbirthtime = 1;
+		setbirthtime = true;
 	VATTR_NULL(&vattr);
 	vattr.va_atime = ts[0];
 	vattr.va_mtime = ts[1];


More information about the dev-commits-src-all mailing list