summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 07:50:43 +0000
committerjln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 07:50:43 +0000
commitf4a71e3804c92623798ca2320120c677c6d12866 (patch)
tree8e65836d0414971be3eeb2887e51c1cc5008d3c3
parent2f3c9293c58466150f57ba65aa3f118f2af3d822 (diff)
downloadchromium_src-f4a71e3804c92623798ca2320120c677c6d12866.zip
chromium_src-f4a71e3804c92623798ca2320120c677c6d12866.tar.gz
chromium_src-f4a71e3804c92623798ca2320120c677c6d12866.tar.bz2
Linux, Android: fix call to setpriority(2).
setpriority(), when used with PRIO_PROCESS, should affect the whole process (i.e. thread group). On Linux the system call only affects one thread (this bug is documented in http://man7.org/linux/man-pages/man2/getpriority.2.html) and thus lets the caller specify a tid. This CL changes the call to setpriority(PRIO_PROCESS, tid, ...) to setpriority(PRIO_PROCESS, 0, ...), which is strictly equivalent, albeit slightly more correct. This makes filtering system calls in our sandbox easier, as the current thread id is not known to the BPF filter. BUG=399473 R=mdempsky@chromium.org, willchan@chromium.org Review URL: https://codereview.chromium.org/434803003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286964 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/threading/platform_thread_android.cc16
-rw-r--r--base/threading/platform_thread_linux.cc21
2 files changed, 24 insertions, 13 deletions
diff --git a/base/threading/platform_thread_android.cc b/base/threading/platform_thread_android.cc
index bd0b4b3..f8395e5 100644
--- a/base/threading/platform_thread_android.cc
+++ b/base/threading/platform_thread_android.cc
@@ -65,14 +65,20 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
return;
}
- // setpriority(2) will set a thread's priority if it is passed a tid as
- // the 'process identifier', not affecting the rest of the threads in the
- // process. Setting this priority will only succeed if the user has been
- // granted permission to adjust nice values on the system.
+ // setpriority(2) should change the whole thread group's (i.e. process)
+ // priority. however, on linux it will only change the target thread's
+ // priority. see the bugs section in
+ // http://man7.org/linux/man-pages/man2/getpriority.2.html.
+ // we prefer using 0 rather than the current thread id since they are
+ // equivalent but it makes sandboxing easier (https://crbug.com/399473).
DCHECK_NE(handle.id_, kInvalidThreadId);
int kNiceSetting = ThreadNiceValue(priority);
- if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting))
+ const PlatformThreadId current_id = PlatformThread::CurrentId();
+ if (setpriority(PRIO_PROCESS,
+ handle.id_ == current_id ? 0 : handle.id_,
+ kNiceSetting)) {
LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting;
+ }
}
void PlatformThread::SetName(const char* name) {
diff --git a/base/threading/platform_thread_linux.cc b/base/threading/platform_thread_linux.cc
index 636e133..97e0932 100644
--- a/base/threading/platform_thread_linux.cc
+++ b/base/threading/platform_thread_linux.cc
@@ -75,22 +75,27 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
ThreadPriority priority) {
#if !defined(OS_NACL)
if (priority == kThreadPriority_RealtimeAudio) {
- const struct sched_param kRealTimePrio = { 8 };
+ const struct sched_param kRealTimePrio = {8};
if (pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0) {
// Got real time priority, no need to set nice level.
return;
}
}
- // setpriority(2) will set a thread's priority if it is passed a tid as
- // the 'process identifier', not affecting the rest of the threads in the
- // process. Setting this priority will only succeed if the user has been
- // granted permission to adjust nice values on the system.
+ // setpriority(2) should change the whole thread group's (i.e. process)
+ // priority. however, on linux it will only change the target thread's
+ // priority. see the bugs section in
+ // http://man7.org/linux/man-pages/man2/getpriority.2.html.
+ // we prefer using 0 rather than the current thread id since they are
+ // equivalent but it makes sandboxing easier (https://crbug.com/399473).
DCHECK_NE(handle.id_, kInvalidThreadId);
const int kNiceSetting = ThreadNiceValue(priority);
- if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) {
- DVPLOG(1) << "Failed to set nice value of thread ("
- << handle.id_ << ") to " << kNiceSetting;
+ const PlatformThreadId current_id = PlatformThread::CurrentId();
+ if (setpriority(PRIO_PROCESS,
+ handle.id_ == current_id ? 0 : handle.id_,
+ kNiceSetting)) {
+ DVPLOG(1) << "Failed to set nice value of thread (" << handle.id_ << ") to "
+ << kNiceSetting;
}
#endif // !defined(OS_NACL)
}