Skip to content

Commit 2650047

Browse files
Tycho Andersenkees
authored andcommitted
ptrace, seccomp: add support for retrieving seccomp metadata
With the new SECCOMP_FILTER_FLAG_LOG, we need to be able to extract these flags for checkpoint restore, since they describe the state of a filter. So, let's add PTRACE_SECCOMP_GET_METADATA, similar to ..._GET_FILTER, which returns the metadata of the nth filter (right now, just the flags). Hopefully this will be future proof, and new per-filter metadata can be added to this struct. Signed-off-by: Tycho Andersen <tycho@docker.com> CC: Kees Cook <keescook@chromium.org> CC: Andy Lutomirski <luto@amacapital.net> CC: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent f06eae8 commit 2650047

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

include/linux/seccomp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,19 @@ static inline void get_seccomp_filter(struct task_struct *tsk)
9595
#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
9696
extern long seccomp_get_filter(struct task_struct *task,
9797
unsigned long filter_off, void __user *data);
98+
extern long seccomp_get_metadata(struct task_struct *task,
99+
unsigned long filter_off, void __user *data);
98100
#else
99101
static inline long seccomp_get_filter(struct task_struct *task,
100102
unsigned long n, void __user *data)
101103
{
102104
return -EINVAL;
103105
}
106+
static inline long seccomp_get_metadata(struct task_struct *task,
107+
unsigned long filter_off,
108+
void __user *data)
109+
{
110+
return -EINVAL;
111+
}
104112
#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
105113
#endif /* _LINUX_SECCOMP_H */

include/uapi/linux/ptrace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ struct ptrace_peeksiginfo_args {
6666
#define PTRACE_SETSIGMASK 0x420b
6767

6868
#define PTRACE_SECCOMP_GET_FILTER 0x420c
69+
#define PTRACE_SECCOMP_GET_METADATA 0x420d
70+
71+
struct seccomp_metadata {
72+
unsigned long filter_off; /* Input: which filter */
73+
unsigned int flags; /* Output: filter's flags */
74+
};
6975

7076
/* Read signals from a shared (process wide) queue */
7177
#define PTRACE_PEEKSIGINFO_SHARED (1 << 0)

kernel/ptrace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,10 @@ int ptrace_request(struct task_struct *child, long request,
10921092
ret = seccomp_get_filter(child, addr, datavp);
10931093
break;
10941094

1095+
case PTRACE_SECCOMP_GET_METADATA:
1096+
ret = seccomp_get_metadata(child, addr, datavp);
1097+
break;
1098+
10951099
default:
10961100
break;
10971101
}

kernel/seccomp.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,39 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
10611061
__put_seccomp_filter(filter);
10621062
return ret;
10631063
}
1064+
1065+
long seccomp_get_metadata(struct task_struct *task,
1066+
unsigned long size, void __user *data)
1067+
{
1068+
long ret;
1069+
struct seccomp_filter *filter;
1070+
struct seccomp_metadata kmd = {};
1071+
1072+
if (!capable(CAP_SYS_ADMIN) ||
1073+
current->seccomp.mode != SECCOMP_MODE_DISABLED) {
1074+
return -EACCES;
1075+
}
1076+
1077+
size = min_t(unsigned long, size, sizeof(kmd));
1078+
1079+
if (copy_from_user(&kmd, data, size))
1080+
return -EFAULT;
1081+
1082+
filter = get_nth_filter(task, kmd.filter_off);
1083+
if (IS_ERR(filter))
1084+
return PTR_ERR(filter);
1085+
1086+
memset(&kmd, 0, sizeof(kmd));
1087+
if (filter->log)
1088+
kmd.flags |= SECCOMP_FILTER_FLAG_LOG;
1089+
1090+
ret = size;
1091+
if (copy_to_user(data, &kmd, size))
1092+
ret = -EFAULT;
1093+
1094+
__put_seccomp_filter(filter);
1095+
return ret;
1096+
}
10641097
#endif
10651098

10661099
#ifdef CONFIG_SYSCTL

0 commit comments

Comments
 (0)