hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8LKYV
--------------------------------
Increment the mm_users of mm_struct to avoid use-after-free.
Fixes: 9bbb63c8f043 ("memcg: introduce per-memcg swapin interface") Signed-off-by: Liu Shixin liushixin2@huawei.com --- mm/memcontrol.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 09cd8c8535fd..c9ffc793e42b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4159,12 +4159,18 @@ static int mem_cgroup_task_swapin(struct task_struct *task, void *arg) struct vm_area_struct *vma; struct blk_plug plug;
+ if (__task_is_dying(task)) + return 0; + if (!mm || !mmget_not_zero(mm)) + return 0; + mmap_read_lock(mm); blk_start_plug(&plug); for (vma = mm->mmap; vma; vma = vma->vm_next) force_swapin_vma(vma); blk_finish_plug(&plug); mmap_read_unlock(mm); + mmput(mm);
return 0; }