Commit 2aa583b4 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

x86/crtools: rework arch_task_compatible

Detect task's personality by the size of register set, returned
by ptrace call with PTRACE_GETREGSET (more reliable).
The same approach uses strace from 4.8 version:
https://sourceforge.net/projects/strace/files/strace/4.8/Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6068d10c
......@@ -58,9 +58,24 @@ void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *
~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF));
}
int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs);
int arch_task_compatible(pid_t pid)
{
unsigned long cs, ds;
user_regs_struct_t r;
int ret = ptrace_get_regs(pid, &r);
if (ret)
return -1;
return !r.is_native;
}
#define USER32_CS 0x23
#define USER_CS 0x33
static bool ldt_task_selectors(pid_t pid)
{
unsigned long cs;
errno = 0;
/*
......@@ -73,15 +88,7 @@ int arch_task_compatible(pid_t pid)
return -1;
}
errno = 0;
ds = ptrace(PTRACE_PEEKUSER, pid, offsetof(user_regs_struct64, ds), 0);
if (errno != 0) {
pr_perror("Can't get DS register for %d", pid);
return -1;
}
/* It's x86-32 or x32 */
return cs != 0x33 || ds == 0x2b;
return cs != USER_CS && cs != USER32_CS;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
......@@ -94,6 +101,11 @@ bool arch_can_dump_task(struct parasite_ctl *ctl)
return false;
}
if (ldt_task_selectors(pid)) {
pr_err("Can't dump task %d with LDT descriptors\n", pid);
return false;
}
return true;
}
......
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