Commit 6e49bce7 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

seize: Split proc_status_creds into pieces

There's a subset of this structure is required by seize_catch_task(),
which in turn will go to compel library. So prepare for that.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 976e13a1
...@@ -729,12 +729,12 @@ static int dump_task_core_all(struct parasite_ctl *ctl, ...@@ -729,12 +729,12 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
goto err; goto err;
creds = dmpi(item)->pi_creds; creds = dmpi(item)->pi_creds;
if (creds->seccomp_mode != SECCOMP_MODE_DISABLED) { if (creds->s.seccomp_mode != SECCOMP_MODE_DISABLED) {
pr_info("got seccomp mode %d for %d\n", creds->seccomp_mode, vpid(item)); pr_info("got seccomp mode %d for %d\n", creds->s.seccomp_mode, vpid(item));
core->tc->has_seccomp_mode = true; core->tc->has_seccomp_mode = true;
core->tc->seccomp_mode = creds->seccomp_mode; core->tc->seccomp_mode = creds->s.seccomp_mode;
if (creds->seccomp_mode == SECCOMP_MODE_FILTER) { if (creds->s.seccomp_mode == SECCOMP_MODE_FILTER) {
core->tc->has_seccomp_filter = true; core->tc->has_seccomp_filter = true;
core->tc->seccomp_filter = creds->last_filter; core->tc->seccomp_filter = creds->last_filter;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "int.h" #include "int.h"
#include "types.h" #include "types.h"
#include "crtools.h" #include "crtools.h"
#include "ptrace.h" #include "proc_parse.h"
#include "pstree.h" #include "pstree.h"
#include "parasite-syscall.h" #include "parasite-syscall.h"
#include "vma.h" #include "vma.h"
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <sys/types.h> #include <sys/types.h>
#include "ptrace.h"
#include "images/seccomp.pb-c.h" #include "images/seccomp.pb-c.h"
#define PROC_TASK_COMM_LEN 32 #define PROC_TASK_COMM_LEN 32
...@@ -72,15 +73,11 @@ struct seccomp_info { ...@@ -72,15 +73,11 @@ struct seccomp_info {
#define PROC_CAP_SIZE 2 #define PROC_CAP_SIZE 2
struct proc_status_creds { struct proc_status_creds {
struct seize_task_status s;
unsigned int uids[4]; unsigned int uids[4];
unsigned int gids[4]; unsigned int gids[4];
char state;
int ppid;
unsigned long long sigpnd;
unsigned long long shdpnd;
int seccomp_mode;
u32 last_filter; u32 last_filter;
/* /*
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include <linux/types.h> #include <linux/types.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include "proc_parse.h"
/* some constants for ptrace */ /* some constants for ptrace */
#ifndef PTRACE_SEIZE #ifndef PTRACE_SEIZE
# define PTRACE_SEIZE 0x4206 # define PTRACE_SEIZE 0x4206
...@@ -64,6 +62,16 @@ ...@@ -64,6 +62,16 @@
#define SI_EVENT(_si_code) (((_si_code) & 0xFFFF) >> 8) #define SI_EVENT(_si_code) (((_si_code) & 0xFFFF) >> 8)
struct seize_task_status {
char state;
int ppid;
unsigned long long sigpnd;
unsigned long long shdpnd;
int seccomp_mode;
};
struct proc_status_creds;
extern int seize_catch_task(pid_t pid); extern int seize_catch_task(pid_t pid);
extern int seize_wait_task(pid_t pid, pid_t ppid, struct proc_status_creds *creds); extern int seize_wait_task(pid_t pid, pid_t ppid, struct proc_status_creds *creds);
extern int suspend_seccomp(pid_t pid); extern int suspend_seccomp(pid_t pid);
......
...@@ -993,8 +993,8 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -993,8 +993,8 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
if (f.fd < 0) if (f.fd < 0)
return -1; return -1;
cr->sigpnd = 0; cr->s.sigpnd = 0;
cr->shdpnd = 0; cr->s.shdpnd = 0;
if (bfdopenr(&f)) if (bfdopenr(&f))
return -1; return -1;
...@@ -1007,13 +1007,13 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -1007,13 +1007,13 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
goto err_parse; goto err_parse;
if (!strncmp(str, "State:", 6)) { if (!strncmp(str, "State:", 6)) {
cr->state = str[7]; cr->s.state = str[7];
done++; done++;
continue; continue;
} }
if (!strncmp(str, "PPid:", 5)) { if (!strncmp(str, "PPid:", 5)) {
if (sscanf(str, "PPid:\t%d", &cr->ppid) != 1) { if (sscanf(str, "PPid:\t%d", &cr->s.ppid) != 1) {
pr_err("Unable to parse: %s\n", str); pr_err("Unable to parse: %s\n", str);
goto err_parse; goto err_parse;
} }
...@@ -1070,7 +1070,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -1070,7 +1070,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
} }
if (!strncmp(str, "Seccomp:", 8)) { if (!strncmp(str, "Seccomp:", 8)) {
if (sscanf(str + 9, "%d", &cr->seccomp_mode) != 1) { if (sscanf(str + 9, "%d", &cr->s.seccomp_mode) != 1) {
goto err_parse; goto err_parse;
} }
...@@ -1084,7 +1084,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -1084,7 +1084,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
if (sscanf(str + 7, "%llx", &sigpnd) != 1) if (sscanf(str + 7, "%llx", &sigpnd) != 1)
goto err_parse; goto err_parse;
cr->shdpnd |= sigpnd; cr->s.shdpnd |= sigpnd;
done++; done++;
continue; continue;
...@@ -1094,7 +1094,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -1094,7 +1094,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
if (sscanf(str + 7, "%llx", &sigpnd) != 1) if (sscanf(str + 7, "%llx", &sigpnd) != 1)
goto err_parse; goto err_parse;
cr->sigpnd |= sigpnd; cr->s.sigpnd |= sigpnd;
done++; done++;
continue; continue;
......
...@@ -180,12 +180,12 @@ try_again: ...@@ -180,12 +180,12 @@ try_again:
goto err; goto err;
if (ret < 0 || WIFEXITED(status) || WIFSIGNALED(status)) { if (ret < 0 || WIFEXITED(status) || WIFSIGNALED(status)) {
if (creds->state != 'Z') { if (creds->s.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, creds->state, ret, wait_errno); pid, creds->s.state, ret, wait_errno);
return -1; return -1;
} }
...@@ -195,9 +195,9 @@ try_again: ...@@ -195,9 +195,9 @@ try_again:
return TASK_DEAD; return TASK_DEAD;
} }
if ((ppid != -1) && (creds->ppid != ppid)) { if ((ppid != -1) && (creds->s.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, creds->ppid); pid, ppid, creds->s.ppid);
goto err; goto err;
} }
...@@ -229,13 +229,13 @@ try_again: ...@@ -229,13 +229,13 @@ try_again:
goto try_again; goto try_again;
} }
if (creds->seccomp_mode != SECCOMP_MODE_DISABLED && suspend_seccomp(pid) < 0) if (creds->s.seccomp_mode != SECCOMP_MODE_DISABLED && suspend_seccomp(pid) < 0)
goto err; goto err;
nr_sigstop = 0; nr_sigstop = 0;
if (creds->sigpnd & (1 << (SIGSTOP - 1))) if (creds->s.sigpnd & (1 << (SIGSTOP - 1)))
nr_sigstop++; nr_sigstop++;
if (creds->shdpnd & (1 << (SIGSTOP - 1))) if (creds->s.shdpnd & (1 << (SIGSTOP - 1)))
nr_sigstop++; nr_sigstop++;
if (si.si_signo == SIGSTOP) if (si.si_signo == SIGSTOP)
nr_sigstop++; nr_sigstop++;
......
...@@ -50,7 +50,7 @@ static int collect_filter_for_pstree(struct pstree_item *item) ...@@ -50,7 +50,7 @@ static int collect_filter_for_pstree(struct pstree_item *item)
void *m; void *m;
if (item->pid->state == TASK_DEAD || if (item->pid->state == TASK_DEAD ||
dmpi(item)->pi_creds->seccomp_mode != SECCOMP_MODE_FILTER) dmpi(item)->pi_creds->s.seccomp_mode != SECCOMP_MODE_FILTER)
return 0; return 0;
for (i = 0; true; i++) { for (i = 0; true; i++) {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "cr-errno.h" #include "cr-errno.h"
#include "pstree.h" #include "pstree.h"
#include "criu-log.h" #include "criu-log.h"
#include "ptrace.h" #include "proc_parse.h"
#include "seize.h" #include "seize.h"
#include "stats.h" #include "stats.h"
#include "xmalloc.h" #include "xmalloc.h"
...@@ -660,11 +660,11 @@ static bool creds_dumpable(struct proc_status_creds *parent, ...@@ -660,11 +660,11 @@ static bool creds_dumpable(struct proc_status_creds *parent,
parent->gids[1], child->gids[1], parent->gids[1], child->gids[1],
parent->gids[2], child->gids[2], parent->gids[2], child->gids[2],
parent->gids[3], child->gids[3], parent->gids[3], child->gids[3],
parent->state, child->state, parent->s.state, child->s.state,
parent->ppid, child->ppid, parent->s.ppid, child->s.ppid,
parent->sigpnd, child->sigpnd, parent->s.sigpnd, child->s.sigpnd,
parent->shdpnd, child->shdpnd, parent->s.shdpnd, child->s.shdpnd,
parent->seccomp_mode, child->seccomp_mode, parent->s.seccomp_mode, child->s.seccomp_mode,
parent->last_filter, child->last_filter); parent->last_filter, child->last_filter);
} }
return false; return false;
......
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