History

tile: enable full SECCOMP support

Chris Metcalf committed 11 years ago

Commit a0ddef81 parent 38715df10 files · +57 −5Browse files

Unified · Split

10 files
  1. Documentation/features/seccomp/seccomp-filter/arch-support.txt +1 −1
  2. arch/tile/Kconfig +17 −0
  3. arch/tile/include/asm/Kbuild +1 −0
  4. arch/tile/include/asm/elf.h +1 −3
  5. arch/tile/include/asm/syscall.h +27 −1
  6. arch/tile/kernel/intvec_32.S +1 −0
  7. arch/tile/kernel/intvec_64.S +1 −0
  8. arch/tile/kernel/ptrace.c +3 −0
  9. include/uapi/linux/audit.h +3 −0
  10. include/uapi/linux/elf-em.h +2 −0
Documentation/features/seccomp/seccomp-filter/arch-support.txt+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 | score: | TODO |
3333 | sh: | TODO |
3434 | sparc: | TODO |
35− | tile: | TODO |
35+ | tile: | ok |
3636 | um: | TODO |
3737 | unicore32: | TODO |
3838 | x86: | ok |
arch/tile/Kconfig+17−0
@@ -32,6 +32,7 @@ config TILE · 31 unmodified lines
3232 select EDAC_SUPPORT
3333 select GENERIC_STRNCPY_FROM_USER
3434 select GENERIC_STRNLEN_USER
35+ select HAVE_ARCH_SECCOMP_FILTER
3536
3637 # FIXME: investigate whether we need/want these options.
3738 # select HAVE_IOREMAP_PROT
@@ -221,6 +222,22 @@ config COMPAT · 183 unmodified lines
221222 If enabled, the kernel will support running TILE-Gx binaries
222223 that were built with the -m32 option.
223224
225+config SECCOMP
226+ bool "Enable seccomp to safely compute untrusted bytecode"
227+ depends on PROC_FS
228+ help
229+ This kernel feature is useful for number crunching applications
230+ that may need to compute untrusted bytecode during their
231+ execution. By using pipes or other transports made available to
232+ the process as file descriptors supporting the read/write
233+ syscalls, it's possible to isolate those applications in
234+ their own address space using seccomp. Once seccomp is
235+ enabled via prctl, it cannot be disabled and the task is only
236+ allowed to execute a few safe syscalls defined by each seccomp
237+ mode.
238+
239+ If unsure, say N.
240+
224241 config SYSVIPC_COMPAT
225242 def_bool y
226243 depends on COMPAT && SYSVIPC
arch/tile/include/asm/Kbuild+1−0
@@ -28,6 +28,7 @@ generic-y += poll.h · 27 unmodified lines
2828 generic-y += posix_types.h
2929 generic-y += preempt.h
3030 generic-y += resource.h
31+generic-y += seccomp.h
3132 generic-y += sembuf.h
3233 generic-y += serial.h
3334 generic-y += shmbuf.h
arch/tile/include/asm/elf.h+1−3
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include <arch/chip.h>
2323
2424 #include <linux/ptrace.h>
25+#include <linux/elf-em.h>
2526 #include <asm/byteorder.h>
2627 #include <asm/page.h>
2728
@@ -30,9 +31,6 @@ typedef unsigned long elf_greg_t; · 2 unmodified lines
3031 #define ELF_NGREG (sizeof(struct pt_regs) / sizeof(elf_greg_t))
3132 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
3233
33−#define EM_TILEPRO 188
34−#define EM_TILEGX 191
35−
3634 /* Provide a nominal data structure. */
3735 #define ELF_NFPREG 0
3836 typedef double elf_fpreg_t;
arch/tile/include/asm/syscall.h+27−1
@@ -20,6 +20,8 @@ · 19 unmodified lines
2020
2121 #include <linux/sched.h>
2222 #include <linux/err.h>
23+#include <linux/audit.h>
24+#include <linux/compat.h>
2325 #include <arch/abi.h>
2426
2527 /* The array of function pointers for syscalls. */
@@ -61,7 +63,15 @@ static inline void syscall_set_return_value(struct task_struct *task, · 35 unmodified lines
6163 struct pt_regs *regs,
6264 int error, long val)
6365 {
64− regs->regs[0] = (long) error ?: val;
66+ if (error) {
67+ /* R0 is the passed-in negative error, R1 is positive. */
68+ regs->regs[0] = error;
69+ regs->regs[1] = -error;
70+ } else {
71+ /* R1 set to zero to indicate no error. */
72+ regs->regs[0] = val;
73+ regs->regs[1] = 0;
74+ }
6575 }
6676
6777 static inline void syscall_get_arguments(struct task_struct *task,
@@ -82,4 +92,20 @@ static inline void syscall_set_arguments(struct task_struct *task, · 14 unmodified lines
8292 memcpy(&regs[i], args, n * sizeof(args[0]));
8393 }
8494
95+/*
96+ * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
97+ * tile has the same system calls both on little- and big- endian.
98+ */
99+static inline int syscall_get_arch(void)
100+{
101+ if (is_compat_task())
102+ return AUDIT_ARCH_TILEGX32;
103+
104+#ifdef CONFIG_TILEGX
105+ return AUDIT_ARCH_TILEGX;
106+#else
107+ return AUDIT_ARCH_TILEPRO;
108+#endif
109+}
110+
85111 #endif /* _ASM_TILE_SYSCALL_H */
arch/tile/kernel/intvec_32.S+1−0
@@ -1224,6 +1224,7 @@ handle_syscall: · 1223 unmodified lines
12241224 jal do_syscall_trace_enter
12251225 }
12261226 FEEDBACK_REENTER(handle_syscall)
1227+ blz r0, .Lsyscall_sigreturn_skip
12271228
12281229 /*
12291230 * We always reload our registers from the stack at this
arch/tile/kernel/intvec_64.S+1−0
@@ -1247,6 +1247,7 @@ handle_syscall: · 1246 unmodified lines
12471247 jal do_syscall_trace_enter
12481248 }
12491249 FEEDBACK_REENTER(handle_syscall)
1250+ bltz r0, .Lsyscall_sigreturn_skip
12501251
12511252 /*
12521253 * We always reload our registers from the stack at this
arch/tile/kernel/ptrace.c+3−0
@@ -262,6 +262,9 @@ int do_syscall_trace_enter(struct pt_regs *regs) · 261 unmodified lines
262262 if (work & _TIF_NOHZ)
263263 user_exit();
264264
265+ if (secure_computing() == -1)
266+ return -1;
267+
265268 if (work & _TIF_SYSCALL_TRACE) {
266269 if (tracehook_report_syscall_entry(regs))
267270 regs->regs[TREG_SYSCALL_NR] = -1;
include/uapi/linux/audit.h+3−0
@@ -382,6 +382,9 @@ enum { · 381 unmodified lines
382382 #define AUDIT_ARCH_SHEL64 (EM_SH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
383383 #define AUDIT_ARCH_SPARC (EM_SPARC)
384384 #define AUDIT_ARCH_SPARC64 (EM_SPARCV9|__AUDIT_ARCH_64BIT)
385+#define AUDIT_ARCH_TILEGX (EM_TILEGX|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
386+#define AUDIT_ARCH_TILEGX32 (EM_TILEGX|__AUDIT_ARCH_LE)
387+#define AUDIT_ARCH_TILEPRO (EM_TILEPRO|__AUDIT_ARCH_LE)
385388 #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
386389
387390 #define AUDIT_PERM_EXEC 1
include/uapi/linux/elf-em.h+2−0
@@ -38,6 +38,8 @@ · 37 unmodified lines
3838 #define EM_ALTERA_NIOS2 113 /* Altera Nios II soft-core processor */
3939 #define EM_TI_C6000 140 /* TI C6X DSPs */
4040 #define EM_AARCH64 183 /* ARM 64 bit */
41+#define EM_TILEPRO 188 /* Tilera TILEPro */
42+#define EM_TILEGX 191 /* Tilera TILE-Gx */
4143 #define EM_FRV 0x5441 /* Fujitsu FR-V */
4244 #define EM_AVR32 0x18ad /* Atmel AVR32 */
4345

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