OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SYSCALL_PARAMETERS_RESTRICTIONS_H_ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SYSCALL_PARAMETERS_RESTRICTIONS_H_ |
6 #define SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SYSCALL_PARAMETERS_RESTRICTIONS_H_ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SYSCALL_PARAMETERS_RESTRICTIONS_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "sandbox/linux/sandbox_export.h" |
9 | 10 |
10 // These are helpers to build seccomp-bpf policies, i.e. policies for a | 11 // These are helpers to build seccomp-bpf policies, i.e. policies for a |
11 // sandbox that reduces the Linux kernel's attack surface. They return an | 12 // sandbox that reduces the Linux kernel's attack surface. They return an |
12 // ErrorCode suitable to restrict certain system call parameters. | 13 // SANDBOX_EXPORT ErrorCode suitable to restrict certain system call parameters. |
13 | 14 |
14 namespace sandbox { | 15 namespace sandbox { |
15 | 16 |
16 class ErrorCode; | 17 class ErrorCode; |
17 class SandboxBPF; | 18 class SandboxBPF; |
18 | 19 |
19 // Allow clone(2) for threads. | 20 // Allow clone(2) for threads. |
20 // Reject fork(2) attempts with EPERM. | 21 // Reject fork(2) attempts with EPERM. |
21 // Don't restrict on ASAN. | 22 // Don't restrict on ASAN. |
22 // Crash if anything else is attempted. | 23 // Crash if anything else is attempted. |
23 ErrorCode RestrictCloneToThreadsAndEPERMFork(SandboxBPF* sandbox); | 24 SANDBOX_EXPORT ErrorCode |
| 25 RestrictCloneToThreadsAndEPERMFork(SandboxBPF* sandbox); |
24 | 26 |
25 // Allow PR_SET_NAME, PR_SET_DUMPABLE, PR_GET_DUMPABLE. | 27 // Allow PR_SET_NAME, PR_SET_DUMPABLE, PR_GET_DUMPABLE. |
26 // Crash if anything else is attempted. | 28 // Crash if anything else is attempted. |
27 ErrorCode RestrictPrctl(SandboxBPF* sandbox); | 29 SANDBOX_EXPORT ErrorCode RestrictPrctl(SandboxBPF* sandbox); |
28 | 30 |
29 // Allow TCGETS and FIONREAD. | 31 // Allow TCGETS and FIONREAD. |
30 // Crash if anything else is attempted. | 32 // Crash if anything else is attempted. |
31 ErrorCode RestrictIoctl(SandboxBPF* sandbox); | 33 SANDBOX_EXPORT ErrorCode RestrictIoctl(SandboxBPF* sandbox); |
32 | 34 |
33 // Restrict the flags argument in mmap(2). | 35 // Restrict the flags argument in mmap(2). |
34 // Only allow: MAP_SHARED | MAP_PRIVATE | MAP_ANONYMOUS | | 36 // Only allow: MAP_SHARED | MAP_PRIVATE | MAP_ANONYMOUS | |
35 // MAP_STACK | MAP_NORESERVE | MAP_FIXED | MAP_DENYWRITE. | 37 // MAP_STACK | MAP_NORESERVE | MAP_FIXED | MAP_DENYWRITE. |
36 // Crash if any other flag is used. | 38 // Crash if any other flag is used. |
37 ErrorCode RestrictMmapFlags(SandboxBPF* sandbox); | 39 SANDBOX_EXPORT ErrorCode RestrictMmapFlags(SandboxBPF* sandbox); |
38 | 40 |
39 // Restrict the prot argument in mprotect(2). | 41 // Restrict the prot argument in mprotect(2). |
40 // Only allow: PROT_READ | PROT_WRITE | PROT_EXEC. | 42 // Only allow: PROT_READ | PROT_WRITE | PROT_EXEC. |
41 ErrorCode RestrictMprotectFlags(SandboxBPF* sandbox); | 43 SANDBOX_EXPORT ErrorCode RestrictMprotectFlags(SandboxBPF* sandbox); |
42 | 44 |
43 // Restrict fcntl(2) cmd argument to: | 45 // Restrict fcntl(2) cmd argument to: |
44 // We allow F_GETFL, F_SETFL, F_GETFD, F_SETFD, F_DUPFD, F_DUPFD_CLOEXEC, | 46 // We allow F_GETFL, F_SETFL, F_GETFD, F_SETFD, F_DUPFD, F_DUPFD_CLOEXEC, |
45 // F_SETLK, F_SETLKW and F_GETLK. | 47 // F_SETLK, F_SETLKW and F_GETLK. |
46 // Also, in F_SETFL, restrict the allowed flags to: O_ACCMODE | O_APPEND | | 48 // Also, in F_SETFL, restrict the allowed flags to: O_ACCMODE | O_APPEND | |
47 // O_NONBLOCK | O_SYNC | O_LARGEFILE | O_CLOEXEC | O_NOATIME. | 49 // O_NONBLOCK | O_SYNC | O_LARGEFILE | O_CLOEXEC | O_NOATIME. |
48 ErrorCode RestrictFcntlCommands(SandboxBPF* sandbox); | 50 SANDBOX_EXPORT ErrorCode RestrictFcntlCommands(SandboxBPF* sandbox); |
49 | 51 |
50 #if defined(__i386__) | 52 #if defined(__i386__) |
51 // Restrict socketcall(2) to only allow socketpair(2), send(2), recv(2), | 53 // Restrict socketcall(2) to only allow socketpair(2), send(2), recv(2), |
52 // sendto(2), recvfrom(2), shutdown(2), sendmsg(2) and recvmsg(2). | 54 // sendto(2), recvfrom(2), shutdown(2), sendmsg(2) and recvmsg(2). |
53 ErrorCode RestrictSocketcallCommand(SandboxBPF* sandbox); | 55 SANDBOX_EXPORT ErrorCode RestrictSocketcallCommand(SandboxBPF* sandbox); |
54 #endif | 56 #endif |
55 | 57 |
56 } // namespace sandbox. | 58 } // namespace sandbox. |
57 | 59 |
58 #endif // SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SYSCALL_PARAMETERS_RESTRICTIONS_H_ | 60 #endif // SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SYSCALL_PARAMETERS_RESTRICTIONS_H_ |
OLD | NEW |