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:19:42 +0000 |
commit | a820057ae00dba322b10d47b3711b04519324690 (patch) | |
tree | 9b5c733535da3ea8a8c3ba1ad9d1fb1893007f08 | |
parent | cbe9c105fcdeba79f1722616e8b576c1d45c93a6 (diff) | |
download | native-a820057ae00dba322b10d47b3711b04519324690.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 cee36a121f..cf57664cd5 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -138,6 +138,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()); return NO_ERROR; } diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h index 64acbd72d0..831bf7baa9 100644 --- a/services/surfaceflinger/Scheduler/EventThread.h +++ b/services/surfaceflinger/Scheduler/EventThread.h @@ -98,7 +98,8 @@ public: private: virtual void onFirstRef(); EventThread* const mEventThread; - gui::BitTube mChannel; + std::mutex mLock; + gui::BitTube mChannel GUARDED_BY(mLock); }; class EventThread { |