mm, kcsan: Instrument SLAB/SLUB free with "ASSERT_EXCLUSIVE_ACCESS"
Subsystems (2)
PATCH 1/1 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 <[email protected]>
--- mm/slab.c | 4 ++++ mm/slub.c | 4 ++++ 2 files changed, 8 insertions(+)
mm/slab.c +4 -0
@@ -3426,6 +3426,10 @@ static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,if (kasan_slab_free (cachep, objp, _RET_IP_))return ; +/* Use KCSAN to help debug racy use-after-free. */ +__kcsan_check_access (objp, cachep->object_size, +KCSAN_ACCESS_WRITE |KCSAN_ACCESS_ASSERT ); +___cache_free (cachep, objp, caller); }
mm/slub.c +4 -0
@@ -1470,6 +1470,10 @@ 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. */ +__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_); }
Signature · 1 line
2.27.0.290.gba653c62da-goog