| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/scoped_file.h" | 5 #include "base/files/scoped_file.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
| 11 #include <errno.h> |
| 11 #include <unistd.h> | 12 #include <unistd.h> |
| 12 | 13 |
| 14 #include "base/debug/alias.h" |
| 13 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 14 #endif | 16 #endif |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 namespace internal { | 19 namespace internal { |
| 18 | 20 |
| 19 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
| 20 | 22 |
| 21 // static | 23 // static |
| 22 void ScopedFDCloseTraits::Free(int fd) { | 24 void ScopedFDCloseTraits::Free(int fd) { |
| 23 // It's important to crash here. | 25 // It's important to crash here. |
| 24 // There are security implications to not closing a file descriptor | 26 // There are security implications to not closing a file descriptor |
| 25 // properly. As file descriptors are "capabilities", keeping them open | 27 // properly. As file descriptors are "capabilities", keeping them open |
| 26 // would make the current process keep access to a resource. Much of | 28 // would make the current process keep access to a resource. Much of |
| 27 // Chrome relies on being able to "drop" such access. | 29 // Chrome relies on being able to "drop" such access. |
| 28 // It's especially problematic on Linux with the setuid sandbox, where | 30 // It's especially problematic on Linux with the setuid sandbox, where |
| 29 // a single open directory would bypass the entire security model. | 31 // a single open directory would bypass the entire security model. |
| 30 PCHECK(0 == IGNORE_EINTR(close(fd))); | 32 int ret = IGNORE_EINTR(close(fd)); |
| 33 |
| 34 // TODO(davidben): Remove this once it's been determined whether |
| 35 // https://crbug.com/603354 is caused by EBADF or a network filesystem |
| 36 // returning some other error. |
| 37 int close_errno = errno; |
| 38 base::debug::Alias(&close_errno); |
| 39 |
| 40 PCHECK(0 == ret); |
| 31 } | 41 } |
| 32 | 42 |
| 33 #endif // OS_POSIX | 43 #endif // OS_POSIX |
| 34 | 44 |
| 35 } // namespace internal | 45 } // namespace internal |
| 36 } // namespace base | 46 } // namespace base |
| OLD | NEW |