Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1546227
| From | Vladimir Davydov <vdavydov@tarantool.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/2] kasan: drain quarantine of memcg slab objects |
| Date | 2016-12-22 10:00 +0100 |
| Message-ID | <sR7od-75y-9@gated-at.bofh.it> (permalink) |
| References | <sQxb3-BZ-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, Dec 20, 2016 at 10:11:01AM -0800, Greg Thelen wrote: > Per memcg slab accounting and kasan have a problem with kmem_cache > destruction. > - kmem_cache_create() allocates a kmem_cache, which is used for > allocations from processes running in root (top) memcg. > - Processes running in non root memcg and allocating with either > __GFP_ACCOUNT or from a SLAB_ACCOUNT cache use a per memcg kmem_cache. > - Kasan catches use-after-free by having kfree() and kmem_cache_free() > defer freeing of objects. Objects are placed in a quarantine. > - kmem_cache_destroy() destroys root and non root kmem_caches. It takes > care to drain the quarantine of objects from the root memcg's > kmem_cache, but ignores objects associated with non root memcg. This > causes leaks because quarantined per memcg objects refer to per memcg > kmem cache being destroyed. > > To see the problem: > 1) create a slab cache with kmem_cache_create(,,,SLAB_ACCOUNT,) > 2) from non root memcg, allocate and free a few objects from cache > 3) dispose of the cache with kmem_cache_destroy() > kmem_cache_destroy() will trigger a "Slab cache still has objects" > warning indicating that the per memcg kmem_cache structure was leaked. > > Fix the leak by draining kasan quarantined objects allocated from non > root memcg. > > Racing memcg deletion is tricky, but handled. kmem_cache_destroy() => > shutdown_memcg_caches() => __shutdown_memcg_cache() => shutdown_cache() > flushes per memcg quarantined objects, even if that memcg has been > rmdir'd and gone through memcg_deactivate_kmem_caches(). > > This leak only affects destroyed SLAB_ACCOUNT kmem caches when kasan is > enabled. So I don't think it's worth patching stable kernels. > > Signed-off-by: Greg Thelen <gthelen@google.com> Reviewed-by: Vladimir Davydov <vdavydov.dev@gmail.com>
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 1/2] kasan: drain quarantine of memcg slab objects Greg Thelen <gthelen@google.com> - 2016-12-20 19:20 +0100
[PATCH 2/2] kasan: add memcg kmem_cache test Greg Thelen <gthelen@google.com> - 2016-12-20 19:20 +0100
Re: [PATCH 2/2] kasan: add memcg kmem_cache test Vladimir Davydov <vdavydov@tarantool.org> - 2016-12-22 10:30 +0100
Re: [PATCH 1/2] kasan: drain quarantine of memcg slab objects Vladimir Davydov <vdavydov@tarantool.org> - 2016-12-22 10:00 +0100
csiph-web