Skip to content

Commit 1f0301b

Browse files
author
Wenhui Yang
committed
Include color layers in input list to fix tapjacking vulnerability
We can use this to compute occlusion more accurately in inputdispatcher. Bug: 277076451 Test: app-debug.apk in the bug Test: go/wm-smoke Flag: EXEMPT bugfix Change-Id: I1e155bcf4a6a7ff1b49338ec21bb0e9ee05a54c8
1 parent 7051e5b commit 1f0301b

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
@@ -1162,7 +1162,7 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot,
11621162
auto displayInfo = displayInfoOpt.value_or(sDefaultInfo);
11631163

11641164
if (!requested.hasInputInfo()) {
1165-
snapshot.inputInfo.inputConfig = InputConfig::NO_INPUT_CHANNEL;
1165+
snapshot.inputInfo.inputConfig |= InputConfig::NO_INPUT_CHANNEL;
11661166
}
11671167
fillInputFrameInfo(snapshot.inputInfo, displayInfo.transform, snapshot);
11681168

services/surfaceflinger/FrontEnd/RequestedLayerState.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ bool RequestedLayerState::needsInputInfo() const {
561561
return false;
562562
}
563563

564-
if ((sidebandStream != nullptr) || (externalTexture != nullptr)) {
564+
if (hasBufferOrSidebandStream() || fillsColor()) {
565565
return true;
566566
}
567567

@@ -574,6 +574,15 @@ bool RequestedLayerState::needsInputInfo() const {
574574
windowInfo->inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL);
575575
}
576576

577+
bool RequestedLayerState::hasBufferOrSidebandStream() const {
578+
return ((sidebandStream != nullptr) || (externalTexture != nullptr));
579+
}
580+
581+
bool RequestedLayerState::fillsColor() const {
582+
return !hasBufferOrSidebandStream() && color.r >= 0.0_hf && color.g >= 0.0_hf &&
583+
color.b >= 0.0_hf;
584+
}
585+
577586
bool RequestedLayerState::hasBlur() const {
578587
return backgroundBlurRadius > 0 || blurRegions.size() > 0;
579588
}

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
@@ -1957,17 +1957,17 @@ TEST_F(LayerSnapshotTest, multipleEdgeExtensionIncreaseBoundSizeWithinCrop) {
19571957
}
19581958

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

19631965
setBuffer(111);
1964-
19651966
UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
19661967

19671968
EXPECT_TRUE(getSnapshot(111)->hasInputInfo());
19681969
EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
19691970
gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL));
1970-
EXPECT_FALSE(getSnapshot(2)->hasInputInfo());
19711971
}
19721972

19731973
// content dirty test

0 commit comments

Comments
 (0)