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 "sandbox/linux/services/broker_process.h" | 5 #include "sandbox/linux/services/broker_process.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <sys/wait.h> | 11 #include <sys/wait.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
20 #include "base/files/scoped_file.h" | 20 #include "base/files/scoped_file.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
23 #include "base/posix/eintr_wrapper.h" | 23 #include "base/posix/eintr_wrapper.h" |
| 24 #include "base/posix/unix_domain_socket_linux.h" |
24 #include "sandbox/linux/tests/test_utils.h" | 25 #include "sandbox/linux/tests/test_utils.h" |
25 #include "sandbox/linux/tests/unit_tests.h" | 26 #include "sandbox/linux/tests/unit_tests.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
28 namespace sandbox { | 29 namespace sandbox { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // Creates and open a temporary file on creation and closes | 33 // Creates and open a temporary file on creation and closes |
33 // and removes it on destruction. | 34 // and removes it on destruction. |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // Don't do anything here, so that ASSERT works in the subfunction as | 428 // Don't do anything here, so that ASSERT works in the subfunction as |
428 // expected. | 429 // expected. |
429 } | 430 } |
430 | 431 |
431 TEST(BrokerProcess, OpenComplexFlagsNoClientCheck) { | 432 TEST(BrokerProcess, OpenComplexFlagsNoClientCheck) { |
432 TestOpenComplexFlags(false /* fast_check_in_client */); | 433 TestOpenComplexFlags(false /* fast_check_in_client */); |
433 // Don't do anything here, so that ASSERT works in the subfunction as | 434 // Don't do anything here, so that ASSERT works in the subfunction as |
434 // expected. | 435 // expected. |
435 } | 436 } |
436 | 437 |
| 438 SANDBOX_DEATH_TEST(BrokerProcess, RecvMsgDescriptorLeak, DEATH_EXIT_CODE(0)) { |
| 439 // Find the lowest available file descriptor currently. |
| 440 const int min_fd = dup(STDIN_FILENO); |
| 441 SANDBOX_ASSERT(min_fd >= 0); |
| 442 SANDBOX_ASSERT(0 == IGNORE_EINTR(close(min_fd))); |
| 443 |
| 444 // Lower our file descriptor limit to just above the current limit so we can |
| 445 // test for descriptor leaks easier. |
| 446 const unsigned kExtraFiles = 8; |
| 447 const struct rlimit new_rlim = {min_fd + kExtraFiles, min_fd + kExtraFiles}; |
| 448 SANDBOX_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &new_rlim)); |
| 449 |
| 450 const char kCpuInfo[] = "/proc/cpuinfo"; |
| 451 std::vector<std::string> read_whitelist; |
| 452 read_whitelist.push_back(kCpuInfo); |
| 453 |
| 454 BrokerProcess open_broker(EPERM, read_whitelist, std::vector<std::string>()); |
| 455 SANDBOX_ASSERT(open_broker.Init(base::Bind(&NoOpCallback))); |
| 456 |
| 457 static const char kBogus[] = "not a pickle"; |
| 458 const std::vector<int> fds(1, STDIN_FILENO); |
| 459 |
| 460 for (unsigned i = 0; i < kExtraFiles; ++i) { |
| 461 SANDBOX_ASSERT(UnixDomainSocket::SendMsg( |
| 462 open_broker.ipc_socketpair(), kBogus, sizeof(kBogus), fds)); |
| 463 } |
| 464 |
| 465 const int fd = open_broker.Open(kCpuInfo, O_RDONLY); |
| 466 SANDBOX_ASSERT(fd >= 0); |
| 467 SANDBOX_ASSERT(0 == IGNORE_EINTR(close(fd))); |
| 468 _exit(0); |
| 469 } |
| 470 |
437 } // namespace sandbox | 471 } // namespace sandbox |
OLD | NEW |