| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/synchronization/lock_impl.h" | 5 #include "base/synchronization/lock_impl.h" |
| 6 | 6 |
| 7 #include <errno.h> | |
| 8 #include <string.h> | 7 #include <string.h> |
| 9 | 8 |
| 10 #include "base/debug/activity_tracker.h" | 9 #include "base/debug/activity_tracker.h" |
| 11 #include "base/logging.h" | |
| 12 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 13 | 11 |
| 14 namespace base { | 12 namespace base { |
| 15 namespace internal { | 13 namespace internal { |
| 16 | 14 |
| 17 // Determines which platforms can consider using priority inheritance locks. Use | 15 // Determines which platforms can consider using priority inheritance locks. Use |
| 18 // this define for platform code that may not compile if priority inheritance | 16 // this define for platform code that may not compile if priority inheritance |
| 19 // locks aren't available. For this platform code, | 17 // locks aren't available. For this platform code, |
| 20 // PRIORITY_INHERITANCE_LOCKS_POSSIBLE() is a necessary but insufficient check. | 18 // PRIORITY_INHERITANCE_LOCKS_POSSIBLE() is a necessary but insufficient check. |
| 21 // Lock::PriorityInheritanceAvailable still must be checked as the code may | 19 // Lock::PriorityInheritanceAvailable still must be checked as the code may |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv); | 56 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv); |
| 59 return rv == 0; | 57 return rv == 0; |
| 60 } | 58 } |
| 61 | 59 |
| 62 void LockImpl::Lock() { | 60 void LockImpl::Lock() { |
| 63 base::debug::ScopedLockAcquireActivity lock_activity(this); | 61 base::debug::ScopedLockAcquireActivity lock_activity(this); |
| 64 int rv = pthread_mutex_lock(&native_handle_); | 62 int rv = pthread_mutex_lock(&native_handle_); |
| 65 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | 63 DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void LockImpl::Unlock() { | |
| 69 int rv = pthread_mutex_unlock(&native_handle_); | |
| 70 DCHECK_EQ(rv, 0) << ". " << strerror(rv); | |
| 71 } | |
| 72 | |
| 73 // static | 66 // static |
| 74 bool LockImpl::PriorityInheritanceAvailable() { | 67 bool LockImpl::PriorityInheritanceAvailable() { |
| 75 #if PRIORITY_INHERITANCE_LOCKS_POSSIBLE() && defined(OS_MACOSX) | 68 #if PRIORITY_INHERITANCE_LOCKS_POSSIBLE() && defined(OS_MACOSX) |
| 76 return true; | 69 return true; |
| 77 #else | 70 #else |
| 78 // Security concerns prevent the use of priority inheritance mutexes on Linux. | 71 // Security concerns prevent the use of priority inheritance mutexes on Linux. |
| 79 // * CVE-2010-0622 - wake_futex_pi unlocks incorrect, possible DoS. | 72 // * CVE-2010-0622 - wake_futex_pi unlocks incorrect, possible DoS. |
| 80 // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-0622 | 73 // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-0622 |
| 81 // * CVE-2012-6647 - Linux < 3.5.1, futex_wait_requeue_pi possible DoS. | 74 // * CVE-2012-6647 - Linux < 3.5.1, futex_wait_requeue_pi possible DoS. |
| 82 // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-6647 | 75 // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-6647 |
| 83 // * CVE-2014-3153 - Linux <= 3.14.5, futex_requeue, privilege escalation. | 76 // * CVE-2014-3153 - Linux <= 3.14.5, futex_requeue, privilege escalation. |
| 84 // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3153 | 77 // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3153 |
| 85 // | 78 // |
| 86 // If the above were all addressed, we still need a runtime check to deal with | 79 // If the above were all addressed, we still need a runtime check to deal with |
| 87 // the bug below. | 80 // the bug below. |
| 88 // * glibc Bug 14652: https://sourceware.org/bugzilla/show_bug.cgi?id=14652 | 81 // * glibc Bug 14652: https://sourceware.org/bugzilla/show_bug.cgi?id=14652 |
| 89 // Fixed in glibc 2.17. | 82 // Fixed in glibc 2.17. |
| 90 // Priority inheritance mutexes may deadlock with condition variables | 83 // Priority inheritance mutexes may deadlock with condition variables |
| 91 // during recacquisition of the mutex after the condition variable is | 84 // during recacquisition of the mutex after the condition variable is |
| 92 // signalled. | 85 // signalled. |
| 93 return false; | 86 return false; |
| 94 #endif | 87 #endif |
| 95 } | 88 } |
| 96 | 89 |
| 97 } // namespace internal | 90 } // namespace internal |
| 98 } // namespace base | 91 } // namespace base |
| OLD | NEW |