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 #if defined(__i386__) || defined(__x86_64__) | |
662 case __NR_mmap: // TODO(jln): to restrict flags. | |
663 #endif | |
664 #if defined(__i386__) || defined(__arm__) | |
665 case __NR_mmap2: | |
666 #endif | |
667 case __NR_mprotect: | |
668 case __NR_munlock: | 661 case __NR_munlock: |
669 case __NR_munmap: | 662 case __NR_munmap: |
670 return true; | 663 return true; |
671 case __NR_madvise: | 664 case __NR_madvise: |
672 case __NR_mincore: | 665 case __NR_mincore: |
673 case __NR_mlockall: | 666 case __NR_mlockall: |
674 #if defined(__i386__) || defined(__x86_64__) | 667 #if defined(__i386__) || defined(__x86_64__) |
668 case __NR_mmap: | |
669 #endif | |
670 #if defined(__i386__) || defined(__arm__) | |
671 case __NR_mmap2: | |
672 #endif | |
673 #if defined(__i386__) || defined(__x86_64__) | |
675 case __NR_modify_ldt: | 674 case __NR_modify_ldt: |
676 #endif | 675 #endif |
676 case __NR_mprotect: | |
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: |
681 case __NR_remap_file_pages: | 681 case __NR_remap_file_pages: |
682 #if defined(__i386__) | 682 #if defined(__i386__) |
683 case __NR_vm86: | 683 case __NR_vm86: |
684 case __NR_vm86old: | 684 case __NR_vm86old: |
685 #endif | 685 #endif |
686 default: | 686 default: |
(...skipping 542 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 // The flags you see are actually the allowed ones, and the variable is a | |
1241 // "denied" mask because of the negation operator. | |
1242 // Significantly, we don't permit MAP_HUGETLB, or the newer flags such as | |
1243 // MAP_POPULATE. | |
1244 uint32_t denied_mask = ~(MAP_SHARED | MAP_PRIVATE | MAP_ANONYMOUS | | |
1245 MAP_STACK | MAP_NORESERVE | MAP_FIXED); | |
1246 return sandbox->Cond(3, ErrorCode::TP_32BIT, ErrorCode::OP_HAS_ANY_BITS, | |
1247 denied_mask, | |
1248 sandbox->Trap(CrashSIGSYS_Handler, NULL), | |
1249 ErrorCode(ErrorCode::ERR_ALLOWED)); | |
1250 } | |
1251 | |
1252 ErrorCode RestrictMprotectFlags(Sandbox *sandbox) { | |
1253 // The flags you see are actually the allowed ones, and the variable is a | |
1254 // "denied" mask because of the negation operator. | |
1255 // Significantly, we don't permit weird undocumented flags such as | |
1256 // PROT_GROWSDOWN. | |
1257 uint32_t denied_mask = ~(PROT_READ | PROT_WRITE | PROT_EXEC); | |
1258 return sandbox->Cond(2, ErrorCode::TP_32BIT, ErrorCode::OP_HAS_ANY_BITS, | |
1259 denied_mask, | |
1260 sandbox->Trap(CrashSIGSYS_Handler, NULL), | |
1261 ErrorCode(ErrorCode::ERR_ALLOWED)); | |
1262 } | |
1263 | |
1239 ErrorCode BaselinePolicy(Sandbox *sandbox, int sysno) { | 1264 ErrorCode BaselinePolicy(Sandbox *sandbox, int sysno) { |
1265 if (IsBaselinePolicyAllowed(sysno)) { | |
1266 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
1267 } | |
1268 | |
1269 #if defined(__i386__) | |
1270 // socketcall(2) should be tightened. | |
1271 if (IsSocketCall(sysno)) { | |
1272 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
1273 } | |
1274 #endif | |
1275 | |
1240 #if defined(__x86_64__) || defined(__arm__) | 1276 #if defined(__x86_64__) || defined(__arm__) |
1241 if (sysno == __NR_socketpair) { | 1277 if (sysno == __NR_socketpair) { |
jln (DO NOT USE THIS)
2013/05/15 23:26:25
I had the memory that socketpair was allowed in Is
| |
1242 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. | 1278 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. |
1243 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); | 1279 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); |
1244 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, | 1280 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, |
1245 ErrorCode(ErrorCode::ERR_ALLOWED), | 1281 ErrorCode(ErrorCode::ERR_ALLOWED), |
1246 sandbox->Trap(CrashSIGSYS_Handler, NULL)); | 1282 sandbox->Trap(CrashSIGSYS_Handler, NULL)); |
1247 } | 1283 } |
1248 #endif | 1284 #endif |
1285 | |
1249 if (sysno == __NR_madvise) { | 1286 if (sysno == __NR_madvise) { |
1250 // Only allow MADV_DONTNEED (aka MADV_FREE). | 1287 // Only allow MADV_DONTNEED (aka MADV_FREE). |
1251 return sandbox->Cond(2, ErrorCode::TP_32BIT, | 1288 return sandbox->Cond(2, ErrorCode::TP_32BIT, |
1252 ErrorCode::OP_EQUAL, MADV_DONTNEED, | 1289 ErrorCode::OP_EQUAL, MADV_DONTNEED, |
1253 ErrorCode(ErrorCode::ERR_ALLOWED), | 1290 ErrorCode(ErrorCode::ERR_ALLOWED), |
1254 ErrorCode(EPERM)); | 1291 ErrorCode(EPERM)); |
1255 } | 1292 } |
1256 | 1293 |
1257 if (IsBaselinePolicyAllowed(sysno)) { | 1294 #if defined(__i386__) || defined(__x86_64__) |
1258 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1295 if (sysno == __NR_mmap) { |
1296 if (IsArchitectureX86_64()) | |
1297 return RestrictMmapFlags(sandbox); | |
1298 else | |
1299 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
1259 } | 1300 } |
1301 #endif | |
1260 | 1302 |
1261 #if defined(__i386__) | 1303 #if defined(__i386__) || defined(__arm__) |
1262 // socketcall(2) should be tightened. | 1304 if (sysno == __NR_mmap2) { |
1263 if (IsSocketCall(sysno)) { | |
1264 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1305 return ErrorCode(ErrorCode::ERR_ALLOWED); |
1265 } | 1306 } |
1266 #endif | 1307 #endif |
1267 | 1308 |
1309 if (sysno == __NR_mprotect) { | |
1310 if (IsArchitectureX86_64()) | |
1311 return RestrictMprotectFlags(sandbox); | |
1312 else | |
1313 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
1314 } | |
1315 | |
1268 // TODO(jln): some system calls in those sets are not supposed to | 1316 // TODO(jln): some system calls in those sets are not supposed to |
1269 // return ENOENT. Return the appropriate error. | 1317 // return ENOENT. Return the appropriate error. |
1270 if (IsFileSystem(sysno) || IsCurrentDirectory(sysno)) { | 1318 if (IsFileSystem(sysno) || IsCurrentDirectory(sysno)) { |
1271 return ErrorCode(ENOENT); | 1319 return ErrorCode(ENOENT); |
1272 } | 1320 } |
1273 | 1321 |
1274 if (IsUmask(sysno) || IsDeniedFileSystemAccessViaFd(sysno) || | 1322 if (IsUmask(sysno) || IsDeniedFileSystemAccessViaFd(sysno) || |
1275 IsDeniedGetOrModifySocket(sysno)) { | 1323 IsDeniedGetOrModifySocket(sysno)) { |
1276 return ErrorCode(EPERM); | 1324 return ErrorCode(EPERM); |
1277 } | 1325 } |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1738 // should enable it, enable it or die. | 1786 // should enable it, enable it or die. |
1739 bool started_sandbox = StartBpfSandbox(command_line, process_type); | 1787 bool started_sandbox = StartBpfSandbox(command_line, process_type); |
1740 CHECK(started_sandbox); | 1788 CHECK(started_sandbox); |
1741 return true; | 1789 return true; |
1742 } | 1790 } |
1743 #endif | 1791 #endif |
1744 return false; | 1792 return false; |
1745 } | 1793 } |
1746 | 1794 |
1747 } // namespace content | 1795 } // namespace content |
OLD | NEW |