[vbox-dev] False kmemleak positives from VB

Larry Finger Larry.Finger at lwfinger.net
Mon Mar 23 16:50:46 UTC 2015

I just reconfigured my kernel to include kmemleak to check the drivers that I 
maintain for memory leaks. I was quite surprised to discover several thousand 
items arising from vboxdrv in the scan of possible leaks. The VB version is 
4.3.26. All of the VB entries are false positives as they disappear from the 
kmemleak scan when the VB modules are unloaded.

I do not recall these false positives as appearing in earlier versions of VB, 
but my memory may be faulty. In any case, a one-line patch to inform kmemleak 
that the offending allocation should be ignored is attached.  The patch carries 
an MIT license.


-------------- next part --------------
When kmemleak is used to check for kernel memory leaks, several thousand
possible leaks from vboxdrv are listed in the kmemleak scan. All of these
are false positives as they disappear when vboxdrv is unloaded.

As such false positives interfere with finding real leaks, it is useful
to inform kmemleak that these memory allocations should be ignored.

Signed-off-by: Larry Finger <Larry.Finger at lwfinger.net>

Index: vboxhost/vboxdrv/r0drv/linux/alloc-r0drv-linux.c
--- vboxhost.orig/vboxdrv/r0drv/linux/alloc-r0drv-linux.c
+++ vboxhost/vboxdrv/r0drv/linux/alloc-r0drv-linux.c
@@ -31,6 +31,7 @@
 #include "the-linux-kernel.h"
 #include "internal/iprt.h"
 #include <iprt/mem.h>
+#include <linux/kmemleak.h>
 #include <iprt/assert.h>
 #include <iprt/err.h>
@@ -278,6 +279,7 @@ DECLHIDDEN(int) rtR0MemAllocEx(size_t cb
             pHdr = kmalloc(cb + sizeof(*pHdr),
                            (fFlags & RTMEMHDR_FLAG_ANY_CTX_ALLOC) ? (GFP_ATOMIC | __GFP_NOWARN)
                                                                   : (GFP_KERNEL | __GFP_NOWARN));
+            kmemleak_ignore(pHdr);
             if (RT_UNLIKELY(   !pHdr
                             && cb > PAGE_SIZE
                             && !(fFlags & RTMEMHDR_FLAG_ANY_CTX) ))

More information about the vbox-dev mailing list