From f861ecca8b4dbdc9f71c3271d1eb6dbc0f71b5c6 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 28 Mar 2024 18:11:09 +0100 Subject: syz-fuzzer: use of monotonic time for latency measurement time.Now/Since may reject to use monotonic time if the fuzzer messes with system time badly enough. Enforce use of monotonic time. --- pkg/osutil/osutil.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pkg/osutil/osutil.go') diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 478c091dc..a619f9169 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -17,6 +17,7 @@ import ( "sync" "syscall" "time" + _ "unsafe" // required to use go:linkname ) const ( @@ -337,3 +338,14 @@ func Abs(path string) string { } return filepath.Join(wd, path) } + +// MonotonicNano returns monotonic time in nanoseconds from some unspecified point in time. +// Useful mostly to measure time intervals. +// This function should be used inside of tested VMs b/c time.Now may reject to use monotonic time +// if the fuzzer messes with system time (sets time past Y2157, see comments in time/time.go). +// This is a hacky way to use the private runtime function. +// If this ever breaks, we can either provide specializations for different Go versions +// using build tags, or fall back to time.Now. +// +//go:linkname MonotonicNano runtime.nanotime +func MonotonicNano() time.Duration -- cgit mrf-deployment