]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Handle Linux kernel /proc FS uint32 type stat overflow when calculating tools rate...
authorOliver Kurth <okurth@vmware.com>
Fri, 26 Oct 2018 17:44:57 +0000 (10:44 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 26 Oct 2018 17:44:57 +0000 (10:44 -0700)
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.

open-vm-tools/services/plugins/guestInfo/perfMonLinux.c

index fa2344b0f6e0a60329a48f82eedcf169b2c23f49..eb74faa553a2688a010a67761f249ed229e2de12 100644 (file)
@@ -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;