Skip to content

Commit

Permalink
ptrace,syscall_user_dispatch: checkpoint/restore support for SUD
Browse files Browse the repository at this point in the history
Implement ptrace getter/setter interface for syscall user dispatch.

These prctl settings are presently write-only, making it impossible to
implement transparent checkpoint/restore via software like CRIU.

'on_dispatch' field is not exposed because it is a kernel-internal
only field that cannot be 'true' when returning to userland.

Signed-off-by: Gregory Price <gregory.price@memverge.com>
  • Loading branch information
Gregory Price authored and intel-lab-lkp committed Jan 28, 2023
1 parent 5af6ce7 commit bc68df2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Documentation/admin-guide/syscall-user-dispatch.rst
Expand Up @@ -43,7 +43,10 @@ doesn't rely on any of the syscall ABI to make the filtering. It uses
only the syscall dispatcher address and the userspace key.

As the ABI of these intercepted syscalls is unknown to Linux, these
syscalls are not instrumentable via ptrace or the syscall tracepoints.
syscalls are not instrumentable via ptrace or the syscall tracepoints,
however an interfaces to suspend, checkpoint, and restore syscall user
dispatch configuration has been added to ptrace to assist userland
checkpoint/restart software.

Interface
---------
Expand Down
18 changes: 18 additions & 0 deletions include/linux/syscall_user_dispatch.h
Expand Up @@ -22,6 +22,12 @@ int set_syscall_user_dispatch(unsigned long mode, unsigned long offset,
#define clear_syscall_work_syscall_user_dispatch(tsk) \
clear_task_syscall_work(tsk, SYSCALL_USER_DISPATCH)

int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size,
void __user *data);

int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long size,
void __user *data);

#else
struct syscall_user_dispatch {};

Expand All @@ -35,6 +41,18 @@ static inline void clear_syscall_work_syscall_user_dispatch(struct task_struct *
{
}

static inline int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size,
void __user *data)
{
return -EINVAL;
}

static inline int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long size,
void __user *data)
{
return -EINVAL;
}

#endif /* CONFIG_GENERIC_ENTRY */

#endif /* _SYSCALL_USER_DISPATCH_H */
9 changes: 9 additions & 0 deletions include/uapi/linux/ptrace.h
Expand Up @@ -112,6 +112,15 @@ struct ptrace_rseq_configuration {
__u32 pad;
};

#define PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG 0x4210
#define PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG 0x4211
struct syscall_user_dispatch_config {
__u64 mode;
__s8 *selector;
__u64 offset;
__u64 len;
};

/*
* These values are stored in task->ptrace_message
* by ptrace_stop to describe the current syscall-stop.
Expand Down
39 changes: 39 additions & 0 deletions kernel/entry/syscall_user_dispatch.c
Expand Up @@ -106,3 +106,42 @@ int set_syscall_user_dispatch(unsigned long mode, unsigned long offset,

return 0;
}

int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size,
void __user *data)
{
struct syscall_user_dispatch *sd = &task->syscall_dispatch;
struct syscall_user_dispatch_config config;

if (size != sizeof(struct syscall_user_dispatch_config))
return -EINVAL;

if (test_syscall_work(SYSCALL_USER_DISPATCH))
config.mode = PR_SYS_DISPATCH_ON;
else
config.mode = PR_SYS_DISPATCH_OFF;

config.offset = sd->offset;
config.len = sd->len;
config.selector = sd->selector;

if (copy_to_user(data, &config, sizeof(config)))
return -EFAULT;

return 0;
}

int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long size,
void __user *data)
{
struct syscall_user_dispatch_config config;

if (size != sizeof(struct syscall_user_dispatch_config))
return -EINVAL;

if (copy_from_user(&config, data, sizeof(config)))
return -EFAULT;

return set_syscall_user_dispatch(config.mode, config.offset, config.len,
config.selector);
}
9 changes: 9 additions & 0 deletions kernel/ptrace.c
Expand Up @@ -32,6 +32,7 @@
#include <linux/compat.h>
#include <linux/sched/signal.h>
#include <linux/minmax.h>
#include <linux/syscall_user_dispatch.h>

#include <asm/syscall.h> /* for syscall_get_* */

Expand Down Expand Up @@ -1259,6 +1260,14 @@ int ptrace_request(struct task_struct *child, long request,
break;
#endif

case PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG:
ret = syscall_user_dispatch_set_config(child, addr, datavp);
break;

case PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG:
ret = syscall_user_dispatch_get_config(child, addr, datavp);
break;

default:
break;
}
Expand Down

0 comments on commit bc68df2

Please sign in to comment.