Commit a6e746ba authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

tty: don't crash if restoring a non-pty

The pty field here is only present with certain tty types, so we shouldn't
unconditionally dereference it, or criu will hang.
Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1ca3317e
...@@ -486,7 +486,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd) ...@@ -486,7 +486,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
{ {
struct tty_info *info = container_of(d, struct tty_info, d); struct tty_info *info = container_of(d, struct tty_info, d);
struct reg_file_info *fake = NULL; struct reg_file_info *fake = NULL;
int slave = -1, ret = -1; int slave = -1, ret = -1, index;
if (!is_service_fd(fd, CTL_TTY_OFF)) if (!is_service_fd(fd, CTL_TTY_OFF))
return 0; return 0;
...@@ -496,12 +496,14 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd) ...@@ -496,12 +496,14 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
if (!fake) if (!fake)
goto err; goto err;
slave = open_pty_reg(&fake->d, O_RDONLY); slave = open_pty_reg(&fake->d, O_RDONLY);
index = info->tie->pty->index;
if (slave < 0) { if (slave < 0) {
pr_perror("Can't open %s", path_from_reg(&fake->d)); pr_perror("Can't open %s", path_from_reg(&fake->d));
goto err; goto err;
} }
} else if (info->type == TTY_TYPE_CONSOLE) { } else if (info->type == TTY_TYPE_CONSOLE) {
slave = open_pty_reg(info->reg_d, O_RDONLY); slave = open_pty_reg(info->reg_d, O_RDONLY);
index = -1;
if (slave < 0) { if (slave < 0) {
pr_perror("Can't open %s", path_from_reg(info->reg_d)); pr_perror("Can't open %s", path_from_reg(info->reg_d));
goto err; goto err;
...@@ -510,8 +512,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd) ...@@ -510,8 +512,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
BUG(); BUG();
pr_info("Restore session %d by %d tty (index %d)\n", pr_info("Restore session %d by %d tty (index %d)\n",
info->tie->sid, (int)getpid(), info->tie->sid, (int)getpid(), index);
info->tie->pty->index);
ret = tty_set_sid(slave); ret = tty_set_sid(slave);
if (!ret) if (!ret)
......
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