Skip to content

Commit a820057

Browse files
committed
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
1 parent cbe9c10 commit a820057

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

services/surfaceflinger/Scheduler/EventThread.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ void EventThreadConnection::onFirstRef() {
138138
}
139139

140140
status_t EventThreadConnection::stealReceiveChannel(gui::BitTube* outChannel) {
141+
std::scoped_lock lock(mLock);
142+
if (mChannel.initCheck() != NO_ERROR) {
143+
return NAME_NOT_FOUND;
144+
}
145+
141146
outChannel->setReceiveFd(mChannel.moveReceiveFd());
142147
return NO_ERROR;
143148
}

services/surfaceflinger/Scheduler/EventThread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class EventThreadConnection : public BnDisplayEventConnection {
9898
private:
9999
virtual void onFirstRef();
100100
EventThread* const mEventThread;
101-
gui::BitTube mChannel;
101+
std::mutex mLock;
102+
gui::BitTube mChannel GUARDED_BY(mLock);
102103
};
103104

104105
class EventThread {

0 commit comments

Comments
 (0)