Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <asm/unistd.h> | 5 #include <asm/unistd.h> |
| 6 #include <dlfcn.h> | 6 #include <dlfcn.h> |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <linux/audit.h> | 9 #include <linux/audit.h> |
| 10 #include <linux/filter.h> | 10 #include <linux/filter.h> |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 default: | 651 default: |
| 652 return false; | 652 return false; |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 #endif | 655 #endif |
| 656 | 656 |
| 657 bool IsAllowedAddressSpaceAccess(int sysno) { | 657 bool IsAllowedAddressSpaceAccess(int sysno) { |
| 658 switch (sysno) { | 658 switch (sysno) { |
| 659 case __NR_brk: | 659 case __NR_brk: |
| 660 case __NR_mlock: | 660 case __NR_mlock: |
| 661 case __NR_mprotect: | |
| 662 case __NR_munlock: | |
| 663 case __NR_munmap: | |
| 664 return true; | |
| 661 #if defined(__i386__) || defined(__x86_64__) | 665 #if defined(__i386__) || defined(__x86_64__) |
| 662 case __NR_mmap: // TODO(jln): to restrict flags. | 666 case __NR_mmap: |
| 663 #endif | 667 #endif |
| 664 #if defined(__i386__) || defined(__arm__) | 668 #if defined(__i386__) || defined(__arm__) |
| 665 case __NR_mmap2: | 669 case __NR_mmap2: |
| 666 #endif | 670 #endif |
| 667 case __NR_mprotect: | |
| 668 case __NR_munlock: | |
| 669 case __NR_munmap: | |
| 670 return true; | |
| 671 case __NR_madvise: | 671 case __NR_madvise: |
| 672 case __NR_mincore: | 672 case __NR_mincore: |
| 673 case __NR_mlockall: | 673 case __NR_mlockall: |
| 674 #if defined(__i386__) || defined(__x86_64__) | 674 #if defined(__i386__) || defined(__x86_64__) |
| 675 case __NR_modify_ldt: | 675 case __NR_modify_ldt: |
| 676 #endif | 676 #endif |
| 677 case __NR_mremap: | 677 case __NR_mremap: |
| 678 case __NR_msync: | 678 case __NR_msync: |
| 679 case __NR_munlockall: | 679 case __NR_munlockall: |
| 680 case __NR_readahead: | 680 case __NR_readahead: |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 #if defined(__arm__) | 1229 #if defined(__arm__) |
| 1230 IsArmPciConfig(sysno) || | 1230 IsArmPciConfig(sysno) || |
| 1231 #endif | 1231 #endif |
| 1232 IsTimer(sysno)) { | 1232 IsTimer(sysno)) { |
| 1233 return true; | 1233 return true; |
| 1234 } else { | 1234 } else { |
| 1235 return false; | 1235 return false; |
| 1236 } | 1236 } |
| 1237 } | 1237 } |
| 1238 | 1238 |
| 1239 ErrorCode RestrictMmapFlags(Sandbox *sandbox) { | |
| 1240 // These flags are allowed. Significantly, we don't permit MAP_HUGETLB, or | |
| 1241 // the newer flags such as MAP_POPULATE. | |
| 1242 uint32_t mask = ~(MAP_SHARED | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK | | |
| 1243 MAP_NORESERVE | MAP_FIXED); | |
| 1244 return sandbox->Cond(3, ErrorCode::TP_32BIT, ErrorCode::OP_HAS_ANY_BITS, | |
| 1245 mask, sandbox->Trap(CrashSIGSYS_Handler, NULL), | |
| 1246 ErrorCode(ErrorCode::ERR_ALLOWED)); | |
| 1247 } | |
| 1248 | |
| 1239 ErrorCode BaselinePolicy(Sandbox *sandbox, int sysno) { | 1249 ErrorCode BaselinePolicy(Sandbox *sandbox, int sysno) { |
| 1240 #if defined(__x86_64__) || defined(__arm__) | 1250 #if defined(__x86_64__) || defined(__arm__) |
| 1241 if (sysno == __NR_socketpair) { | 1251 if (sysno == __NR_socketpair) { |
| 1242 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. | 1252 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. |
| 1243 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); | 1253 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); |
| 1244 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, | 1254 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, |
| 1245 ErrorCode(ErrorCode::ERR_ALLOWED), | 1255 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1246 sandbox->Trap(CrashSIGSYS_Handler, NULL)); | 1256 sandbox->Trap(CrashSIGSYS_Handler, NULL)); |
| 1247 } | 1257 } |
| 1248 #endif | 1258 #endif |
| 1249 if (sysno == __NR_madvise) { | 1259 switch (sysno) { |
| 1260 case __NR_madvise: | |
| 1250 // Only allow MADV_DONTNEED (aka MADV_FREE). | 1261 // Only allow MADV_DONTNEED (aka MADV_FREE). |
| 1251 return sandbox->Cond(2, ErrorCode::TP_32BIT, | 1262 return sandbox->Cond(2, ErrorCode::TP_32BIT, |
| 1252 ErrorCode::OP_EQUAL, MADV_DONTNEED, | 1263 ErrorCode::OP_EQUAL, MADV_DONTNEED, |
| 1253 ErrorCode(ErrorCode::ERR_ALLOWED), | 1264 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1254 ErrorCode(EPERM)); | 1265 ErrorCode(EPERM)); |
| 1266 #if defined(__x86_64__) | |
|
jln (very slow on Chromium)
2013/05/15 20:03:52
Arg, had missed one important nit:
#ifdef are rea
| |
| 1267 case __NR_mmap: | |
| 1268 return RestrictMmapFlags(sandbox); | |
| 1269 #elif defined(__i386__) | |
| 1270 case __NR_mmap: | |
| 1271 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 1272 #endif | |
| 1273 #if defined(__i386__) || defined(__arm__) | |
| 1274 case __NR_mmap2: | |
| 1275 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 1276 #endif | |
| 1255 } | 1277 } |
| 1256 | 1278 |
| 1257 if (IsBaselinePolicyAllowed(sysno)) { | 1279 if (IsBaselinePolicyAllowed(sysno)) { |
| 1258 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1280 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1259 } | 1281 } |
| 1260 | 1282 |
| 1261 #if defined(__i386__) | 1283 #if defined(__i386__) |
| 1262 // socketcall(2) should be tightened. | 1284 // socketcall(2) should be tightened. |
| 1263 if (IsSocketCall(sysno)) { | 1285 if (IsSocketCall(sysno)) { |
| 1264 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1286 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1754 // should enable it, enable it or die. | 1776 // should enable it, enable it or die. |
| 1755 bool started_sandbox = StartBpfSandbox(command_line, process_type); | 1777 bool started_sandbox = StartBpfSandbox(command_line, process_type); |
| 1756 CHECK(started_sandbox); | 1778 CHECK(started_sandbox); |
| 1757 return true; | 1779 return true; |
| 1758 } | 1780 } |
| 1759 #endif | 1781 #endif |
| 1760 return false; | 1782 return false; |
| 1761 } | 1783 } |
| 1762 | 1784 |
| 1763 } // namespace content | 1785 } // namespace content |
| OLD | NEW |