VideoFrames cannot be created asynchronously in WebContent process
Component: WebKit GPU Process media | 6d5870d
Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp
GPU process의 RemoteVideoFrameObjectHeap은 RemoteVideoFrameReference ID를 살아 있는 VideoFrame 객체에 매핑합니다. WebContent 쪽은 이 frame들을 가리키는 RemoteVideoFrameProxy 객체를 보유합니다. 이후 frame을 그리거나 encode, sampling해야 할 때 해당 reference를 GPU process로 다시 전달합니다. WebGL, 2D canvas, WebGPU external texture, WebRTC encoder가 여기에 해당합니다.
이전에는 GPU process가 ID를 동기적으로 할당하고 reply에 담아 반환했습니다. 이 ID는 ObjectIdentifier domain에서 발급되는데, GPU process가 재시작되면 같은 base부터 다시 발급을 시작합니다. 그래서 이미 종료된 GPU process가 발급한 ID가 새 process에서는 전혀 무관한 frame을 가리킬 수 있습니다.
이번 변경으로 WebContent가 요청하는 frame에 대해서는 reference를 WebContent가 직접 할당하게 되었습니다. 할당된 reference는 RemoteGraphicsContextGL::SurfaceBufferToVideoFrame, RemoteAudioVideoRendererProxyManager::CurrentVideoFrame, RemoteMediaPlayerProxy::VideoFrameForCurrentTimeIfChanged에 새 인자로 추가되어 전달됩니다. GPU process는 새로 추가된 add(reference, frame)으로 frame을 저장하고, RemoteVideoFrameProxy::properties()로 reply를 구성합니다.
한편 GPU process가 자체적으로 생성하는 frame은 여전히 GPU process가 할당한 reference를 사용합니다. metadata, WebRTC decoder 출력, capture가 여기에 속합니다. 다만 이 reference는 이제 PushVideoFrameMetadata, CompletedDecoding, VideoFrameAvailable의 별도 인자로 전달됩니다. 또한 RemoteVideoFrameProxy::newReadReference()와 SharedVideoFrameWriter::write()가 IPC connection을 인자로 받도록 변경되었습니다. frame이 다른 GPU process connection에 묶여 있으면 두 함수 모두 실패합니다.
Before: After:
WebContent GPUProcess WebContent GPUProcess
│ Request ───────► │ │ reserve ref (WCP domain)
│ ├ heap.add(frame)→ref │ Request(ref) ───────► │
│ ◄── Properties(ref) ┤ │ ├ props = properties(frame)
│ (blocks for ID) │ ◄── Properties ───────┤ heap.add(ref, frame)
│ newReadReference(conn) -> fails if frame bound
│ to a different GPUP connection
Significance
WebContent에서 reference를 미리 확보해 두면, fast path에서 video frame reference를 비동기적으로 생성할 수 있습니다. 더 빠른 frame 전달을 위한 기반 작업인 셈입니다. 이제 GPU process는 신뢰도가 낮은 WebContent process가 정한 ID로 frame을 등록하며, 이 경로는 WebGL, media player, audio/video renderer entry point 전반에 걸쳐 있습니다. 최상위 bit 기준으로 domain을 나눈 덕분에 두 process의 ID는 서로 충돌하지 않습니다. 또한 connection binding이 이전 GPU process에서 넘어온 stale ID를 걸러냅니다.
Audit directions
신뢰 관계에서 바뀐 지점은 ID가 이제 renderer에서 온다는 것입니다. 따라서 점검의 초점은 GPU process가 직접 발급하지 않은 ID를 어떻게 다루는지에 맞춰집니다.
RemoteVideoFrameObjectHeap::add(reference, frame)은 domain 검증을 수행하지 않으며, 삽입 성공 여부도ASSERT로만 확인합니다.isInGPUProcessObjectIdentifierDomain은get()에서만 참조됩니다. compromised WebContent가 중복된 reference나 이미 사용 중인 reference, 혹은 GPU process domain의 reference를 전달했을 때 무엇을 얻을 수 있는지 확인해야 합니다. 아울러 release build에서 해당 frame이 조용히 버려지는지, 아니면 alias되는지도 살펴볼 필요가 있습니다.get()은 이제 GPU domain 밖의 reference에 대해 최대 10초까지 대기합니다. 끝내 채워지지 않는 reference가 있으면, 요청마다 consumer의 work queue가 최대 10초씩 멈출 수 있습니다. 먼저 어느 queue에서get()이 실행되는지 확인해야 합니다. 예를 들어 WebGLcopyTextureFromVideoFrame은 자체 stream에서 실행됩니다. 이 대기가 실질적인 DoS로 이어지는지, 혹은 frame을 생성하는 요청과의 사이에 race window를 만드는지도 점검 대상입니다.- Stale ID에 대한 방어는 WebContent 쪽의
newReadReference(connection)과SharedVideoFrameWriter::write()에 있습니다. 모든 호출 지점은 자신의 stream이 생성된 connection을 전달해야 합니다. WebGL, 2D canvasdrawVideoFrame, WebGPU device/queue, encoder, display layer가 모두 해당합니다. 한 곳이라도 누락되거나 GPU process 재시작 이후 connection이 바뀌면, aliasing 문제가 다시 생깁니다. - WebContent가 reference를 확보한 뒤 GPU process가
nullopt를 반환하는 경우가 있습니다. 이때 존재한 적 없는 heap entry를 가리키는 객체가 남아 있어서는 안 됩니다. 제거된releaseUnused()도 함께 검토할 필요가 있습니다. - 변경 파일이 약 45개에 달하는 만큼, message signature가 어긋나거나 호출 지점 하나가 누락되었을 가능성도 존재합니다.