From: Oliver Kurth Date: Fri, 26 Oct 2018 17:44:57 +0000 (-0700) Subject: Handle Linux kernel /proc FS uint32 type stat overflow when calculating tools rate... X-Git-Tag: stable-11.0.0~376 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45f0733b4eeb4b46f820a5db911917cfbb769d37;p=thirdparty%2Fopen-vm-tools.git Handle Linux kernel /proc FS uint32 type stat overflow when calculating tools rate stats. On both 32-bit and 64-bit Linux, tools always parses Linux kernel /proc FS stats as uint64 values. For rate stats, current - previous can handle uint64 type stat overflow, but not uint32 type. --- diff --git a/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c b/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c index fa2344b0f..eb74faa55 100644 --- a/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c +++ b/open-vm-tools/services/plugins/guestInfo/perfMonLinux.c @@ -1094,7 +1094,18 @@ GuestInfoAppendRate(Bool emitNameSpace, // IN: if (reportID == GuestStatID_Linux_DiskRequestQueueAvg) { valueDelta = ((double)(currentStat->value)) / 10; } else { - valueDelta = currentStat->value - previousStat->value; + /* + * The /proc FS stat can be uint32 type in the kernel on both x86 + * and x64 Linux, it is parsed and stored as uint64 in tools, so we + * also need to handle uint32 overflow here. + */ + if (currentStat->value < previousStat->value && + previousStat->value <= MAX_UINT32) { + valueDelta = (uint32)(currentStat->value) - + (uint32)(previousStat->value); + } else { + valueDelta = currentStat->value - previousStat->value; + } } valueDouble = valueDelta / timeDelta;