summaryrefslogtreecommitdiff
path: root/ipc/chromium/src/base/lock_impl_posix.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/chromium/src/base/lock_impl_posix.cc')
-rw-r--r--ipc/chromium/src/base/lock_impl_posix.cc80
1 files changed, 58 insertions, 22 deletions
diff --git a/ipc/chromium/src/base/lock_impl_posix.cc b/ipc/chromium/src/base/lock_impl_posix.cc
index 0513cf0e65..b0fbfe5f04 100644
--- a/ipc/chromium/src/base/lock_impl_posix.cc
+++ b/ipc/chromium/src/base/lock_impl_posix.cc
@@ -1,49 +1,85 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/lock_impl.h"
#include <errno.h>
+#include <string.h>
#include "base/logging.h"
+#include "base/lock.h"
+
+namespace base {
+namespace internal {
+
+#define PRIORITY_INHERITANCE_LOCKS_POSSIBLE() 1
LockImpl::LockImpl() {
-#ifndef NDEBUG
- // In debug, setup attributes for lock error checking.
pthread_mutexattr_t mta;
int rv = pthread_mutexattr_init(&mta);
- DCHECK_EQ(rv, 0);
+
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+#if PRIORITY_INHERITANCE_LOCKS_POSSIBLE()
+ if (PriorityInheritanceAvailable()) {
+ rv = pthread_mutexattr_setprotocol(&mta, PTHREAD_PRIO_INHERIT);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+ }
+#endif
+#ifndef NDEBUG
+ // In debug, setup attributes for lock error checking.
rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
- DCHECK_EQ(rv, 0);
- rv = pthread_mutex_init(&os_lock_, &mta);
- DCHECK_EQ(rv, 0);
- rv = pthread_mutexattr_destroy(&mta);
- DCHECK_EQ(rv, 0);
-#else
- // In release, go with the default lock attributes.
- pthread_mutex_init(&os_lock_, NULL);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
#endif
+ rv = pthread_mutex_init(&native_handle_, &mta);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+ rv = pthread_mutexattr_destroy(&mta);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
}
LockImpl::~LockImpl() {
- int rv = pthread_mutex_destroy(&os_lock_);
- DCHECK_EQ(rv, 0);
+ int rv = pthread_mutex_destroy(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
}
bool LockImpl::Try() {
- int rv = pthread_mutex_trylock(&os_lock_);
- DCHECK(rv == 0 || rv == EBUSY);
- return rv == 0;
+ int rv = pthread_mutex_trylock(&native_handle_);
+ DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv);
}
void LockImpl::Lock() {
- int rv = pthread_mutex_lock(&os_lock_);
- DCHECK_EQ(rv, 0);
+ int rv = pthread_mutex_lock(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
}
void LockImpl::Unlock() {
- int rv = pthread_mutex_unlock(&os_lock_);
- DCHECK_EQ(rv, 0);
+ int rv = pthread_mutex_unlock(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+// static
+bool LockImpl::PriorityInheritanceAvailable() {
+#if PRIORITY_INHERITANCE_LOCKS_POSSIBLE() && defined(OS_MACOSX)
+ return true;
+#else
+ // Security concerns prevent the use of priority inheritance mutexes on Linux.
+ // * CVE-2010-0622 - wake_futex_pi unlocks incorrect, possible DoS.
+ // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-0622
+ // * CVE-2012-6647 - Linux < 3.5.1, futex_wait_requeue_pi possible DoS.
+ // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-6647
+ // * CVE-2014-3153 - Linux <= 3.14.5, futex_requeue, privilege escalation.
+ // https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3153
+ //
+ // If the above were all addressed, we still need a runtime check to deal with
+ // the bug below.
+ // * glibc Bug 14652: https://sourceware.org/bugzilla/show_bug.cgi?id=14652
+ // Fixed in glibc 2.17.
+ // Priority inheritance mutexes may deadlock with condition variables
+ // during recacquisition of the mutex after the condition variable is
+ // signalled.
+ return false;
+#endif
}
+
+} // namespace internal
+} // namespace base