[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [win-pv-devel] [PATCH] Limit timeoffset to valid values
> -----Original Message----- > From: win-pv-devel <win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx> On Behalf Of > Owen Smith > Sent: 23 August 2019 14:22 > To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx > Cc: Owen Smith <owen.smith@xxxxxxxxxx> > Subject: [win-pv-devel] [PATCH] Limit timeoffset to valid values > > timeoffset is expressed in +/- seconds from UTC. This translates to > 43200. Log out of range values and ignore the timeoffset. > Not sure 12 hours is a suitable upper limit; it may be possible to get adjustments bigger than that since the time offset is not a timezone correction but an offset from host time that's supposed to accommodate any time set by the guest admin IIRC. TBH I'm not sure why we're reading the value from xenstore here anyway since it used to be the case that all the offset calculation/application nastiness was hidden behind the toolstack and the Xen wallclock. I'll have to take a closer look. Paul > Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx> > --- > src/xenagent/service.cpp | 30 ++++++++++++++++++++++-------- > src/xenagent/service.h | 2 +- > 2 files changed, 23 insertions(+), 9 deletions(-) > > diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp > index a77ff23..2c034b8 100644 > --- a/src/xenagent/service.cpp > +++ b/src/xenagent/service.cpp > @@ -40,6 +40,9 @@ > #include "service.h" > #include "messages.h" > > +// 12 hours in seconds > +#define MAX_TIME_OFFSET (12 * 60 * 60) > + > class CCritSec > { > public: > @@ -404,17 +407,23 @@ bool CXenIfaceCreator::IsRTCInUTC() > return val; > } > > -void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now) > +long CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now) > { > std::string vm; > if (!m_device->StoreRead("vm", vm)) > - return; > + return 0; > > std::string offs; > if (!m_device->StoreRead(vm + "/rtc/timeoffset", offs)) > - return; > + return 0; > > long offset = (long)atoi(offs.c_str()); > + if (offset > MAX_TIME_OFFSET || offset < -MAX_TIME_OFFSET) { > + CXenAgent::Log("Invalid offset \"%s\" (%+d), using 0 offset\n", > + offs.c_str(), > + offset); > + return 0; > + } > > ULARGE_INTEGER lnow; > lnow.LowPart = now->dwLowDateTime; > @@ -424,11 +433,14 @@ void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now) > > now->dwLowDateTime = lnow.LowPart; > now->dwHighDateTime = lnow.HighPart; > + > + return offset; > } > > void CXenIfaceCreator::SetXenTime() > { > bool IsUTC = IsRTCInUTC(); > + long offset = 0; > > SYSTEMTIME cur = { 0 }; > if (IsUTC) > @@ -441,7 +453,7 @@ void CXenIfaceCreator::SetXenTime() > return; > > if (IsUTC) > - AdjustXenTimeToUTC(&now); > + offset = AdjustXenTimeToUTC(&now); > > SYSTEMTIME sys = { 0 }; > if (!FileTimeToSystemTime(&now, &sys)) > @@ -451,12 +463,14 @@ void CXenIfaceCreator::SetXenTime() > return; > > CXenAgent::Log("RTC is in %s\n", IsUTC ? "UTC" : "local time"); > - CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d\n", > + CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d (%+d)\n", > cur.wYear, cur.wMonth, cur.wDay, > - cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds); > - CXenAgent::Log("New Time = %d/%d/%d %d:%02d:%02d.%d\n", > + cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds, > + offset); > + CXenAgent::Log("New Time = %d/%d/%d %d:%02d:%02d.%d (%+d)\n", > sys.wYear, sys.wMonth, sys.wDay, > - sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds); > + sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, > + offset); > > if (IsUTC) > SetSystemTime(&sys); > diff --git a/src/xenagent/service.h b/src/xenagent/service.h > index 9547177..e8d2ef5 100644 > --- a/src/xenagent/service.h > +++ b/src/xenagent/service.h > @@ -86,7 +86,7 @@ private: > void StopSlateModeWatch(); > void AcquireShutdownPrivilege(); > bool IsRTCInUTC(); > - void AdjustXenTimeToUTC(FILETIME* time); > + long AdjustXenTimeToUTC(FILETIME* time); > void SetXenTime(); > > private: > -- > 2.16.2.windows.1 > > > _______________________________________________ > win-pv-devel mailing list > win-pv-devel@xxxxxxxxxxxxxxxxxxxx > https://lists.xenproject.org/mailman/listinfo/win-pv-devel _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |