summaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
authorMarco Elver <elver@google.com>2020-08-06 23:19:12 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2020-08-07 11:33:23 -0700
commitcfbe1636c3585c1e032bfac512fb8be903fbc913 (patch)
tree36503944fe18f9ae48bbe728ea1e4e3a2a729596 /mm/slub.c
parentb3cb9fc3aeaf9d52967c87d54a98f035e96279dc (diff)
downloadlinux-cfbe1636c3585c1e032bfac512fb8be903fbc913.tar.gz
linux-cfbe1636c3585c1e032bfac512fb8be903fbc913.tar.bz2
linux-cfbe1636c3585c1e032bfac512fb8be903fbc913.zip
mm, kcsan: instrument SLAB/SLUB free with "ASSERT_EXCLUSIVE_ACCESS"
Provide the necessary KCSAN checks to assist with debugging racy use-after-frees. While KASAN is more reliable at generally catching such use-after-frees (due to its use of a quarantine), it can be difficult to debug racy use-after-frees. If a reliable reproducer exists, KCSAN can assist in debugging such issues. Note: ASSERT_EXCLUSIVE_ACCESS is a convenience wrapper if the size is simply sizeof(var). Instead, here we just use __kcsan_check_access() explicitly to pass the correct size. Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <andreyknvl@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> Link: http://lkml.kernel.org/r/20200623072653.114563-1-elver@google.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/mm/slub.c b/mm/slub.c
index e5fc31c37b37..ae39eb392396 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1549,6 +1549,11 @@ static __always_inline bool slab_free_hook(struct kmem_cache *s, void *x)
if (!(s->flags & SLAB_DEBUG_OBJECTS))
debug_check_no_obj_freed(x, s->object_size);
+ /* Use KCSAN to help debug racy use-after-free. */
+ if (!(s->flags & SLAB_TYPESAFE_BY_RCU))
+ __kcsan_check_access(x, s->object_size,
+ KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ASSERT);
+
/* KASAN might put x into memory quarantine, delaying its reuse */
return kasan_slab_free(s, x, _RET_IP_);
}