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

kdat: add compat_sigreturn feature

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6b9780ca
......@@ -52,6 +52,7 @@
: "sp", "x0", "memory")
#define kdat_compat_sigreturn_test() 0
int restore_gpregs(struct rt_sigframe *f, UserAarch64RegsEntry *r);
int restore_nonsigframe_gpregs(UserAarch64RegsEntry *r);
......
......@@ -53,7 +53,7 @@
: "memory")
#define kdat_compat_sigreturn_test() 0
int restore_gpregs(struct rt_sigframe *f, UserArmRegsEntry *r);
int restore_nonsigframe_gpregs(UserArmRegsEntry *r);
......
......@@ -47,6 +47,7 @@
"r"(&thread_args[i]) /* %6 */ \
: "memory","0","3","4","5","6","7","14","15")
#define kdat_compat_sigreturn_test() 0
int restore_gpregs(struct rt_sigframe *f, UserPpc64RegsEntry *r);
int restore_nonsigframe_gpregs(UserPpc64RegsEntry *r);
......
......@@ -3,6 +3,8 @@
#include <elf.h>
#include <sys/user.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/auxv.h>
#include "types.h"
#include "asm/processor-flags.h"
......@@ -20,6 +22,7 @@
#include "cpu.h"
#include "errno.h"
#include "syscall-codes.h"
#include "kerndat.h"
#include "protobuf.h"
#include "images/core.pb-c.h"
......@@ -67,6 +70,31 @@ void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *
~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF));
}
#ifdef CONFIG_X86_64
/* Remaps 64-bit vDSO on the same addr, where it already is */
int kdat_compat_sigreturn_test(void)
{
unsigned long auxval;
int ret;
errno = 0;
auxval = getauxval(AT_SYSINFO_EHDR);
if (!auxval || errno == ENOENT) {
pr_err("Failed to get auxval, err: %lu\n", auxval);
return 0;
}
/*
* Mapping vDSO on very low unaligned address (1).
* We will get ENOMEM or EPERM if ARCH_MAP_VDSO_* exist,
* and ENOSYS if patches aren't in kernel.
*/
ret = syscall(SYS_arch_prctl, ARCH_MAP_VDSO_32, 1);
if (ret == -1 && errno == ENOSYS)
return 0;
return 1;
}
#endif /* CONFIG_X86_64 */
int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs);
int arch_task_compatible(pid_t pid)
{
......@@ -103,9 +131,13 @@ static bool ldt_task_selectors(pid_t pid)
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
pid_t pid = ctl->rpid;
int ret;
ret = arch_task_compatible(pid);
if (ret < 0)
return false;
/* FIXME: remove it */
if (arch_task_compatible(pid)) {
if (ret && !kdat.has_compat_sigreturn) {
pr_err("Can't dump task %d running in 32-bit mode\n", pid);
return false;
}
......
......@@ -54,6 +54,12 @@
: \
: "r"(ret) \
: "memory")
#ifndef ARCH_MAP_VDSO_32
# define ARCH_MAP_VDSO_32 0x2002
#endif
extern int kdat_compat_sigreturn_test(void);
#else /* CONFIG_X86_64 */
#define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, \
thread_args, clone_restore_fn) \
......@@ -72,6 +78,8 @@
: \
: "r"(ret) \
: "memory")
#define kdat_compat_sigreturn_test() 0
#endif /* CONFIG_X86_64 */
static inline void
......
......@@ -34,6 +34,7 @@ struct kerndat_s {
unsigned long task_size;
bool ipv6;
bool has_loginuid;
bool has_compat_sigreturn;
enum pagemap_func pmap;
unsigned int has_xtlocks;
unsigned long mmap_min_addr;
......
......@@ -557,6 +557,16 @@ err:
return exit_code;
}
static int kerndat_compat_restore(void)
{
int ret = kdat_compat_sigreturn_test();
if (ret < 0) /* failure */
return ret;
kdat.has_compat_sigreturn = !!ret;
return 0;
}
int kerndat_init(void)
{
int ret;
......@@ -582,6 +592,8 @@ int kerndat_init(void)
ret = kerndat_iptables_has_xtlocks();
if (!ret)
ret = kerndat_tcp_repair();
if (!ret)
ret = kerndat_compat_restore();
kerndat_lsm();
kerndat_mmap_min_addr();
......@@ -614,6 +626,8 @@ int kerndat_init_rst(void)
ret = kerndat_iptables_has_xtlocks();
if (!ret)
ret = kerndat_tcp_repair();
if (!ret)
ret = kerndat_compat_restore();
kerndat_lsm();
kerndat_mmap_min_addr();
......@@ -626,6 +640,8 @@ int kerndat_init_cr_exec(void)
int ret;
ret = get_task_size();
if (!ret)
ret = kerndat_compat_restore();
return 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