Commit a4243f07 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

dump: move the may_dump() check in seize_task()

It's a bad idea to a group of processes and only then check
rights for this operation. We need to check permissions a soon as
posible to reduce impacts in case of wrong permissions.

In addtion criu doesn't to parse /proc/pid/state and gets all required
infromation from /proc/pid/status.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 05943959
...@@ -1484,19 +1484,6 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1484,19 +1484,6 @@ static int dump_one_task(struct pstree_item *item)
if (ret < 0) if (ret < 0)
goto err; goto err;
if (!cr_user_is_root()) {
struct proc_status_creds cr;
ret = parse_pid_status(pid, &cr);
if (ret)
goto err;
if (!may_dump(&cr)) {
pr_err("Check uid (pid: %d) failed\n", pid);
goto err;
}
}
ret = collect_mappings(pid, &vmas); ret = collect_mappings(pid, &vmas);
if (ret) { if (ret) {
pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret); pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "util.h" #include "util.h"
#include "ptrace.h" #include "ptrace.h"
#include "proc_parse.h" #include "proc_parse.h"
#include "crtools.h"
int unseize_task(pid_t pid, int orig_st, int st) int unseize_task(pid_t pid, int orig_st, int st)
{ {
...@@ -49,7 +50,7 @@ int seize_task(pid_t pid, pid_t ppid) ...@@ -49,7 +50,7 @@ int seize_task(pid_t pid, pid_t ppid)
siginfo_t si; siginfo_t si;
int status; int status;
int ret, ret2, ptrace_errno; int ret, ret2, ptrace_errno;
struct proc_pid_stat_small ps; struct proc_status_creds cr;
ret = ptrace(PTRACE_SEIZE, pid, NULL, 0); ret = ptrace(PTRACE_SEIZE, pid, NULL, 0);
ptrace_errno = errno; ptrace_errno = errno;
...@@ -78,26 +79,31 @@ int seize_task(pid_t pid, pid_t ppid) ...@@ -78,26 +79,31 @@ int seize_task(pid_t pid, pid_t ppid)
* we might nead at that early point. * we might nead at that early point.
*/ */
ret2 = parse_pid_stat_small(pid, &ps); ret2 = parse_pid_status(pid, &cr);
if (ret2 < 0) if (ret2)
return -1; goto err;
if (!may_dump(&cr)) {
pr_err("Check uid (pid: %d) failed\n", pid);
goto err;
}
if (ret < 0) { if (ret < 0) {
if (ps.state != 'Z') { if (cr.state != 'Z') {
if (pid == getpid()) if (pid == getpid())
pr_err("The criu itself is within dumped tree.\n"); pr_err("The criu itself is within dumped tree.\n");
else else
pr_err("Unseizable non-zombie %d found, state %c, err %d/%d\n", pr_err("Unseizable non-zombie %d found, state %c, err %d/%d\n",
pid, ps.state, ret, ptrace_errno); pid, cr.state, ret, ptrace_errno);
return -1; return -1;
} }
return TASK_DEAD; return TASK_DEAD;
} }
if ((ppid != -1) && (ps.ppid != ppid)) { if ((ppid != -1) && (cr.ppid != ppid)) {
pr_err("Task pid reused while suspending (%d: %d -> %d)\n", pr_err("Task pid reused while suspending (%d: %d -> %d)\n",
pid, ppid, ps.ppid); pid, ppid, cr.ppid);
goto err; goto err;
} }
......
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