History

Merge tag 'seccomp-next' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux into next

James Morris committed 11 years ago

Commit fe6c59d2 parents 52721d9 221272f5 files · +31 −8Browse files

Unified · Split

5 files
  1. include/linux/ptrace.h +1 −0
  2. include/linux/seccomp.h +1 −1
  3. include/uapi/linux/ptrace.h +4 −2
  4. kernel/ptrace.c +13 −0
  5. kernel/seccomp.c +12 −5
include/linux/ptrace.h+1−0
@@ -34,6 +34,7 @@ · 33 unmodified lines
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+1−1
@@ -78,7 +78,7 @@ static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) · 77 unmodified lines
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+4−2
@@ -89,9 +89,11 @@ struct ptrace_peeksiginfo_args { · 88 unmodified lines
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+13−0
@@ -556,6 +556,19 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data) · 555 unmodified lines
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+12−5
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen) · 174 unmodified lines
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) · 357 unmodified lines
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) · 94 unmodified lines
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 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t