Use after free in Parcel Tracking (CVE-2024-9961)
A raw pointer to the WebState object is held by the parcel tracking opt-in coordinator without any lifetime observation, so if the WebState is released while the prompt is displayed the pointer dangles. An attacker could then trigger a heap use-after-free when the user taps the AlwaysTrack button and confirms.
- Fix shipped in 2 months
Steps to reproduce the problem
repro:
- apply the patch.
- host the uaf8.html
- wait for display the view then wait for site close, click AlwaysTrack and allow button.
Problem Description
- There is a raw pointer in the marked area that has not been observed, so there is a risk of UAF.
@implementation ParcelTrackingOptInCoordinator {
raw_ptr<web::WebState> _webState; // <--- raw_ptr
NSArray<CustomTextCheckingResult*>* _parcels;
ParcelTrackingOptInMediator* _mediator;
ParcelTrackingOptInViewController* _viewController;
}
- Then, in the
startmethod ofParcelTrackingOptInCoordinator, it is passed toParcelTrackingOptInMediator, and then thepresentViewControlleris called to display the view.
- (void)start {
[super start];
_mediator = [[ParcelTrackingOptInMediator alloc] initWithWebState:_webState]; //
_mediator.parcelTrackingCommandsHandler = HandlerForProtocol(
self.browser->GetCommandDispatcher(), ParcelTrackingOptInCommands);
_viewController = [[ParcelTrackingOptInViewController alloc] init];
_viewController.actionHandler = _viewController;
_viewController.delegate = self;
_viewController.presentationController.delegate = self;
[self.baseViewController presentViewController:_viewController
animated:YES
completion:nil];
base::UmaHistogramBoolean(parcel_tracking::kOptInPromptDisplayedHistogramName,
true);
}
- Then, in the logic of the
AlwaysTrackbutton in its view, once the user selects thealwaysTrackoption and confirms, itsdidTapAlwayTrackmethod will be called. However, if the webState is released while the view is displayed, the marked area_webStatebecomes a hanging pointer. This leads to UAF.
- (void)didTapAlwaysTrack:(NSArray<CustomTextCheckingResult*>*)parcelList {
commerce::ShoppingService* shoppingService =
commerce::ShoppingServiceFactory::GetForBrowserState(
_webState->GetBrowserState()); //!
TrackParcels(shoppingService, parcelList, std::string(),
_parcelTrackingCommandsHandler, true,
TrackingSource::kAutoTrack);
}
[0]. https://source.chromium.org/chromium/chromium/src/+/main:ios/chrome/browser/ui/parcel_tracking/parcel_tracking_opt_in_coordinator.mm;l=26;drc=c55c4a4997144a5ff358f3271f5a304dd1eff57d [1]. https://source.chromium.org/chromium/chromium/src/+/main:ios/chrome/browser/ui/parcel_tracking/parcel_tracking_opt_in_coordinator.mm;l=47;drc=41374c974d98f8cf67134f9ddb8d96d398154dfe;bpv=1;bpt=1 [2]. https://source.chromium.org/chromium/chromium/src/+/main:ios/chrome/browser/ui/parcel_tracking/parcel_tracking_opt_in_mediator.mm;l=30;drc=41374c974d98f8cf67134f9ddb8d96d398154dfe;bpv=0;bpt=1
bitset: https://source.chromium.org/chromium/chromium/src/+/f50e47b4284bf099f85c1dd3903d7d372877b1e9
owner is hiramahmood@。
Notice: why need patch? Because the function requires user login and adding packages, the role of the patch is to add packages that need to be tracked, and then the patch drops the branch that verifies whether to login.
fix suggestions: use weakptr for webstate or observe the lifetime of webstate.
Summary
heap-use-after-free on [ParcelTrackingOptInMediator didTapAlwaysTrack]
Custom Questions
Type of crash:
browser
Crash state:
see asan.log
Additional Data
Category: Security
Chrome Channel: Stable
Regression: N/A
Context
This report describes a use-after-free (UAF) in Chrome for iOS, in the Parcel Tracking opt-in flow. Parcel Tracking is the feature that watches for parcels in the user's email and offers to track them; the opt-in coordinator is the object that presents the prompt asking the user whether to track parcels automatically. The bug was reported through the Chrome VRP, rated medium severity, and paid a bounty of 2000.00 USD. It was disclosed on 2024-10-15 and assigned CVE-2024-9961. The researchers are lime (@limeSec_) and fmyy (@binary_fmyy) from the TIANGONG Team of Legendsec at QI-ANXIN Group.
The crash is a heap-use-after-free on [ParcelTrackingOptInMediator didTapAlwaysTrack], in the browser process.
Setup
The report gives no information about the Chrome version tested, the iOS version, the device, or any tooling beyond the patch described below. What it does state is a precondition: the reproduction needs a patch, because the normal flow requires the user to be logged in and to have added packages. The patch adds packages that need to be tracked and drops the branch that verifies whether the user is logged in. The patch itself is not included in the report.
The reproduction also needs a page, uaf8.html, hosted somewhere the browser can load it. The contents of that page are not given.
Finding it
The researcher points at the instance variables of ParcelTrackingOptInCoordinator and singles out one of them: _webState is stored as a raw_ptr<web::WebState>, while the other members are Objective-C object pointers.
@implementation ParcelTrackingOptInCoordinator {
raw_ptr<web::WebState> _webState; // <--- raw_ptr
NSArray<CustomTextCheckingResult*>* _parcels;
ParcelTrackingOptInMediator* _mediator;
ParcelTrackingOptInViewController* _viewController;
}
A raw pointer to a WebState that is not observed means nothing keeps the WebState alive for as long as the coordinator holds it, so there is a risk of UAF. The report links the line in parcel_tracking_opt_in_coordinator.mm where this member is declared.
Exploitation
Step 1: apply the patch
The patch is applied to the build under test. Its purpose, as the report explains, is to add the packages that need to be tracked and to drop the branch that verifies whether the user is logged in, so the flow can be reached without a logged-in account with real parcels.
Step 2: host the page
host the uaf8.html
The page is hosted and then loaded in the browser. The report does not describe what the page contains or which API it uses.
Step 3: drive the prompt
wait for display the view then wait for site close, click AlwaysTrack and allow button.
Wait until the opt-in view is displayed, then wait for the site to close, then click the AlwaysTrack button and the allow button. The order matters: the site is closed while the opt-in view is still on screen, and only afterwards does the user confirm automatic tracking.
What happens in the code
When the coordinator starts, it hands its _webState to a newly created ParcelTrackingOptInMediator and then presents the view controller.
- (void)start {
[super start];
_mediator = [[ParcelTrackingOptInMediator alloc] initWithWebState:_webState]; //
_mediator.parcelTrackingCommandsHandler = HandlerForProtocol(
self.browser->GetCommandDispatcher(), ParcelTrackingOptInCommands);
_viewController = [[ParcelTrackingOptInViewController alloc] init];
_viewController.actionHandler = _viewController;
_viewController.delegate = self;
_viewController.presentationController.delegate = self;
[self.baseViewController presentViewController:_viewController
animated:YES
completion:nil];
base::UmaHistogramBoolean(parcel_tracking::kOptInPromptDisplayedHistogramName,
true);
}
The mediator receives the same unobserved pointer. The view is presented with animated:YES.
When the user selects the alwaysTrack option and confirms, the view calls didTapAlwaysTrack. That method dereferences _webState to obtain the browser state and pass it to the shopping service:
- (void)didTapAlwaysTrack:(NSArray<CustomTextCheckingResult*>*)parcelList {
commerce::ShoppingService* shoppingService =
commerce::ShoppingServiceFactory::GetForBrowserState(
_webState->GetBrowserState()); //!
TrackParcels(shoppingService, parcelList, std::string(),
_parcelTrackingCommandsHandler, true,
TrackingSource::kAutoTrack);
}
If the WebState has been released while the view was displayed, _webState is a hanging pointer and the dereference in didTapAlwaysTrack is a use-after-free. The report marks the dereference with //!.
Root cause
The coordinator and the mediator hold a raw_ptr<web::WebState> that is never observed. The _webState pointer is not observed, so nothing keeps the WebState alive while the prompt is displayed. When the site closes, the WebState is destroyed, but the prompt remains and its action handler still holds the stale pointer. Confirming AlwaysTrack then dereferences freed memory.
The report does not describe any existing defence that should have caught this, beyond the fact that the pointer was not observed. The report links the coordinator's member declaration, its start method, and the mediator source.
Impact
The report classifies the crash as a browser-process heap-use-after-free. The report itself does not demonstrate anything beyond the crash and does not describe an exploit. Reaching the vulnerable path requires the user to be shown the parcel tracking opt-in prompt and to confirm automatic tracking after the underlying site has gone away; in the unpatched product the flow also requires a logged-in user with packages to track, which is why the researchers patched the build to bypass the login check.
Fix
The report's suggestion is to use a weakptr for the WebState, or to observe the lifetime of the WebState. Either approach means the mediator no longer dereferences a pointer that may already be dangling when didTapAlwaysTrack runs.
Variants to test
- Other iOS coordinators and mediators that store a
raw_ptr<web::WebState>and present a view controller asynchronously. A positive result is a prompt that survives the destruction of itsWebStateand dereferences it from a button handler. - Any user-confirmation callback that captures a browser state or web state obtained at presentation time rather than at callback time. A positive result is a crash under ASan when the tab or site is closed before the confirmation is tapped.
- Flows where the prompt is presented with
animated:YESand the delegate or action handler is the view controller itself, as in_viewController.actionHandler = _viewController. A positive result is a callback firing after the presenting context has been torn down. - Re-running the same sequence with the site closed at different points (before the prompt appears, while it is animating, after it is fully shown) to see whether the window for the stale pointer is wider than the one described here.
What happened, in plain words
Chrome on iPhone and iPad has a feature called Parcel Tracking. It offers to follow parcels for you. Before it starts following anything, it shows you a small prompt asking whether you want it to track parcels automatically. That prompt is the "opt-in" step: you opt in by agreeing.
The code that shows this prompt is a small object called ParcelTrackingOptInCoordinator. It keeps a reference to a web page (the "site"), stored in a variable called _webState. The problem is the kind of reference it keeps. It is a "raw pointer", which is like writing down someone's home address on a sticky note: the note does not stop the person from moving out. If the site closes while the prompt is still on screen, the thing the pointer points at is destroyed, but the pointer still holds the old address. When you then tap the button that says "Always Track", the code follows that stale address and reads memory that has already been freed. That is a use-after-free, or UAF.
This report was filed through the Chrome VRP (the Chrome Vulnerability Reward Program, Google's scheme for paying people who report security bugs). It was rated medium severity and paid a bounty of 2000.00 USD. It was disclosed on 2024-10-15 and given the identifier CVE-2024-9961. The researchers are lime (@limeSec_) and fmyy (@binary_fmyy) from the TIANGONG Team of Legendsec at QI-ANXIN Group.
The crash happens in the browser process, in a method called [ParcelTrackingOptInMediator didTapAlwaysTrack].
Setup
The report does not say which version of Chrome was tested, which version of iOS, which device, or which tools were used, apart from the patch described below.
What it does say is that you cannot reach the bug in a normal build. The normal flow needs the user to be logged in and to have added packages to track. So the researchers applied a patch to the build under test. The patch does two things: it adds packages that need to be tracked, and it removes the check that verifies whether the user is logged in. In other words, it fakes the situation the feature expects, so the prompt can be reached without a real account full of real parcels. The patch itself is not included in the report.
The reproduction also needs a web page called uaf8.html, hosted somewhere the browser can load it. The report does not give the contents of that page.
Finding it
The researcher starts by looking at the variables that ParcelTrackingOptInCoordinator keeps for itself, and points at one of them in particular.
@implementation ParcelTrackingOptInCoordinator {
raw_ptr<web::WebState> _webState; // <--- raw_ptr
NSArray<CustomTextCheckingResult*>* _parcels;
ParcelTrackingOptInMediator* _mediator;
ParcelTrackingOptInViewController* _viewController;
}
Line by line:
@implementation ParcelTrackingOptInCoordinator {opens the definition of the coordinator class, and the brace after it starts the list of instance variables, the pieces of data each coordinator object carries around.raw_ptr<web::WebState> _webState; // <--- raw_ptrdeclares_webState, the reference to the web page.raw_ptris a plain pointer: it records where theWebStatelives but does nothing to keep it alive. The comment marks it as the suspicious one.NSArray<CustomTextCheckingResult*>* _parcels;is a list of parcels found by scanning text.ParcelTrackingOptInMediator* _mediator;is a helper object that sits between the coordinator and the rest of the browser.ParcelTrackingOptInViewController* _viewController;is the object that draws the prompt on screen.- The closing brace ends the variable list.
Why this matters: the other three members are Objective-C object pointers, which in this codebase are managed in a way that keeps their objects alive while they are referenced. The _webState member is not. Nothing keeps the WebState alive for as long as the coordinator holds it, so there is a risk of a use-after-free. The report links the exact line in parcel_tracking_opt_in_coordinator.mm where this member is declared.
Exploitation
Step 1: apply the patch
The patch is applied to the build under test. As explained above, its purpose is to add the packages that need to be tracked and to drop the branch that checks whether the user is logged in. Without it, you would need a real logged-in account with real parcels before the prompt ever appears.
Step 2: host the page
host the uaf8.html
This is the instruction to put the page uaf8.html somewhere the browser can load it, and then load it in the browser.
Step 3: drive the prompt
wait for display the view then wait for site close, click AlwaysTrack and allow button.
This single line is the whole sequence, and the order is the point:
- Wait until the opt-in view (the prompt) is displayed.
- Wait for the site to close. Closing the site is what destroys the
WebStatethat the coordinator still points at. - Click the
AlwaysTrackbutton. - Click the allow button.
The site is closed while the prompt is still on screen, and only afterwards does the user confirm automatic tracking. That is the moment the stale pointer gets used.
What happens in the code
When the coordinator starts, it hands its _webState to a newly created ParcelTrackingOptInMediator and then presents the view controller.
- (void)start {
[super start];
_mediator = [[ParcelTrackingOptInMediator alloc] initWithWebState:_webState]; //
_mediator.parcelTrackingCommandsHandler = HandlerForProtocol(
self.browser->GetCommandDispatcher(), ParcelTrackingOptInCommands);
_viewController = [[ParcelTrackingOptInViewController alloc] init];
_viewController.actionHandler = _viewController;
_viewController.delegate = self;
_viewController.presentationController.delegate = self;
[self.baseViewController presentViewController:_viewController
animated:YES
completion:nil];
base::UmaHistogramBoolean(parcel_tracking::kOptInPromptDisplayedHistogramName,
true);
}
Line by line:
- (void)start {begins thestartmethod, the routine that runs when the coordinator is launched.[super start];runs the parent class's version ofstartfirst, so the shared setup happens before anything else._mediator = [[ParcelTrackingOptInMediator alloc] initWithWebState:_webState];creates the mediator and passes it the same_webStatepointer. The mediator now holds the same unobserved reference. The comment marker at the end of the line flags this handover._mediator.parcelTrackingCommandsHandler = HandlerForProtocol(starts giving the mediator a handler for parcel tracking commands, obtained from the browser's command dispatcher.self.browser->GetCommandDispatcher(), ParcelTrackingOptInCommands);finishes that call: it fetches the dispatcher from the browser and asks for the parcel tracking command interface._viewController = [[ParcelTrackingOptInViewController alloc] init];creates the object that draws the prompt._viewController.actionHandler = _viewController;makes the view controller its own action handler, so button taps come back to it._viewController.delegate = self;makes the coordinator the view controller's delegate, so it receives lifecycle callbacks._viewController.presentationController.delegate = self;does the same for the presentation controller, which manages how the prompt is shown and dismissed.[self.baseViewController presentViewController:_viewControllerstarts presenting the prompt from the base view controller.animated:YES,asks for the presentation to be animated.completion:nil];passes no completion block, so nothing runs when the animation finishes.base::UmaHistogramBoolean(parcel_tracking::kOptInPromptDisplayedHistogramName,starts recording a metric that the prompt was displayed.true);is the value recorded for that metric.- The closing brace ends the method.
The presentation is animated with animated:YES. That is the window in which the site can close underneath it.
When the user selects the alwaysTrack option and confirms, the view calls didTapAlwaysTrack. That method dereferences _webState to obtain the browser state and pass it to the shopping service:
- (void)didTapAlwaysTrack:(NSArray<CustomTextCheckingResult*>*)parcelList {
commerce::ShoppingService* shoppingService =
commerce::ShoppingServiceFactory::GetForBrowserState(
_webState->GetBrowserState()); //!
TrackParcels(shoppingService, parcelList, std::string(),
_parcelTrackingCommandsHandler, true,
TrackingSource::kAutoTrack);
}
Line by line:
- (void)didTapAlwaysTrack:(NSArray<CustomTextCheckingResult*>*)parcelList {begins the method that runs when the user taps the Always Track button. It receives the list of parcels to track.commerce::ShoppingService* shoppingService =starts declaring a pointer to the shopping service, the part of the browser that handles shopping and parcel features.commerce::ShoppingServiceFactory::GetForBrowserState(asks the factory for the shopping service belonging to a particular browser state._webState->GetBrowserState()); //!is the dangerous part. The arrow means "follow the pointer and call a method on the object it points at". Here the code follows_webStateto get its browser state. The//!marks this dereference as the place where the bug bites.TrackParcels(shoppingService, parcelList, std::string(),starts the call that actually sets up tracking, passing the service, the parcel list and an empty string._parcelTrackingCommandsHandler, true,passes the command handler and a true flag.TrackingSource::kAutoTrack);says the tracking was started automatically, by the Always Track choice.- The closing brace ends the method.
If the WebState has been released while the view was displayed, _webState is a hanging pointer. Following it in didTapAlwaysTrack reads memory that has already been freed: a use-after-free.
Root cause
The coordinator and the mediator both hold a raw_ptr<web::WebState> that is never observed. The _webState pointer is not observed, so nothing keeps the WebState alive. The view controller is presented and can outlive the WebState it was created for. When the site closes, the WebState is destroyed, but the prompt remains and its action handler still holds the stale pointer. Confirming Always Track then dereferences freed memory.
The report links the coordinator's member declaration, its start method, and the mediator source.
Impact
The report classifies the crash as a browser-process heap-use-after-free. The report itself does not demonstrate anything beyond the crash and does not describe an exploit. Reaching the vulnerable path requires the user to be shown the parcel tracking opt-in prompt and to confirm automatic tracking after the underlying site has gone away. In the unpatched product the flow also requires a logged-in user with packages to track, which is why the researchers patched the build to bypass the login check.
Fix
The report's suggestion is to use a weakptr for the WebState, or to observe the lifetime of the WebState. A weak pointer is the opposite of a raw pointer in one important way: it knows when the object it points at has been destroyed, so the code can check before using it. Observing the lifetime means registering to be told when the WebState goes away, so the prompt can be dismissed or its handler cleared at that moment. Either approach means the mediator no longer dereferences a pointer that may already be dangling when didTapAlwaysTrack runs.
Variants to test
- Other iOS coordinators and mediators that store a
raw_ptr<web::WebState>and present a view controller asynchronously. A positive result is a prompt that survives the destruction of itsWebStateand dereferences it from a button handler. - Any user-confirmation callback that captures a browser state or web state obtained at presentation time rather than at callback time. A positive result is a crash under ASan when the tab or site is closed before the confirmation is tapped.
- Flows where the prompt is presented with
animated:YESand the delegate or action handler is the view controller itself, as in_viewController.actionHandler = _viewController. A positive result is a callback firing after the presenting context has been torn down. - Re-running the same sequence with the site closed at different points (before the prompt appears, while it is animating, after it is fully shown) to see whether the window for the stale pointer is wider than the one described here.
Glossary
- ASan: AddressSanitizer, a debugging tool that makes programs crash loudly when they touch memory they should not, such as memory that has already been freed.
- Browser process: the main process of a browser, which manages tabs, windows and features; a bug here is more serious than one in a single tab's rendering process.
- Bounty: money paid by a company to someone who reports a security bug through its programme.
- Chrome VRP: the Chrome Vulnerability Reward Program, Google's scheme for rewarding security reports about Chrome.
- Coordinator: in iOS app code, an object that manages one screen or flow, creating the view controller and wiring up its actions.
- CVE: Common Vulnerabilities and Exposures, a public identifier given to a known security vulnerability, here CVE-2024-9961.
- Dangling pointer: a pointer that still holds the address of an object that has already been destroyed.
- Delegate: an object that another object calls back when something happens, such as a screen appearing or disappearing.
- Dereference: following a pointer to read or use the object it points at.
- Heap-use-after-free: a use-after-free where the freed memory came from the heap, the area programs use for objects created while running.
- Instance variable: a piece of data that each object of a class carries around.
- Mediator: a helper object that sits between a screen and the rest of the app and carries out actions on its behalf.
- Memory corruption: a bug where a program reads or writes memory it should not, which can sometimes be abused to run attacker-chosen code.
- Objective-C: the programming language used for much of Apple's iOS and macOS software; the code in this report is Objective-C.
- Opt-in: a step where the user explicitly agrees to a feature before it is turned on.
- Parcel Tracking: the Chrome feature that finds parcels in the user's email and offers to follow them.
- Patch: a change applied to source code before building a program; here, a test-only change to skip the login check and add parcels.
- Prompt: the on-screen question asking the user whether to enable automatic parcel tracking.
- Raw pointer: a plain reference to an object that does not keep the object alive and does not know if it has been destroyed.
- Severity: a rating of how serious a vulnerability is; this one was rated medium.
- UAF (use-after-free): using an object after it has been destroyed, so the program reads or writes memory that may now belong to something else.
- View controller: in iOS, the object that manages one screen of the user interface.
- Weak pointer (weakptr): a reference that does not keep an object alive but can tell whether the object still exists before it is used.
- WebState: Chrome's internal object representing one web page or tab; when the site closes, the corresponding
WebStateis destroyed.