Commit 051dd46
memcg, slab: unregister cache from memcg before starting to destroy it
Currently, memcg_unregister_cache(), which deletes the cache being
destroyed from the memcg_slab_caches list, is called after
__kmem_cache_shutdown() (see kmem_cache_destroy()), which starts to
destroy the cache.
As a result, one can access a partially destroyed cache while traversing
a memcg_slab_caches list, which can have deadly consequences (for
instance, cache_show() called for each cache on a memcg_slab_caches list
from mem_cgroup_slabinfo_read() will dereference pointers to already
freed data).
To fix this, let's move memcg_unregister_cache() before the cache
destruction process beginning, issuing memcg_register_cache() on failure.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Glauber Costa <glommer@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>1 parent 794b124 commit 051dd46
2 files changed
+8
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3140 | 3140 | | |
3141 | 3141 | | |
3142 | 3142 | | |
| 3143 | + | |
3143 | 3144 | | |
3144 | 3145 | | |
3145 | 3146 | | |
| |||
3148 | 3149 | | |
3149 | 3150 | | |
3150 | 3151 | | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
3151 | 3156 | | |
3152 | 3157 | | |
3153 | 3158 | | |
| |||
3170 | 3175 | | |
3171 | 3176 | | |
3172 | 3177 | | |
3173 | | - | |
3174 | | - | |
3175 | | - | |
3176 | 3178 | | |
3177 | 3179 | | |
3178 | 3180 | | |
| |||
3221 | 3223 | | |
3222 | 3224 | | |
3223 | 3225 | | |
3224 | | - | |
| 3226 | + | |
3225 | 3227 | | |
3226 | | - | |
3227 | | - | |
3228 | 3228 | | |
3229 | 3229 | | |
3230 | 3230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
316 | 317 | | |
317 | 318 | | |
318 | | - | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| 328 | + | |
328 | 329 | | |
329 | 330 | | |
330 | 331 | | |
| |||
0 commit comments