summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdy Abraham <adyabr@google.com>2022-06-06 15:16:06 -0700
committerAdy Abraham <adyabr@google.com>2022-06-07 00:17:21 +0000
commit0840cdd08f39994e3f8c58eb65f24a8db1dc1173 (patch)
tree9f26f67acb39d731cec6ab8acca759b1d4d92ff3
parent224d576c0bd7f5c29356f208d60fcfa274671c52 (diff)
downloadnative-0840cdd08f39994e3f8c58eb65f24a8db1dc1173.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.cpp5
-rw-r--r--services/surfaceflinger/Scheduler/EventThread.h3
2 files changed, 7 insertions, 1 deletions
diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp
index 05bad4ddd8..e5711c2e84 100644
--- a/services/surfaceflinger/Scheduler/EventThread.cpp
+++ b/services/surfaceflinger/Scheduler/EventThread.cpp
@@ -123,6 +123,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 61530c62e5..15f21d5dec 100644
--- a/services/surfaceflinger/Scheduler/EventThread.h
+++ b/services/surfaceflinger/Scheduler/EventThread.h
@@ -86,7 +86,8 @@ public:
private:
virtual void onFirstRef();
EventThread* const mEventThread;
- gui::BitTube mChannel;
+ std::mutex mLock;
+ gui::BitTube mChannel GUARDED_BY(mLock);
};
class EventThread {