Skip to content

Commit 406adf0

Browse files
Wenhui YangAndroid (Google) Code Review
authored andcommitted
Merge "Include color layers in input list to fix tapjacking vulnerability" into main
2 parents 9d286fc + 1f0301b commit 406adf0

5 files changed

Lines changed: 39 additions & 10 deletions

File tree

services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot,
11781178
auto displayInfo = displayInfoOpt.value_or(sDefaultInfo);
11791179

11801180
if (!requested.hasInputInfo()) {
1181-
snapshot.inputInfo.inputConfig = InputConfig::NO_INPUT_CHANNEL;
1181+
snapshot.inputInfo.inputConfig |= InputConfig::NO_INPUT_CHANNEL;
11821182
}
11831183
fillInputFrameInfo(snapshot.inputInfo, displayInfo.transform, snapshot);
11841184

services/surfaceflinger/FrontEnd/RequestedLayerState.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ bool RequestedLayerState::needsInputInfo() const {
573573
return false;
574574
}
575575

576-
if ((sidebandStream != nullptr) || (externalTexture != nullptr)) {
576+
if (hasBufferOrSidebandStream() || fillsColor()) {
577577
return true;
578578
}
579579

@@ -586,6 +586,15 @@ bool RequestedLayerState::needsInputInfo() const {
586586
windowInfo->inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL);
587587
}
588588

589+
bool RequestedLayerState::hasBufferOrSidebandStream() const {
590+
return ((sidebandStream != nullptr) || (externalTexture != nullptr));
591+
}
592+
593+
bool RequestedLayerState::fillsColor() const {
594+
return !hasBufferOrSidebandStream() && color.r >= 0.0_hf && color.g >= 0.0_hf &&
595+
color.b >= 0.0_hf;
596+
}
597+
589598
bool RequestedLayerState::hasBlur() const {
590599
return backgroundBlurRadius > 0 || blurRegions.size() > 0;
591600
}

services/surfaceflinger/FrontEnd/RequestedLayerState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct RequestedLayerState : layer_state_t {
8888
bool hasValidRelativeParent() const;
8989
bool hasInputInfo() const;
9090
bool needsInputInfo() const;
91+
bool hasBufferOrSidebandStream() const;
92+
bool fillsColor() const;
9193
bool hasBlur() const;
9294
bool hasFrameUpdate() const;
9395
bool hasReadyFrame() const;

services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,32 @@ TEST_F(LayerLifecycleManagerTest, isSimpleBufferUpdate) {
619619
}
620620
}
621621

622-
TEST_F(LayerLifecycleManagerTest, testInputInfoOfRequestedLayerState) {
623-
// By default the layer has no buffer, so it doesn't need an input info
624-
EXPECT_FALSE(getRequestedLayerState(mLifecycleManager, 111)->needsInputInfo());
622+
TEST_F(LayerLifecycleManagerTest, layerWithBufferNeedsInputInfo) {
623+
// If a layer has no buffer or no color, it doesn't have an input info
624+
LayerHierarchyTestBase::createRootLayer(3);
625+
setColor(3, {-1._hf, -1._hf, -1._hf});
626+
mLifecycleManager.commitChanges();
627+
628+
EXPECT_FALSE(getRequestedLayerState(mLifecycleManager, 3)->needsInputInfo());
629+
630+
setBuffer(3);
631+
mLifecycleManager.commitChanges();
632+
633+
EXPECT_TRUE(getRequestedLayerState(mLifecycleManager, 3)->needsInputInfo());
634+
}
635+
636+
TEST_F(LayerLifecycleManagerTest, layerWithColorNeedsInputInfo) {
637+
// If a layer has no buffer or no color, it doesn't have an input info
638+
LayerHierarchyTestBase::createRootLayer(4);
639+
setColor(4, {-1._hf, -1._hf, -1._hf});
640+
mLifecycleManager.commitChanges();
641+
642+
EXPECT_FALSE(getRequestedLayerState(mLifecycleManager, 4)->needsInputInfo());
625643

626-
setBuffer(111);
644+
setColor(4, {1._hf, 0._hf, 0._hf});
627645
mLifecycleManager.commitChanges();
628646

629-
EXPECT_TRUE(getRequestedLayerState(mLifecycleManager, 111)->needsInputInfo());
647+
EXPECT_TRUE(getRequestedLayerState(mLifecycleManager, 4)->needsInputInfo());
630648
}
631649

632650
} // namespace android::surfaceflinger::frontend

services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,17 +2045,17 @@ TEST_F(LayerSnapshotTest, multipleEdgeExtensionIncreaseBoundSizeWithinCrop) {
20452045
}
20462046

20472047
TEST_F(LayerSnapshotTest, shouldUpdateInputWhenNoInputInfo) {
2048-
// By default the layer has no buffer, so we don't expect it to have an input info
2048+
// If a layer has no buffer or no color, it doesn't have an input info
2049+
setColor(111, {-1._hf, -1._hf, -1._hf});
2050+
UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 12, 121, 122, 1221, 13, 2});
20492051
EXPECT_FALSE(getSnapshot(111)->hasInputInfo());
20502052

20512053
setBuffer(111);
2052-
20532054
UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
20542055

20552056
EXPECT_TRUE(getSnapshot(111)->hasInputInfo());
20562057
EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
20572058
gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL));
2058-
EXPECT_FALSE(getSnapshot(2)->hasInputInfo());
20592059
}
20602060

20612061
// content dirty test

0 commit comments

Comments
 (0)