diff options
author | Ady Abraham <adyabr@google.com> | 2022-06-06 15:16:06 -0700 |
---|---|---|
committer | Ady Abraham <adyabr@google.com> | 2022-06-07 00:04:26 +0000 |
commit | 97a317064a76b8fc3a65bd980027f820fd4d53ae (patch) | |
tree | 0c5ec0b8ac9cd8aaf5d82635ba4a648e52d12286 | |
parent | f8ce875c134b1e6ce08171c2cb4b4f3232a90b08 (diff) | |
download | native-97a317064a76b8fc3a65bd980027f820fd4d53ae.tar.gz |
RESTRICT AUTOMERGE SurfaceFlinger: fix a potential race condition in stealReceiveChannel
Add a mutex to prevent a potential race condition.
Bug: 232541124
Test: See bug for details
Change-Id: Ia338f124c786bf12d6adba10a67b9048fe9c34a5
-rw-r--r-- | services/surfaceflinger/Scheduler/EventThread.cpp | 5 | ||||
-rw-r--r-- | services/surfaceflinger/Scheduler/EventThread.h | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp index 2bdcaf6ad0..695c2a3787 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -171,6 +171,11 @@ void EventThreadConnection::onFirstRef() { } status_t EventThreadConnection::stealReceiveChannel(gui::BitTube* outChannel) { + std::scoped_lock lock(mLock); + if (mChannel.initCheck() != NO_ERROR) { + return NAME_NOT_FOUND; + } + outChannel->setReceiveFd(mChannel.moveReceiveFd()); outChannel->setSendFd(base::unique_fd(dup(mChannel.getSendFd()))); return NO_ERROR; diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h index 9265a25b86..9526fe18be 100644 --- a/services/surfaceflinger/Scheduler/EventThread.h +++ b/services/surfaceflinger/Scheduler/EventThread.h @@ -102,7 +102,8 @@ public: private: virtual void onFirstRef(); EventThread* const mEventThread; - gui::BitTube mChannel; + std::mutex mLock; + gui::BitTube mChannel GUARDED_BY(mLock); std::vector<DisplayEventReceiver::Event> mPendingEvents; }; |