← All reports

Site Isolation: validate target frame before redispatching iOS selection gestures

Component: WebKit UIProcess | 3ddf01b

Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

+ std::optional<WebCore::FrameIdentifier> sourceFrameID = frameID;
+ if (!sourceFrameID && m_mainFrame)
+ sourceFrameID = m_mainFrame->frameID();
...
- if (protectedThis && remoteUserInputEventData) {
+ if (RefPtr targetFrame = protectedThis && sourceFrameID && remoteUserInputEventData ? protectedThis->frameForRemoteUserInputEventRedispatch(connection, *sourceFrameID, remoteUserInputEventData->targetFrameID) : nullptr) {
...
- protectedThis->selectPositionAtPoint(remoteUserInputEventData->targetFrameID, ...);
+ protectedThis->selectPositionAtPoint(targetFrame->frameID(), ...);

Source/WebKit/UIProcess/WebPageProxy.h

+template<typename Message> using ReplyWithConnection = typename ReplyWithConnectionType<typename Message::Reply>::Type;

Site Isolation 환경에서는 cross-origin frame마다 서로 다른 WebContent process에 위치할 수 있습니다. 이때 UI process는 frame을 대상으로 하는 IPC를 해당 frame을 소유한 process로 라우팅합니다. 한편 iOS selection gesture를 처리하다 보면, 요청을 받은 process의 hit test가 자신이 호스팅하지 않는 cross-origin subframe에 도달하는 경우가 있습니다. 그러면 이 process는 target frame ID와 변환된 좌표로 구성된 RemoteUserInputEventData를 reply로 반환합니다. UI process는 이 정보를 바탕으로 해당 frame의 process에 요청을 다시 전달하게 됩니다.

이번 commit에서는 selectWithGesture, selectPositionAtPoint, selectTextWithGranularityAtPoint, selectPositionAtBoundaryWithDirection, prepareSelectionForContextMenuWithLocationInView, selectWithTwoTouches의 reply handler가 수정되었습니다. 각 handler는 redispatch 직전에 기존 frameForRemoteUserInputEventRedispatch(connection, sourceFrameID, targetFrameID)를 호출하도록 변경되었습니다. 여기서 sourceFrameID는 요청 대상 frame이며, 지정된 frame이 없으면 main frame이 사용됩니다. 또한 reply를 보낸 IPC::Connection을 참조할 수 있도록, reply 타입이 새로운 ReplyWithConnection<>으로 바뀌었습니다. 검증에 실패하면 대부분의 handler는 reply를 보낸 process 자신의 결과로 callback을 실행합니다. 반면 context menu handler는 callbackFunction(false, RevealItem())을 호출합니다. 새로 추가된 테스트는 source frame 자신을 target으로 지정한 위조 reply를 사용합니다.

패치 이전에는 compromised WebContent process가 임의의 FrameIdentifier를 담은 reply를 위조해, 해당 frame을 호스팅하는 process로 UI process가 selection IPC를 보내도록 만드는 것이 이론적으로 가능했습니다. 특히 source frame 자신을 지정하면, UI process가 같은 process에 같은 요청을 끝없이 재전송하게 될 수 있습니다. 새 테스트가 주로 검증하는 것도 바로 이 경우입니다. 결과적으로 이번 수정으로 UI process의 trust boundary에 존재하던 confused deputy 공백이 해소되었습니다.

찾아야 할 패턴은 WebContent의 reply에 FrameIdentifier 같은 routing key가 담겨 있고, UI process가 이를 그대로 이용해 후속 IPC를 보내는 경우입니다. 이번 fix는 호출 지점 단위로 적용되었습니다. 따라서 아직 변환되지 않은 RemoteUserInputEventData나 targetFrameID 사용 지점은 모두 후보가 됩니다. 먼저 살펴볼 곳은 frame 대상 async reply 경로 가운데 기존 INSTANTIATE_SEND_WITH_ASYNC_REPLY_TO_PROCESS_CONTAINING_FRAME macro를 여전히 사용하는 곳입니다. PerformDictionaryLookupAtLocation, CommitPotentialTap, RequestDragStart 등이 여기에 해당합니다. 이 경로들에서 reply에 담긴 frame ID나 redispatch 대상이 검증 없이 사용되는지 확인할 필요가 있습니다.

다음으로 frameForRemoteUserInputEventRedispatch의 본문을 읽어 볼 필요가 있습니다. reply connection, sourceFrameID, targetFrameID 사이에 어떤 관계를 강제하는지 확인해야 합니다. frameID가 없을 때 main frame으로 대체하는 fallback이 지나치게 관대하지 않은지도 함께 점검해야 합니다. 한편 redispatch는 targetFrame->frameID()로 같은 handler에 다시 진입합니다. 그래서 각 hop이 개별적으로는 검증을 통과하더라도, 여러 hop이 이어지면서 여전히 loop가 형성될 수 있는지 살펴봐야 합니다. 또한 capture된 WeakPtr와 callback이 async hop 이후에도 유효하게 유지되는지 검증해야 합니다. 모든 거부 경로에서 callback이 정확히 한 번 실행되는지도 확인 대상입니다. 위조 reply 테스트(countRequestsAndForgeRedispatch)는 reply에 담기는 다른 identifier를 fuzzing할 때 바로 활용할 수 있는 harness입니다.