Skip to content

Commit fe6c59d

Browse files
author
James Morris
committed
Merge tag 'seccomp-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into next
2 parents 52721d9 + 221272f commit fe6c59d

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

include/linux/ptrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define PT_TRACE_SECCOMP PT_EVENT_FLAG(PTRACE_EVENT_SECCOMP)
3535

3636
#define PT_EXITKILL (PTRACE_O_EXITKILL << PT_OPT_FLAG_SHIFT)
37+
#define PT_SUSPEND_SECCOMP (PTRACE_O_SUSPEND_SECCOMP << PT_OPT_FLAG_SHIFT)
3738

3839
/* single stepping state bits (used on ARM and PA-RISC) */
3940
#define PT_SINGLESTEP_BIT 31

include/linux/seccomp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
7878

7979
static inline int seccomp_mode(struct seccomp *s)
8080
{
81-
return 0;
81+
return SECCOMP_MODE_DISABLED;
8282
}
8383
#endif /* CONFIG_SECCOMP */
8484

include/uapi/linux/ptrace.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ struct ptrace_peeksiginfo_args {
8989
#define PTRACE_O_TRACESECCOMP (1 << PTRACE_EVENT_SECCOMP)
9090

9191
/* eventless options */
92-
#define PTRACE_O_EXITKILL (1 << 20)
92+
#define PTRACE_O_EXITKILL (1 << 20)
93+
#define PTRACE_O_SUSPEND_SECCOMP (1 << 21)
9394

94-
#define PTRACE_O_MASK (0x000000ff | PTRACE_O_EXITKILL)
95+
#define PTRACE_O_MASK (\
96+
0x000000ff | PTRACE_O_EXITKILL | PTRACE_O_SUSPEND_SECCOMP)
9597

9698
#include <asm/ptrace.h>
9799

kernel/ptrace.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,19 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data)
556556
if (data & ~(unsigned long)PTRACE_O_MASK)
557557
return -EINVAL;
558558

559+
if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) {
560+
if (!config_enabled(CONFIG_CHECKPOINT_RESTORE) ||
561+
!config_enabled(CONFIG_SECCOMP))
562+
return -EINVAL;
563+
564+
if (!capable(CAP_SYS_ADMIN))
565+
return -EPERM;
566+
567+
if (seccomp_mode(&current->seccomp) != SECCOMP_MODE_DISABLED ||
568+
current->ptrace & PT_SUSPEND_SECCOMP)
569+
return -EPERM;
570+
}
571+
559572
/* Avoid intermediate state when all opts are cleared */
560573
flags = child->ptrace;
561574
flags &= ~(PTRACE_O_MASK << PT_OPT_FLAG_SHIFT);

kernel/seccomp.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
175175
*/
176176
static u32 seccomp_run_filters(struct seccomp_data *sd)
177177
{
178-
struct seccomp_filter *f = ACCESS_ONCE(current->seccomp.filter);
179178
struct seccomp_data sd_local;
180179
u32 ret = SECCOMP_RET_ALLOW;
180+
/* Make sure cross-thread synced filter points somewhere sane. */
181+
struct seccomp_filter *f =
182+
lockless_dereference(current->seccomp.filter);
181183

182184
/* Ensure unexpected behavior doesn't result in failing open. */
183185
if (unlikely(WARN_ON(f == NULL)))
184186
return SECCOMP_RET_KILL;
185187

186-
/* Make sure cross-thread synced filter points somewhere sane. */
187-
smp_read_barrier_depends();
188-
189188
if (!sd) {
190189
populate_seccomp_data(&sd_local);
191190
sd = &sd_local;
@@ -549,7 +548,11 @@ void secure_computing_strict(int this_syscall)
549548
{
550549
int mode = current->seccomp.mode;
551550

552-
if (mode == 0)
551+
if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&
552+
unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
553+
return;
554+
555+
if (mode == SECCOMP_MODE_DISABLED)
553556
return;
554557
else if (mode == SECCOMP_MODE_STRICT)
555558
__secure_computing_strict(this_syscall);
@@ -650,6 +653,10 @@ u32 seccomp_phase1(struct seccomp_data *sd)
650653
int this_syscall = sd ? sd->nr :
651654
syscall_get_nr(current, task_pt_regs(current));
652655

656+
if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&
657+
unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
658+
return SECCOMP_PHASE1_OK;
659+
653660
switch (mode) {
654661
case SECCOMP_MODE_STRICT:
655662
__secure_computing_strict(this_syscall); /* may call do_exit */

0 commit comments

Comments
 (0)