[vbox-dev] Patch to quiet false positive messages from kmemleak

Larry Finger Larry.Finger at lwfinger.net
Thu Aug 25 18:32:49 GMT 2016


The kernel facility named kmemleak is very useful in tracking memory leaks in 
the kernel. Unfortunately, there are instances when the scan of allocated memory 
cannot find an active user even though one actually exists. In this case, 
kmemleak issues a false positive result. This situation is verified by unloading 
the driver in question and noting that the leak then disappears.

Unfortunately, vboxdrv displays such false positives. A typical traceback is

unreferenced object 0xffff88020cfeb080 (size 128):
   comm "EMT-0", pid 4180, jiffies 4297724945 (age 80.264s)
   hex dump (first 32 bytes):
     19 01 09 18 01 00 00 80 58 00 00 00 58 00 00 00  ........X...X...
     10 12 61 19 58 00 00 00 03 00 00 00 00 00 00 00  ..a.X...........
   backtrace:
     [<ffffffff8169ef8a>] kmemleak_alloc+0x4a/0xa0
     [<ffffffff811e6d94>] __kmalloc+0xe4/0x230
     [<ffffffffa0940dd8>] rtR0MemAllocEx+0x178/0x230 [vboxdrv]
     [<ffffffffa093ec1b>] VBoxHost_RTMemAllocZTag+0x1b/0x40 [vboxdrv]
     [<ffffffffa0940017>] rtR0MemObjNew+0x37/0x70 [vboxdrv]
     [<ffffffffa09410c8>] rtR0MemObjLinuxAllocPages+0x48/0x200 [vboxdrv]
     [<ffffffffa0941948>] rtR0MemObjNativeAllocCont+0x48/0xe0 [vboxdrv]
     [<ffffffffa093f5f4>] VBoxHost_RTR0MemObjAllocContTag+0x54/0x70 [vboxdrv]
     [<ffffffffffffffff>] 0xffffffffffffffff

Fortunately, these false positives are easily quieted one they have been 
identified. The following two-line patch, which has an MIT license, does the trick:

Index: VirtualBox-5.1.4/src/VBox/Runtime/r0drv/linux/alloc-r0drv-linux.c
===================================================================
--- VirtualBox-5.1.4.orig/src/VBox/Runtime/r0drv/linux/alloc-r0drv-linux.c
+++ VirtualBox-5.1.4/src/VBox/Runtime/r0drv/linux/alloc-r0drv-linux.c
@@ -35,7 +35,7 @@
  #include <iprt/assert.h>
  #include <iprt/err.h>
  #include "r0drv/alloc-r0drv.h"
-
+#include <linux/kmemleak.h>

  #if (defined(RT_ARCH_AMD64) || defined(DOXYGEN_RUNNING)) && 
!defined(RTMEMALLOC_EXEC_HEAP)
  # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
@@ -294,6 +294,7 @@ DECLHIDDEN(int) rtR0MemAllocEx(size_t cb
                  fFlags &= ~RTMEMHDR_FLAG_KMALLOC;
                  pHdr = vmalloc(cb + sizeof(*pHdr));
              }
+           kmemleak_not_leak(pHdr);
          }
          else
              pHdr = vmalloc(cb + sizeof(*pHdr));




More information about the vbox-dev mailing list