Commit 75b1d4a1 authored by Pavel Emelyanov's avatar Pavel Emelyanov

rst: Open sys.ns_last_pid before diving into restorer

We restore chroot before doing this, so if we might need to
open one, we may have no access to the /proc/... paths.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent cd19b2fe
...@@ -2545,6 +2545,16 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) ...@@ -2545,6 +2545,16 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
if (ret < 0) if (ret < 0)
goto err; goto err;
/*
* Open the last_pid syscl early, since restorer (maybe) lives
* in chroot and has no access to "/proc/..." paths.
*/
task_args->fd_last_pid = open(LAST_PID_PATH, O_RDWR);
if (task_args->fd_last_pid < 0) {
pr_perror("Can't open sys.ns_last_pid");
goto err;
}
/* /*
* Now prepare run-time data for threads restore. * Now prepare run-time data for threads restore.
*/ */
......
...@@ -92,7 +92,6 @@ int open_pages_image_at(int dfd, unsigned long flags, int pm_fd); ...@@ -92,7 +92,6 @@ int open_pages_image_at(int dfd, unsigned long flags, int pm_fd);
void up_page_ids_base(void); void up_page_ids_base(void);
#define LAST_PID_PATH "/proc/sys/kernel/ns_last_pid" #define LAST_PID_PATH "/proc/sys/kernel/ns_last_pid"
#define LAST_PID_PERM 0666
struct cr_fdset { struct cr_fdset {
int fd_off; int fd_off;
......
...@@ -151,6 +151,8 @@ struct task_restore_core_args { ...@@ -151,6 +151,8 @@ struct task_restore_core_args {
struct rst_tcp_sock *tcp_socks; struct rst_tcp_sock *tcp_socks;
int tcp_socks_nr; int tcp_socks_nr;
int fd_last_pid; /* sys.ns_last_pid for threads rst */
struct vdso_symtable vdso_sym_rt; /* runtime vdso symbols */ struct vdso_symtable vdso_sym_rt; /* runtime vdso symbols */
unsigned long vdso_rt_parked_at; /* safe place to keep vdso */ unsigned long vdso_rt_parked_at; /* safe place to keep vdso */
} __aligned(sizeof(long)); } __aligned(sizeof(long));
......
...@@ -810,12 +810,7 @@ long __export_restore_task(struct task_restore_core_args *args) ...@@ -810,12 +810,7 @@ long __export_restore_task(struct task_restore_core_args *args)
long parent_tid; long parent_tid;
int i, fd; int i, fd;
fd = sys_open(LAST_PID_PATH, O_RDWR, LAST_PID_PERM); fd = args->fd_last_pid;
if (fd < 0) {
pr_err("Can't open last_pid %d\n", fd);
goto core_restore_end;
}
ret = sys_flock(fd, LOCK_EX); ret = sys_flock(fd, LOCK_EX);
if (ret) { if (ret) {
pr_err("Can't lock last_pid %d\n", fd); pr_err("Can't lock last_pid %d\n", fd);
...@@ -856,9 +851,10 @@ long __export_restore_task(struct task_restore_core_args *args) ...@@ -856,9 +851,10 @@ long __export_restore_task(struct task_restore_core_args *args)
goto core_restore_end; goto core_restore_end;
} }
sys_close(fd);
} }
sys_close(args->fd_last_pid);
restore_rlims(args); restore_rlims(args);
pr_info("%ld: Restored\n", sys_getpid()); pr_info("%ld: Restored\n", sys_getpid());
......
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