From e52a3b607d8b6be8c550a0e0de0e48f630514e5d Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 18 Feb 2020 18:33:38 -0800 Subject: Disallow shrinking threadpool size once started. If a larger threadpool is started, and concurrent binder transactions are cause these threads to actually be started, and then we shrink the threadpool, these extra threads won't be shut down. So, when we detect that this race may happen, we abort with an error. It's best practice to setup a threadpool at process startup time. Bug: 147699567 Test: TH Change-Id: I12d2e6e6b1ebf92c2b2abbfccffb011c4248d8ec --- libs/binder/ProcessState.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libs/binder/ProcessState.cpp') diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index c0f5e31d72..6627618ddf 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -324,6 +324,8 @@ void ProcessState::spawnPooledThread(bool isMain) } status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) { + LOG_ALWAYS_FATAL_IF(mThreadPoolStarted && maxThreads < mMaxThreads, + "Binder threadpool cannot be shrunk after starting"); status_t result = NO_ERROR; if (ioctl(mDriverFD, BINDER_SET_MAX_THREADS, &maxThreads) != -1) { mMaxThreads = maxThreads; -- cgit v1.2.3-59-g8ed1b