Skip to content

Commit

Permalink
Fix cache leak in umount simplefs
Browse files Browse the repository at this point in the history
1. When the cache be destoryed, we should call rcu_barrier() to prevent
call_rcu() still works and this also prevent the cache be reused.

2. After simplefs_destroy_inode_cache() function, we need rcu_barrier()
to make sure all memory have be freed.
  • Loading branch information
RoyWFHuang committed Aug 4, 2024
1 parent 0606867 commit 4cbaa4d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static int __init simplefs_init(void)

err_inode:
simplefs_destroy_inode_cache();
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
rcu_barrier();
err:
return ret;
}
Expand All @@ -69,6 +71,8 @@ static void __exit simplefs_exit(void)
pr_err("Failed to unregister file system\n");

simplefs_destroy_inode_cache();
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
rcu_barrier();

pr_info("module unloaded\n");
}
Expand Down
3 changes: 3 additions & 0 deletions super.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ int simplefs_init_inode_cache(void)
/* De-allocate the inode cache */
void simplefs_destroy_inode_cache(void)
{
/* wait for call_rcu() and prevent the free cache be used */
rcu_barrier();

kmem_cache_destroy(simplefs_inode_cache);
}

Expand Down

0 comments on commit 4cbaa4d

Please sign in to comment.