git: 29d25561813f - stable/13 - vfs: Avoid a comparison with an uninitialized field in setutimes()
Mark Johnston
markj at FreeBSD.org
Mon Aug 16 13:02:29 UTC 2021
The branch stable/13 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=29d25561813fd040e41d6588243eb4f32a39b57f
commit 29d25561813fd040e41d6588243eb4f32a39b57f
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-16 13:01:49 +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
Sponsored by: The FreeBSD Foundation
(cherry picked from commit eca9ac5a32e432313b1c7f52f43dd11504fceef4)
---
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 80bcc0cb4d41..855943adecef 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -3161,15 +3161,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