提交 d5fb0387 编写于 作者: Z Zhang Zekun 提交者: Wang Wensheng

mm/sharepool: Add a read lock in proc_usage_show()

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5XQS4
CVE: NA

-----------------------------------------------

In function get_process_sp_res(), spg_node can be freed by other
process, the access to spg_node->spg can cause kernel panic. Add
a pair of read lock to fix this problem.
Fix the same problem in proc_sp_group_state().

Fixes: 3d37f8717287 ("[Huawei] mm: sharepool: use built-in-statistics")
Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
上级 de73eb95
...@@ -3809,10 +3809,12 @@ int proc_sp_group_state(struct seq_file *m, struct pid_namespace *ns, ...@@ -3809,10 +3809,12 @@ int proc_sp_group_state(struct seq_file *m, struct pid_namespace *ns,
if (!mm) if (!mm)
return 0; return 0;
down_read(&sp_group_sem);
down_read(&mm->mmap_lock); down_read(&mm->mmap_lock);
master = mm->sp_group_master; master = mm->sp_group_master;
if (!master) { if (!master) {
up_read(&mm->mmap_lock); up_read(&mm->mmap_lock);
up_read(&sp_group_sem);
return 0; return 0;
} }
...@@ -3847,6 +3849,7 @@ int proc_sp_group_state(struct seq_file *m, struct pid_namespace *ns, ...@@ -3847,6 +3849,7 @@ int proc_sp_group_state(struct seq_file *m, struct pid_namespace *ns,
seq_putc(m, '\n'); seq_putc(m, '\n');
} }
up_read(&mm->mmap_lock); up_read(&mm->mmap_lock);
up_read(&sp_group_sem);
return 0; return 0;
} }
...@@ -4127,6 +4130,7 @@ static int proc_usage_show(struct seq_file *seq, void *offset) ...@@ -4127,6 +4130,7 @@ static int proc_usage_show(struct seq_file *seq, void *offset)
"PID", "COMM", "SP_ALLOC", "SP_K2U", "SP_RES", "Non-SP_RES", "PID", "COMM", "SP_ALLOC", "SP_K2U", "SP_RES", "Non-SP_RES",
"Non-SP_Shm", "VIRT"); "Non-SP_Shm", "VIRT");
down_read(&sp_group_sem);
mutex_lock(&master_list_lock); mutex_lock(&master_list_lock);
list_for_each_entry(master, &master_list, list_node) { list_for_each_entry(master, &master_list, list_node) {
proc_stat = &master->instat; proc_stat = &master->instat;
...@@ -4142,6 +4146,7 @@ static int proc_usage_show(struct seq_file *seq, void *offset) ...@@ -4142,6 +4146,7 @@ static int proc_usage_show(struct seq_file *seq, void *offset)
page2kb(master->mm->total_vm)); page2kb(master->mm->total_vm));
} }
mutex_unlock(&master_list_lock); mutex_unlock(&master_list_lock);
up_read(&sp_group_sem);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册