| 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 <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <sys/resource.h> | 6 #include <sys/resource.h> |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return seccomp_bpf_supported_; | 245 return seccomp_bpf_supported_; |
| 246 } | 246 } |
| 247 | 247 |
| 248 bool LinuxSandbox::LimitAddressSpace(const std::string& process_type) { | 248 bool LinuxSandbox::LimitAddressSpace(const std::string& process_type) { |
| 249 (void) process_type; | 249 (void) process_type; |
| 250 #if defined(__x86_64__) && !defined(ADDRESS_SANITIZER) | 250 #if defined(__x86_64__) && !defined(ADDRESS_SANITIZER) |
| 251 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 251 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 252 if (command_line->HasSwitch(switches::kNoSandbox)) { | 252 if (command_line->HasSwitch(switches::kNoSandbox)) { |
| 253 return false; | 253 return false; |
| 254 } | 254 } |
| 255 // Limit the address space to 8GB. | 255 // Limit the address space to 4GB. |
| 256 const rlim_t kNewAddressSpaceMaxSize = 0x200000000L; | 256 const rlim_t kNewAddressSpaceMaxSize = 0x100000000L; |
| 257 struct rlimit old_address_space_limit; | 257 struct rlimit old_address_space_limit; |
| 258 if (getrlimit(RLIMIT_AS, &old_address_space_limit)) | 258 if (getrlimit(RLIMIT_AS, &old_address_space_limit)) |
| 259 return false; | 259 return false; |
| 260 // Make sure we don't raise the existing limit. | 260 // Make sure we don't raise the existing limit. |
| 261 const struct rlimit new_address_space_limit = { | 261 const struct rlimit new_address_space_limit = { |
| 262 std::min(old_address_space_limit.rlim_cur, kNewAddressSpaceMaxSize), | 262 std::min(old_address_space_limit.rlim_cur, kNewAddressSpaceMaxSize), |
| 263 std::min(old_address_space_limit.rlim_max, kNewAddressSpaceMaxSize) | 263 std::min(old_address_space_limit.rlim_max, kNewAddressSpaceMaxSize) |
| 264 }; | 264 }; |
| 265 int rc = setrlimit(RLIMIT_AS, &new_address_space_limit); | 265 int rc = setrlimit(RLIMIT_AS, &new_address_space_limit); |
| 266 return (rc == 0); | 266 return (rc == 0); |
| 267 #else | 267 #else |
| 268 return false; | 268 return false; |
| 269 #endif // __x86_64__ && !defined(ADDRESS_SANITIZER) | 269 #endif // __x86_64__ && !defined(ADDRESS_SANITIZER) |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace content | 272 } // namespace content |
| 273 | 273 |
| OLD | NEW |