Commit adaa7979 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Andrei Vagin

compel: split sanitize ptrace.h

We have ptrace defines and functions that are part of UAPI,
and we have some internal stuff not to be exposed. Split
ptrace.h into two files accordingly.

While at it, do some cleanups:
 - add ptrace_ prefix to some functions and macros
 - remove (duplicated) PTRACE_* defines from .c files
 - rename ptrace_seccomp(), remove its duplicate
 - remove unused ptrace defines
 - remove unneeded (ptrace-related) includes

travis-ci: success for compel uapi cleanups
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Reviewed-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 e23c1d4e
#include <sys/ptrace.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/auxv.h> #include <sys/auxv.h>
...@@ -14,10 +13,9 @@ ...@@ -14,10 +13,9 @@
#include "errno.h" #include "errno.h"
#include <compel/plugins/std/syscall-codes.h> #include <compel/plugins/std/syscall-codes.h>
#include <compel/plugins/std/syscall.h> #include <compel/plugins/std/syscall.h>
#include "asm/ptrace.h"
#include "common/err.h" #include "common/err.h"
#include "asm/infect-types.h" #include "asm/infect-types.h"
#include "uapi/compel/ptrace.h" #include "ptrace.h"
#include "infect.h" #include "infect.h"
#include "infect-priv.h" #include "infect-priv.h"
#include "log.h" #include "log.h"
...@@ -159,10 +157,6 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *ar ...@@ -159,10 +157,6 @@ int get_task_regs(pid_t pid, user_regs_struct_t regs, save_regs_t save, void *ar
} }
} }
#ifndef PTRACE_GETREGSET
# define PTRACE_GETREGSET 0x4204
#endif
if (!cpu_has_feature(X86_FEATURE_FPU)) if (!cpu_has_feature(X86_FEATURE_FPU))
goto out; goto out;
......
#ifndef COMPEL_PTRACE_H__
#define COMPEL_PTRACE_H__
#include <linux/types.h>
#include <compel/asm/infect-types.h>
#include <compel/ptrace.h>
#define PTRACE_SI_EVENT(_si_code) (((_si_code) & 0xFFFF) >> 8)
extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
extern int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes);
extern int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs);
extern int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs);
#endif /* COMPEL_PTRACE_H__ */
#ifndef UAPI_COMPEL_PTRACE_H__ #ifndef UAPI_COMPEL_PTRACE_H__
#define UAPI_COMPEL_PTRACE_H__ #define UAPI_COMPEL_PTRACE_H__
#include <linux/types.h> /*
* We'd want to include both sys/ptrace.h and linux/ptrace.h,
* hoping that most definitions come from either one or another.
* Alas, on Alpine/musl both files declare struct ptrace_peeksiginfo_args,
* so there is no way they can be used together. Let's rely on libc one.
*/
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <compel/asm/infect-types.h>
#include <compel/asm/breakpoints.h> #include <compel/asm/breakpoints.h>
/* some constants for ptrace */ /*
* Some constants for ptrace that might be missing from the
* standard library includes due to being (relatively) new.
*/
#ifndef PTRACE_SEIZE #ifndef PTRACE_SEIZE
# define PTRACE_SEIZE 0x4206 # define PTRACE_SEIZE 0x4206
#endif #endif
...@@ -20,10 +28,6 @@ ...@@ -20,10 +28,6 @@
# define PTRACE_INTERRUPT 0x4207 # define PTRACE_INTERRUPT 0x4207
#endif #endif
#ifndef PTRACE_LISTEN
#define PTRACE_LISTEN 0x4208
#endif
#ifndef PTRACE_PEEKSIGINFO #ifndef PTRACE_PEEKSIGINFO
#define PTRACE_PEEKSIGINFO 0x4209 #define PTRACE_PEEKSIGINFO 0x4209
...@@ -45,32 +49,15 @@ ...@@ -45,32 +49,15 @@
#define PTRACE_SECCOMP_GET_FILTER 0x420c #define PTRACE_SECCOMP_GET_FILTER 0x420c
#endif #endif
#define PTRACE_SEIZE_DEVEL 0x80000000 #ifdef PTRACE_EVENT_STOP
# if PTRACE_EVENT_STOP == 7 /* Bad value from Linux 3.1-3.3, fixed in 3.4 */
#define PTRACE_EVENT_FORK 1 # undef PTRACE_EVENT_STOP
#define PTRACE_EVENT_VFORK 2 # endif
#define PTRACE_EVENT_CLONE 3 #endif
#define PTRACE_EVENT_EXEC 4 #ifndef PTRACE_EVENT_STOP
#define PTRACE_EVENT_VFORK_DONE 5 # define PTRACE_EVENT_STOP 128
#define PTRACE_EVENT_EXIT 6 #endif
#define PTRACE_EVENT_STOP 128
#define PTRACE_O_TRACESYSGOOD 0x00000001
#define PTRACE_O_TRACEFORK 0x00000002
#define PTRACE_O_TRACEVFORK 0x00000004
#define PTRACE_O_TRACECLONE 0x00000008
#define PTRACE_O_TRACEEXEC 0x00000010
#define PTRACE_O_TRACEVFORKDONE 0x00000020
#define PTRACE_O_TRACEEXIT 0x00000040
#define SI_EVENT(_si_code) (((_si_code) & 0xFFFF) >> 8)
extern int suspend_seccomp(pid_t pid);
extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
extern int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes);
extern int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs); extern int ptrace_suspend_seccomp(pid_t pid);
extern int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs);
#endif /* UAPI_COMPEL_PTRACE_H__ */ #endif /* UAPI_COMPEL_PTRACE_H__ */
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/ptrace.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
...@@ -17,12 +16,11 @@ ...@@ -17,12 +16,11 @@
#include <compel/plugins/std/syscall-codes.h> #include <compel/plugins/std/syscall-codes.h>
#include <compel/plugins/std/asm/syscall-types.h> #include <compel/plugins/std/asm/syscall-types.h>
#include "asm/ptrace.h"
#include "uapi/compel/plugins/std/syscall.h" #include "uapi/compel/plugins/std/syscall.h"
#include "asm/infect-types.h" #include "asm/infect-types.h"
#include "asm/sigframe.h" #include "asm/sigframe.h"
#include "infect.h" #include "infect.h"
#include "uapi/compel/ptrace.h" #include "ptrace.h"
#include "infect-rpc.h" #include "infect-rpc.h"
#include "infect-priv.h" #include "infect-priv.h"
#include "infect-util.h" #include "infect-util.h"
...@@ -41,18 +39,10 @@ ...@@ -41,18 +39,10 @@
#define PARASITE_STACK_SIZE (16 << 10) #define PARASITE_STACK_SIZE (16 << 10)
#define PTRACE_EVENT_STOP 128
#ifndef SECCOMP_MODE_DISABLED #ifndef SECCOMP_MODE_DISABLED
#define SECCOMP_MODE_DISABLED 0 #define SECCOMP_MODE_DISABLED 0
#endif #endif
#ifndef PTRACE_O_SUSPEND_SECCOMP
# define PTRACE_O_SUSPEND_SECCOMP (1 << 21)
#endif
#define SI_EVENT(_si_code) (((_si_code) & 0xFFFF) >> 8)
static int prepare_thread(int pid, struct thread_ctx *ctx); static int prepare_thread(int pid, struct thread_ctx *ctx);
static inline void close_safe(int *pfd) static inline void close_safe(int *pfd)
...@@ -195,16 +185,6 @@ static int skip_sigstop(int pid, int nr_signals) ...@@ -195,16 +185,6 @@ static int skip_sigstop(int pid, int nr_signals)
return 0; return 0;
} }
static int do_suspend_seccomp(pid_t pid)
{
if (ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_SUSPEND_SECCOMP) < 0) {
pr_perror("suspending seccomp failed");
return -1;
}
return 0;
}
/* /*
* This routine seizes task putting it into a special * This routine seizes task putting it into a special
* state where we can manipulate the task via ptrace * state where we can manipulate the task via ptrace
...@@ -278,7 +258,7 @@ try_again: ...@@ -278,7 +258,7 @@ try_again:
goto err; goto err;
} }
if (SI_EVENT(si.si_code) != PTRACE_EVENT_STOP) { if (PTRACE_SI_EVENT(si.si_code) != PTRACE_EVENT_STOP) {
/* /*
* Kernel notifies us about the task being seized received some * Kernel notifies us about the task being seized received some
* event other than the STOP, i.e. -- a signal. Let the task * event other than the STOP, i.e. -- a signal. Let the task
...@@ -295,7 +275,7 @@ try_again: ...@@ -295,7 +275,7 @@ try_again:
goto try_again; goto try_again;
} }
if (ss->seccomp_mode != SECCOMP_MODE_DISABLED && do_suspend_seccomp(pid) < 0) if (ss->seccomp_mode != SECCOMP_MODE_DISABLED && ptrace_suspend_seccomp(pid) < 0)
goto err; goto err;
nr_sigstop = 0; nr_sigstop = 0;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <signal.h> #include <signal.h>
#include <elf.h> #include <elf.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/ptrace.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
...@@ -18,11 +17,11 @@ ...@@ -18,11 +17,11 @@
#include "common/compiler.h" #include "common/compiler.h"
#include "uapi/compel/asm/infect-types.h" #include "uapi/compel/asm/infect-types.h"
#include "uapi/compel/ptrace.h" #include "ptrace.h"
#include "log.h" #include "log.h"
int suspend_seccomp(pid_t pid) int ptrace_suspend_seccomp(pid_t pid)
{ {
if (ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_SUSPEND_SECCOMP) < 0) { if (ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_SUSPEND_SECCOMP) < 0) {
pr_perror("suspending seccomp failed"); pr_perror("suspending seccomp failed");
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "cr_options.h" #include "cr_options.h"
#include "common/compiler.h" #include "common/compiler.h"
#include "restorer.h" #include "restorer.h"
#include <compel/ptrace.h>
#include "parasite-syscall.h" #include "parasite-syscall.h"
#include "util.h" #include "util.h"
#include "cpu.h" #include "cpu.h"
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "cr_options.h" #include "cr_options.h"
#include "servicefd.h" #include "servicefd.h"
#include "string.h" #include "string.h"
#include <compel/ptrace.h>
#include "ptrace-compat.h" #include "ptrace-compat.h"
#include "util.h" #include "util.h"
#include "namespaces.h" #include "namespaces.h"
......
...@@ -1572,7 +1572,7 @@ static int attach_to_tasks(bool root_seized) ...@@ -1572,7 +1572,7 @@ static int attach_to_tasks(bool root_seized)
* doing an munmap in the process, which may be blocked by * doing an munmap in the process, which may be blocked by
* seccomp and cause the task to be killed. * seccomp and cause the task to be killed.
*/ */
if (rsti(item)->has_seccomp && suspend_seccomp(pid) < 0) if (rsti(item)->has_seccomp && ptrace_suspend_seccomp(pid) < 0)
pr_err("failed to suspend seccomp, restore will probably fail...\n"); pr_err("failed to suspend seccomp, restore will probably fail...\n");
if (ptrace(PTRACE_CONT, pid, NULL, NULL) ) { if (ptrace(PTRACE_CONT, pid, NULL, NULL) ) {
......
#ifndef __CR_PTRACE_H__ #ifndef __CR_PTRACE_H__
#define __CR_PTRACE_H__ #define __CR_PTRACE_H__
#include <compel/ptrace.h>
#include <linux/types.h> #include <linux/types.h>
#include <sys/ptrace.h>
#include "types.h"
#include "config.h" #include "config.h"
#ifndef CONFIG_HAS_PTRACE_PEEKSIGINFO #ifndef CONFIG_HAS_PTRACE_PEEKSIGINFO
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "images/pagemap.pb-c.h" #include "images/pagemap.pb-c.h"
#include "imgset.h" #include "imgset.h"
#include <compel/ptrace.h>
#include "parasite-syscall.h" #include "parasite-syscall.h"
#include "parasite.h" #include "parasite.h"
#include "crtools.h" #include "crtools.h"
......
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