Skip to content

Commit b25fd35

Browse files
Papya-jgregkh
authored andcommitted
fs/mbcache: cancel shrink work before destroying the cache
[ Upstream commit d227786 ] mb_cache_destroy() calls shrinker_free() and then frees all cache entries and the cache itself, but it does not cancel the pending c_shrink_work work item first. If mb_cache_entry_create() schedules c_shrink_work via schedule_work() and the work item is still pending or running when mb_cache_destroy() runs, mb_cache_shrink_worker() will access the cache after its memory has been freed, causing a use-after-free. This is only reachable by a privileged user (root or CAP_SYS_ADMIN) who can trigger the last put of a mounted ext2/ext4/ocfs2 filesystem. Cancel the work item with cancel_work_sync() before calling shrinker_free(), ensuring the worker has finished and will not be rescheduled before the cache is torn down. Fixes: c2f3140 ("mbcache2: limit cache size") Signed-off-by: Hyungjung Joo <jhj140711@gmail.com> Link: https://patch.msgid.link/20260317054556.1821600-1-jhj140711@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 817f16e commit b25fd35

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

fs/mbcache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ void mb_cache_destroy(struct mb_cache *cache)
406406
{
407407
struct mb_cache_entry *entry, *next;
408408

409+
cancel_work_sync(&cache->c_shrink_work);
409410
shrinker_free(cache->c_shrink);
410411

411412
/*

0 commit comments

Comments
 (0)