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 "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 int fd = HANDLE_EINTR( | 150 int fd = HANDLE_EINTR( |
151 open(path.value().c_str(), O_RDWR | O_CREAT | O_EXCL, kOwnerOnly)); | 151 open(path.value().c_str(), O_RDWR | O_CREAT | O_EXCL, kOwnerOnly)); |
152 if (fd == -1 && options.open_existing_deprecated) { | 152 if (fd == -1 && options.open_existing_deprecated) { |
153 // If this doesn't work, try and open an existing file in append mode. | 153 // If this doesn't work, try and open an existing file in append mode. |
154 // Opening an existing file in a world writable directory has two main | 154 // Opening an existing file in a world writable directory has two main |
155 // security implications: | 155 // security implications: |
156 // - Attackers could plant a file under their control, so ownership of | 156 // - Attackers could plant a file under their control, so ownership of |
157 // the file is checked below. | 157 // the file is checked below. |
158 // - Attackers could plant a symbolic link so that an unexpected file | 158 // - Attackers could plant a symbolic link so that an unexpected file |
159 // is opened, so O_NOFOLLOW is passed to open(). | 159 // is opened, so O_NOFOLLOW is passed to open(). |
| 160 #if !defined(OS_AIX) |
160 fd = HANDLE_EINTR( | 161 fd = HANDLE_EINTR( |
161 open(path.value().c_str(), O_RDWR | O_APPEND | O_NOFOLLOW)); | 162 open(path.value().c_str(), O_RDWR | O_APPEND | O_NOFOLLOW)); |
162 | 163 #else |
| 164 // AIX has no 64-bit support for open falgs such as - |
| 165 // O_CLOEXEC, O_NOFOLLOW and O_TTY_INIT. |
| 166 fd = HANDLE_EINTR(open(path.value().c_str(), O_RDWR | O_APPEND)); |
| 167 #endif |
163 // Check that the current user owns the file. | 168 // Check that the current user owns the file. |
164 // If uid != euid, then a more complex permission model is used and this | 169 // If uid != euid, then a more complex permission model is used and this |
165 // API is not appropriate. | 170 // API is not appropriate. |
166 const uid_t real_uid = getuid(); | 171 const uid_t real_uid = getuid(); |
167 const uid_t effective_uid = geteuid(); | 172 const uid_t effective_uid = geteuid(); |
168 struct stat sb; | 173 struct stat sb; |
169 if (fd >= 0 && | 174 if (fd >= 0 && |
170 (fstat(fd, &sb) != 0 || sb.st_uid != real_uid || | 175 (fstat(fd, &sb) != 0 || sb.st_uid != real_uid || |
171 sb.st_uid != effective_uid)) { | 176 sb.st_uid != effective_uid)) { |
172 LOG(ERROR) << | 177 LOG(ERROR) << |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 base::ThreadRestrictions::ScopedAllowIO allow_io; | 412 base::ThreadRestrictions::ScopedAllowIO allow_io; |
408 struct stat file_stat; | 413 struct stat file_stat; |
409 if (HANDLE_EINTR(::fstat(static_cast<int>(handle().fd), &file_stat)) != 0) | 414 if (HANDLE_EINTR(::fstat(static_cast<int>(handle().fd), &file_stat)) != 0) |
410 return false; | 415 return false; |
411 id->first = file_stat.st_dev; | 416 id->first = file_stat.st_dev; |
412 id->second = file_stat.st_ino; | 417 id->second = file_stat.st_ino; |
413 return true; | 418 return true; |
414 } | 419 } |
415 | 420 |
416 } // namespace base | 421 } // namespace base |
OLD | NEW |