Skip to content

Commit cc21eee

Browse files
committed
Fix cache leak in umount simplefs
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.
1 parent 5afbafc commit cc21eee

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

fs.c

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static int __init simplefs_init(void)
5858

5959
err_inode:
6060
simplefs_destroy_inode_cache();
61+
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
62+
rcu_barrier();
6163
err:
6264
return ret;
6365
}
@@ -69,6 +71,8 @@ static void __exit simplefs_exit(void)
6971
pr_err("Failed to unregister file system\n");
7072

7173
simplefs_destroy_inode_cache();
74+
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
75+
rcu_barrier();
7276

7377
pr_info("module unloaded\n");
7478
}

super.c

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ int simplefs_init_inode_cache(void)
3737
/* De-allocate the inode cache */
3838
void simplefs_destroy_inode_cache(void)
3939
{
40+
/* wait for call_rcu() and prevent the free cache be used */
41+
rcu_barrier();
42+
4043
kmem_cache_destroy(simplefs_inode_cache);
4144
}
4245

0 commit comments

Comments
 (0)