[26] WKDateTimePicker SetForScope writes to freed self
Medium severity로 분류됩니다. diff는 UI process 내의 UAF를 수정합니다.
[_datePickerController dismissViewControllerAnimated:NO completion:nil]호출 도중 runloop 작업이 재진입하면서WKDateTimePicker에 대한 마지막 reference가 해제됩니다. 이때_isDismissingDatePicker에 바인딩된SetForScopeRAII guard가self보다 오래 살아남아, scope 종료 시점에 이미 해제된 메모리에NO를 기록했습니다.
Source/WebKit/UIProcess/ios/forms/WKDateTimeInputControl.mm
Objective-C re-entrancy 경계에서 RAII scope-guard가 enclosing 객체보다 오래 살아남아 발생하는 use-after-free.
총 세 곳의 호출 지점이 수정되었습니다. removeDatePickerPresentation 외에, WKFormPeripheralBase의 beginEditing/endEditing(controlBeginEditing/controlEndEditing 패턴)도 동일하게 처리되었습니다. 한편 WKDatePickerPopoverController.mm에서도 같은 방식으로 __weak _delegate를 보호합니다.
인스턴스 멤버에 바인딩된 RAII scope guard는 Objective-C++에서 조용히 반복되는 함정입니다. C++는 RAII 소멸 순서를 강제하지만, Objective-C reference counting은 동기 메서드 호출에 걸친 receiver를 보호하지 않습니다. 결과적으로, UIKit, delegate, 또는 callback이 있는 API를 호출하는 메서드 내부에서 SetForScope { self->_member, ... } 패턴을 사용하면, receiver가 별도로 retain되지 않는 한 잠재적인 UAF 상태가 됩니다.
이 vulnerability는 UI process 내부의 memory safety를 약화시킵니다. UI process는 WebContent보다 높은 권한을 가지며, renderer sandbox 외부에서 실행됩니다.
Audit directions
SetForScopein-[]methods bracketing synchronous Objective-C calls.Source/WebKit/UIProcess/ios/에서SetForScope.*_이후 동일 scope 내에[_또는[self가 이어지는 패턴을 검색해야 합니다. receiver가protect(...)로 retain되어 있거나, 지역 변수RetainPtr로 유지되는지 확인해야 합니다.- Synchronous UIKit calls invoked from IPC handlers. IPC handler에서 호출되는 동기 UIKit 함수를 점검해야 합니다.
WKFormSelectControl,WKFormColorControl,WKFormInputSession등 form-peripheral 클래스에서protect(...)없이 멤버 ivar에 대해dismissViewController,endEditing:,resignFirstResponder,removeFromSuperview를 호출하는 지점이 대상입니다. __weakivars dereferenced multiple times in one method. 한 메서드 내에서__weakivar를 여러 번 역참조하는 경우를 살펴봐야 합니다. 각 접근은 독립적인 로드이며, dealloc과의 race condition이 발생할 가능성이 있습니다.- Stack-allocated RAII whose destructor depends on
self.TemporaryChange,makeScopeExit([this]{...}), 그리고 Objective-C 메서드 내부에서this를 캡처하는 cleanup 코드를 점검해야 합니다.