Commit 46dcc7c9 authored by Nanyong Sun's avatar Nanyong Sun Committed by Andrew Morton

mm: migrate: simplify find_mm_struct()

Use find_get_task_by_vpid() to replace the task_struct find logic in
find_mm_struct(), note that this patch move the ptrace_may_access() call
out from rcu_read_lock() scope, this is ok because it actually does not
need it, find_get_task_by_vpid() already get the pid and task safely,
ptrace_may_access() can use the task safely, like what
sched_core_share_pid() similarly do.

Link: https://lkml.kernel.org/r/20240905153118.1205173-1-sunnanyong@huawei.comSigned-off-by: default avatarNanyong Sun <sunnanyong@huawei.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 25e8acbc
...@@ -2505,25 +2505,19 @@ static struct mm_struct *find_mm_struct(pid_t pid, nodemask_t *mem_nodes) ...@@ -2505,25 +2505,19 @@ static struct mm_struct *find_mm_struct(pid_t pid, nodemask_t *mem_nodes)
return current->mm; return current->mm;
} }
/* Find the mm_struct */ task = find_get_task_by_vpid(pid);
rcu_read_lock();
task = find_task_by_vpid(pid);
if (!task) { if (!task) {
rcu_read_unlock();
return ERR_PTR(-ESRCH); return ERR_PTR(-ESRCH);
} }
get_task_struct(task);
/* /*
* Check if this process has the right to modify the specified * Check if this process has the right to modify the specified
* process. Use the regular "ptrace_may_access()" checks. * process. Use the regular "ptrace_may_access()" checks.
*/ */
if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) {
rcu_read_unlock();
mm = ERR_PTR(-EPERM); mm = ERR_PTR(-EPERM);
goto out; goto out;
} }
rcu_read_unlock();
mm = ERR_PTR(security_task_movememory(task)); mm = ERR_PTR(security_task_movememory(task));
if (IS_ERR(mm)) if (IS_ERR(mm))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment