• Greg Thelen's avatar
    kasan: add memcg kmem_cache test · 0386bf38
    Greg Thelen authored
    Make a kasan test which uses a SLAB_ACCOUNT slab cache.  If the test is
    run within a non default memcg, then it uncovers the bug fixed by
    "kasan: drain quarantine of memcg slab objects"[1].
    If run without fix [1] it shows "Slab cache still has objects", and the
    kmem_cache structure is leaked.
    Here's an unpatched kernel test:
     $ dmesg -c > /dev/null
     $ mkdir /sys/fs/cgroup/memory/test
     $ echo $$ > /sys/fs/cgroup/memory/test/tasks
     $ modprobe test_kasan 2> /dev/null
     $ dmesg | grep -B1 still
     [ 123.456789] kasan test: memcg_accounted_kmem_cache allocate memcg accounted object
     [ 124.456789] kmem_cache_destroy test_cache: Slab cache still has objects
    Kernels with fix [1] don't have the "Slab cache still has objects"
    warning or the underlying leak.
    The new test runs and passes in the default (root) memcg, though in the
    root memcg it won't uncover the problem fixed by [1].
    Link: http://lkml.kernel.org/r/1482257462-36948-2-git-send-email-gthelen@google.comSigned-off-by: default avatarGreg Thelen <gthelen@google.com>
    Reviewed-by: default avatarVladimir Davydov <vdavydov.dev@gmail.com>
    Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
    Cc: Alexander Potapenko <glider@google.com>
    Cc: Dmitry Vyukov <dvyukov@google.com>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Pekka Enberg <penberg@kernel.org>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
test_kasan.c 9.76 KB