← All issues

[26] WKDateTimePicker SetForScope writes to freed self

Severity: Medium | Component: WebKit UIProcess iOS forms | 7b904b1

Rated Medium because the diff fixes a UAF in the UI process: a SetForScope RAII guard tied to _isDismissingDatePicker outlived self when [_datePickerController dismissViewControllerAnimated:NO completion:nil] re-entered runloop work that dropped the last reference to the WKDateTimePicker, then wrote NO into freed memory at scope exit.

Source/WebKit/UIProcess/ios/forms/WKDateTimeInputControl.mm

- (void)removeDatePickerPresentation
{
if (_datePickerController) {
if (!_isDismissingDatePicker) {
SetForScope isDismissingDatePicker { _isDismissingDatePicker, YES };
- [_datePickerController dismissViewControllerAnimated:NO completion:nil];
+ [protect(_datePickerController) dismissViewControllerAnimated:NO completion:nil];
}
_datePickerController = nil;
}
}

Use-after-free via RAII scope-guard outliving its enclosing object across an Objective-C re-entrancy boundary.

Three call sites wrapped: removeDatePickerPresentation, plus WKFormPeripheralBase's beginEditing/endEditing for the same controlBeginEditing/controlEndEditing shape. WKDatePickerPopoverController.mm similarly protects a __weak _delegate.

RAII scope guards bound to instance members are a quiet recurring Objective-C++ footgun: C++ enforces RAII destruction order, but Objective-C reference counting doesn't protect the receiver across a synchronous method call. Every SetForScope { self->_member, ... } inside a method that calls into UIKit, delegates, or callback-bearing APIs is a latent UAF unless the receiver is independently retained.

This vulnerability weakens memory safety inside the UI process — more privileged than WebContent and outside the renderer sandbox.