Skip to content
Memory corruption Advisory Advanced CVE-2024-7533

Use after free in Sharing (CVE-2024-7533)

A use-after-free occurs in Chrome for iOS sharing code because a WebState pointer is captured and used after the object may have been destroyed. An attacker could potentially trigger a browser crash, and the report suggests memory corruption is possible, though no code execution is demonstrated.

lime Follow

Originally disclosed on Chrome VRP

Bounty$11,000 High View original
  • Fix shipped in 21 days

Steps to reproduce the problem

repro: 1. apply patch.diff which simplify trigger。 2. run poc.html then click the share button

Problem Description

  1. ThreadPool::PostTaskAndReplyWithResult in the start function passes currentWebState as a parameter, but this Objc class is controlled by ARC. So his two life cycles may not be consistent.
OBJC
- (void)start {
  web::WebState* currentWebState =
      self.browser->GetWebStateList()->GetActiveWebState();
  if (currentWebState &&
      ShareFileDownloadTabHelper::ShouldDownload(currentWebState)) {
    // Creating the directory can block the main thread, so perform it on a
    // background sequence, then on current sequence complete the workflow.
    __weak SharingCoordinator* weakSelf = self;
    base::ThreadPool::PostTaskAndReplyWithResult(
        FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
        base::BindOnce(&CreateDestinationDirectoryAndRemoveObsoleteFiles),
        base::BindOnce(^(BOOL directoryCreated) {
          [weakSelf startDownloadWithExistingDirectory:directoryCreated
                                              webState:currentWebState]; // <-- here pass the webState 
        }));
  } else {
    [self startActivityService];
  }
}
  1. In fact, it is. If WebState is destroyed before this Reply is run, UAF will result. This is where use comes in.
  • 1.1
    OBJC
    - (void)start {
    id<ShareDownloadOverlayCommands> handler = HandlerForProtocol(
        self.browser->GetCommandDispatcher(), ShareDownloadOverlayCommands);
    self.viewController = [[ShareDownloadOverlayViewController alloc]
        initWithBaseView:_webState->GetView() //<---- use here
                handler:handler];
    
    UIView* overlayedView = self.viewController.view;
    [UIView animateWithDuration:kOverlayViewAnimationDuration
                    animations:^{
                        [overlayedView setAlpha:1.0];
                    }];
    }
    
  • 1.2
OBJC
- (void)startDownloadFromWebState:(web::WebState*)webState {
  self.isDownloadCanceled = NO;
  NSString* tempDirPath = GetTemporaryDocumentDirectory();
  ShareFileDownloadTabHelper* helper =
      ShareFileDownloadTabHelper::FromWebState(webState); // use here
  self.filePath = [tempDirPath
      stringByAppendingPathComponent:base::SysUTF16ToNSString(
                                         helper->GetFileNameSuggestion())];
  self.fileNSURL = [NSURL fileURLWithPath:self.filePath];

      __weak SharingCoordinator* weakSelf = self;
      webState->DownloadCurrentPage(self.filePath, self,  // use here
                                    ^(id<CRWWebViewDownload> download) {
                                      weakSelf.download = download;
                                    });
}

fix suggestions: Since webstate is used in many places, I think it is better to use weakptr not add a WebStateDestory observer to the class. Because I only saw the initialization of _webState and did not see any zeroing operation.

OBJC
@interface ShareDownloadOverlayCoordinator () {
 // Web state that will receive the overlay view.
 raw_ptr<web::WebState> _webState;
}

bitset:

  1. Although _webState is not set to 0 here, I think the key to this problem is still in use, so I pointed the bitset to https://source.chromium.org/chromium/chromium/src/+/0ee2fb6db0754b2579419265bb64dbc4463410c3
  2. This will be introduced in October 2022 at the earliest.

NOTE

  1. The reason why patch is needed is to simplify my trigger operation, because there are many components that use this function (see 1.jpg)
  2. The root cause of the vulnerability has nothing to do with the path.
  3. There's no guarantee that it can't be triggered without a user gesture, since a large number of components use it.

Summary

AddressSanitizer: heap-use-after-free on [SharingCoordinator start]

Custom Questions

Type of crash:

browser

Crash state:

see uaf.log

Reporter credit:

lime(@limeSec_) From TIANGONG Team of Legendsec at QI-ANXIN Group,

Additional Data

Category: Security
Chrome Channel: Not sure
Regression: N/A

The original report as published on the Chromium issue tracker, by lime(@limeSec_) from TIANGONG Team of Legendsec at QI-ANXIN Group. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This report is a Chrome Vulnerability Reward Program (VRP) advisory for a use after free in Chrome's Sharing feature on iOS, tracked as CVE-2024-7533. The researcher is credited as lime(@limeSec_) from TIANGONG Team of Legendsec at QI-ANXIN Group. The platform records the severity as high, the weakness as use after free, the asset as Sharing, and the bounty as 11000.00 USD. The report was disclosed on 2024-08-06. The report itself does not state a CVSS score.

The affected code is the iOS sharing flow. When the user taps the share button, a SharingCoordinator decides whether the active web state should be downloaded as a file. If so, it creates a destination directory on a background sequence and then continues the download workflow on the current sequence. The crash summary in the report is:

Text
AddressSanitizer: heap-use-after-free on [SharingCoordinator start]

The report classifies the crash type as browser and points to uaf.log for the crash state. That log is not reproduced in the text given here.

Setup

The report gives very little environment detail. It does not name a Chrome version, an iOS version, a device, or a build configuration beyond the fact that AddressSanitizer was used to observe the crash. The Chrome channel is recorded as Not sure and regression as N/A.

The researcher does describe two preconditions for the reproduction:

  1. A patch, patch.diff, must be applied. The report says this patch simplifies the trigger. It does not include the contents of patch.diff.
  2. A file, poc.html, must be run, after which the share button is clicked.

The report does not include the contents of poc.html either. It also does not describe any account, role or authentication requirement.

Finding it

The researcher focused on the start method of SharingCoordinator. The method obtains the active web state, checks whether the page should be downloaded, and then posts a background task whose reply block captures the web state pointer.

OBJC
- (void)start {
  web::WebState* currentWebState =
      self.browser->GetWebStateList()->GetActiveWebState();
  if (currentWebState &&
      ShareFileDownloadTabHelper::ShouldDownload(currentWebState)) {
    // Creating the directory can block the main thread, so perform it on a
    // background sequence, then on current sequence complete the workflow.
    __weak SharingCoordinator* weakSelf = self;
    base::ThreadPool::PostTaskAndReplyWithResult(
        FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
        base::BindOnce(&CreateDestinationDirectoryAndRemoveObsoleteFiles),
        base::BindOnce(^(BOOL directoryCreated) {
          [weakSelf startDownloadWithExistingDirectory:directoryCreated
                                              webState:currentWebState]; // <-- here pass the webState
        }));
  } else {
    [self startActivityService];
  }
}

The researcher's observation is that ThreadPool::PostTaskAndReplyWithResult in start passes currentWebState as a parameter, but this Objective-C class is controlled by ARC. The two life cycles, that of the coordinator and that of the web state, may therefore not be consistent. The coordinator itself is captured weakly (__weak SharingCoordinator* weakSelf), but the web state is captured as a raw pointer in the reply block.

The researcher states plainly: if the WebState is destroyed before this reply runs, a use after free results. That is where the use comes in.

The report links the relevant source locations:

  • [0] ios/chrome/browser/ui/sharing/sharing_coordinator.mm, line 212, at revision [redacted].
  • [1.1] ios/chrome/browser/ui/sharing/share_download_overlay_coordinator.mm, line 47.
  • [1.2] ios/chrome/browser/ui/sharing/sharing_coordinator.mm, line 308, at the same revision.

Exploitation

Step 1: apply the simplifying patch

The first step in the reproduction is to apply patch.diff, which the researcher says simplifies the trigger. The report does not show the patch, so the exact change cannot be reproduced from this text alone. The report says the patch simplifies the trigger, because many components use this function.

Step 2: run the proof of concept and click share

The second step is to run poc.html and then click the share button. The report does not include the HTML, so the page content and the mechanism by which it causes the web state to be destroyed are not described. The code shown enters the download branch only when ShareFileDownloadTabHelper::ShouldDownload(currentWebState) returns true.

Step 3: the web state is used after it is freed

The report lists three places where the dangling web state is subsequently used. These are the use sites that turn the lifetime mismatch into a heap use after free.

Use site 1.1, in ShareDownloadOverlayCoordinator:

OBJC
- (void)start {
id<ShareDownloadOverlayCommands> handler = HandlerForProtocol(
    self.browser->GetCommandDispatcher(), ShareDownloadOverlayCommands);
self.viewController = [[ShareDownloadOverlayViewController alloc]
    initWithBaseView:_webState->GetView() //<---- use here
            handler:handler];

UIView* overlayedView = self.viewController.view;
[UIView animateWithDuration:kOverlayViewAnimationDuration
                animations:^{
                    [overlayedView setAlpha:1.0];
                }];
}

Here _webState->GetView() dereferences the stored web state pointer to obtain the view used to initialise the overlay view controller.

Use site 1.2, in SharingCoordinator:

OBJC
- (void)startDownloadFromWebState:(web::WebState*)webState {
  self.isDownloadCanceled = NO;
  NSString* tempDirPath = GetTemporaryDocumentDirectory();
  ShareFileDownloadTabHelper* helper =
      ShareFileDownloadTabHelper::FromWebState(webState); // use here
  self.filePath = [tempDirPath
      stringByAppendingPathComponent:base::SysUTF16ToNSString(
                                         helper->GetFileNameSuggestion())];
  self.fileNSURL = [NSURL fileURLWithPath:self.filePath];

      __weak SharingCoordinator* weakSelf = self;
      webState->DownloadCurrentPage(self.filePath, self,  // use here
                                    ^(id<CRWWebViewDownload> download) {
                                      weakSelf.download = download;
                                    });
}

In this method the web state is used twice: once through ShareFileDownloadTabHelper::FromWebState(webState) and once through webState->DownloadCurrentPage(...). The report marks both with // use here.

The report does not include the AddressSanitizer output itself, only the summary line quoted above and a reference to uaf.log, which is not part of the supplied text.

Root cause

The root cause described by the researcher is a lifetime mismatch. SharingCoordinator is an Objective-C class managed by ARC, while web::WebState is a C++ object with its own lifetime. The reply block passed to ThreadPool::PostTaskAndReplyWithResult captures currentWebState as a raw pointer. The block runs later, on the current sequence, after the background directory creation completes. If the web state has been destroyed in the meantime, the pointer is dangling and every subsequent dereference is a use after free.

The coordinator is protected by capturing weakSelf, but that protection does not extend to the web state. The report notes that the two life cycles may not be consistent precisely because one is ARC-controlled and the other is not.

On the overlay coordinator, the report shows the member declaration and points out that _webState is a raw pointer:

OBJC
@interface ShareDownloadOverlayCoordinator () {
 // Web state that will receive the overlay view.
 raw_ptr<web::WebState> _webState;
}

The researcher adds that _webState is not set to zero anywhere they could see, and that they only saw its initialisation. They also say that although _webState is not zeroed here, they believe the key to the problem is still the use, and they point the bitset at revision [redacted]. They state that this would have been introduced in October 2022 at the earliest.

Impact

The crash type is recorded as browser, and the AddressSanitizer summary names [SharingCoordinator start].

The researcher is careful about reachability. They note that the reason a patch is needed is to simplify the trigger, because many components use this function. They state that the root cause of the vulnerability has nothing to do with the path. They also state that there is no guarantee it cannot be triggered without a user gesture, since a large number of components use it.

Any stronger impact claim would go beyond what the text says.

Fix

The report offers a fix suggestion rather than describing a landed fix. The researcher recommends using a weak pointer instead of adding a WebStateDestroy observer to the class, because the web state is used in many places. Their reasoning is that they only saw the initialisation of _webState and did not see any zeroing operation.

Variants to test

The following directions follow from the lifetime mismatch described, but the report does not test or suggest them.

  1. Other reply blocks that capture a raw web::WebState* across an asynchronous boundary. A positive result is a use after free reported by AddressSanitizer when the web state is destroyed before the reply runs.
  2. Other Objective-C coordinators that hold a raw_ptr<web::WebState> member and dereference it in a later callback. A positive result is a crash or sanitizer report at the dereference site after the web state is gone.
  3. Paths that reach the same download branch through components other than the share button. The researcher notes that many components use this function and that a user gesture may not be required. A positive result is the same [SharingCoordinator start] use after free reached without the share button.
  4. Places where a weak capture protects the Objective-C object but not the C++ object it references. A positive result is that the coordinator survives, the web state does not, and the reply block still dereferences it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

This is a public bug bounty report from Google's Chrome Vulnerability Reward Program (VRP). It describes a security flaw in Google Chrome on iOS (the iPhone and iPad operating system). The flaw is called a use after free, and it was given the identifier CVE-2024-7533. The researcher who found it is credited as lime(@limeSec_) from TIANGONG Team of Legendsec at QI-ANXIN Group. The platform records the severity as high, the weakness as use after free, the asset as Sharing, and the bounty as 11000.00 USD. The report was disclosed on 2024-08-06. The report itself does not state a CVSS score.

The affected code is the iOS sharing flow. When you tap the share button in Chrome on an iPhone or iPad, a piece of code called SharingCoordinator decides whether the page you are looking at should be downloaded as a file. If it should, the code creates a destination folder in the background and then continues the download workflow. The crash summary in the report is:

Text
AddressSanitizer: heap-use-after-free on [SharingCoordinator start]

The report classifies the crash type as browser and points to uaf.log for the crash state. That log is not reproduced in the text given here.

Setup

The report gives very little environment detail. It does not name a Chrome version, an iOS version, a device, or a build configuration beyond the fact that AddressSanitizer was used to observe the crash. The Chrome channel is recorded as Not sure and regression as N/A.

The researcher does describe two preconditions for the reproduction:

  1. A patch, patch.diff, must be applied. The report says this patch simplifies the trigger. It does not include the contents of patch.diff.
  2. A file, poc.html, must be run, after which the share button is clicked.

The report does not include the contents of poc.html either. It also does not describe any account, role or authentication requirement.

Finding it

The researcher focused on the start method of SharingCoordinator. The method obtains the active web state, checks whether the page should be downloaded, and then posts a background task whose reply block captures the web state pointer.

OBJC
- (void)start {
  web::WebState* currentWebState =
      self.browser->GetWebStateList()->GetActiveWebState();
  if (currentWebState &&
      ShareFileDownloadTabHelper::ShouldDownload(currentWebState)) {
    // Creating the directory can block the main thread, so perform it on a
    // background sequence, then on current sequence complete the workflow.
    __weak SharingCoordinator* weakSelf = self;
    base::ThreadPool::PostTaskAndReplyWithResult(
        FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
        base::BindOnce(&CreateDestinationDirectoryAndRemoveObsoleteFiles),
        base::BindOnce(^(BOOL directoryCreated) {
          [weakSelf startDownloadWithExistingDirectory:directoryCreated
                                              webState:currentWebState]; // <-- here pass the webState
        }));
  } else {
    [self startActivityService];
  }
}

The researcher's observation is that ThreadPool::PostTaskAndReplyWithResult in start passes currentWebState as a parameter, but this Objective-C class is controlled by ARC. The two life cycles, that of the coordinator and that of the web state, may therefore not be consistent. The coordinator itself is captured weakly (__weak SharingCoordinator* weakSelf), but the web state is captured as a raw pointer in the reply block.

The researcher states plainly: if the WebState is destroyed before this reply runs, a use after free results. That is where the use comes in.

The report links the relevant source locations:

  • [0] ios/chrome/browser/ui/sharing/sharing_coordinator.mm, line 212, at revision [redacted].
  • [1.1] ios/chrome/browser/ui/sharing/share_download_overlay_coordinator.mm, line 47.
  • [1.2] ios/chrome/browser/ui/sharing/sharing_coordinator.mm, line 308, at the same revision.

Exploitation

Step 1: apply the simplifying patch

The first step in the reproduction is to apply patch.diff, which the researcher says simplifies the trigger. The report does not show the patch, so the exact change cannot be reproduced from this text alone. The report says the patch simplifies the trigger, because many components use this function.

Step 2: run the proof of concept and click share

The second step is to run poc.html and then click the share button. The report does not include the HTML, so the page content and the mechanism by which it causes the web state to be destroyed are not described. The code shown enters the download branch only when ShareFileDownloadTabHelper::ShouldDownload(currentWebState) returns true.

Step 3: the web state is used after it is freed

The report lists three places where the dangling web state is subsequently used. These are the use sites that turn the lifetime mismatch into a heap use after free.

Use site 1.1, in ShareDownloadOverlayCoordinator:

OBJC
- (void)start {
id<ShareDownloadOverlayCommands> handler = HandlerForProtocol(
    self.browser->GetCommandDispatcher(), ShareDownloadOverlayCommands);
self.viewController = [[ShareDownloadOverlayViewController alloc]
    initWithBaseView:_webState->GetView() //<---- use here
            handler:handler];

UIView* overlayedView = self.viewController.view;
[UIView animateWithDuration:kOverlayViewAnimationDuration
                animations:^{
                    [overlayedView setAlpha:1.0];
                }];
}

Here _webState->GetView() dereferences the stored web state pointer to obtain the view used to initialise the overlay view controller.

Use site 1.2, in SharingCoordinator:

OBJC
- (void)startDownloadFromWebState:(web::WebState*)webState {
  self.isDownloadCanceled = NO;
  NSString* tempDirPath = GetTemporaryDocumentDirectory();
  ShareFileDownloadTabHelper* helper =
      ShareFileDownloadTabHelper::FromWebState(webState); // use here
  self.filePath = [tempDirPath
      stringByAppendingPathComponent:base::SysUTF16ToNSString(
                                         helper->GetFileNameSuggestion())];
  self.fileNSURL = [NSURL fileURLWithPath:self.filePath];

      __weak SharingCoordinator* weakSelf = self;
      webState->DownloadCurrentPage(self.filePath, self,  // use here
                                    ^(id<CRWWebViewDownload> download) {
                                      weakSelf.download = download;
                                    });
}

In this method the web state is used twice: once through ShareFileDownloadTabHelper::FromWebState(webState) and once through webState->DownloadCurrentPage(...). The report marks both with // use here.

The report does not include the AddressSanitizer output itself, only the summary line quoted above and a reference to uaf.log, which is not part of the supplied text.

Root cause

The root cause described by the researcher is a lifetime mismatch. SharingCoordinator is an Objective-C class managed by ARC, while web::WebState is a C++ object with its own lifetime. The reply block passed to ThreadPool::PostTaskAndReplyWithResult captures currentWebState as a raw pointer. The block runs later, on the current sequence, after the background directory creation completes. If the web state has been destroyed in the meantime, the pointer is dangling and every subsequent dereference is a use after free.

The coordinator is protected by capturing weakSelf, but that protection does not extend to the web state. The report notes that the two life cycles may not be consistent precisely because one is ARC-controlled and the other is not.

On the overlay coordinator, the report shows the member declaration and points out that _webState is a raw pointer:

OBJC
@interface ShareDownloadOverlayCoordinator () {
 // Web state that will receive the overlay view.
 raw_ptr<web::WebState> _webState;
}

The researcher adds that _webState is not set to zero anywhere they could see, and that they only saw its initialisation. They also say that although _webState is not zeroed here, they believe the key to the problem is still the use, and they point the bitset at revision [redacted]. They state that this would have been introduced in October 2022 at the earliest.

Impact

The crash type is recorded as browser, and the AddressSanitizer summary names [SharingCoordinator start].

The researcher is careful about reachability. They note that the reason a patch is needed is to simplify the trigger, because many components use this function. They state that the root cause of the vulnerability has nothing to do with the path. They also state that there is no guarantee it cannot be triggered without a user gesture, since a large number of components use it.

Any stronger impact claim would go beyond what the text says.

Fix

The report offers a fix suggestion rather than describing a landed fix. The researcher recommends using a weak pointer instead of adding a WebStateDestroy observer to the class, because the web state is used in many places. Their reasoning is that they only saw the initialisation of _webState and did not see any zeroing operation.

Variants to test

The following directions follow from the lifetime mismatch described, but the report does not test or suggest them.

  1. Other reply blocks that capture a raw web::WebState* across an asynchronous boundary. A positive result is a use after free reported by AddressSanitizer when the web state is destroyed before the reply runs.
  2. Other Objective-C coordinators that hold a raw_ptr<web::WebState> member and dereference it in a later callback. A positive result is a crash or sanitizer report at the dereference site after the web state is gone.
  3. Paths that reach the same download branch through components other than the share button. The researcher notes that many components use this function and that a user gesture may not be required. A positive result is the same [SharingCoordinator start] use after free reached without the share button.
  4. Places where a weak capture protects the Objective-C object but not the C++ object it references. A positive result is that the coordinator survives, the web state does not, and the reply block still dereferences it.

Glossary

  • AddressSanitizer: a tool built into some software builds that watches memory and reports when a program reads or writes memory it should no longer be using.
  • ARC (Automatic Reference Counting): a memory management system used by Objective-C that automatically keeps track of when objects are still needed and frees them when they are not.
  • bitset: in this report, a pointer to a specific revision of the source code that the researcher believes is relevant.
  • browser process: the main part of the browser that manages tabs, windows and the user interface.
  • C++: a programming language used for many parts of Chrome.
  • Chrome VRP (Vulnerability Reward Program): Google's programme that pays people for finding and reporting security bugs in Chrome.
  • CVE: a unique identifier for a publicly known security vulnerability.
  • CVSS: a scoring system that rates the severity of a vulnerability.
  • dangling pointer: a pointer that still holds the address of memory that has already been freed.
  • dereference: to access the value stored at the address a pointer points to.
  • heap: the area of memory where a program stores objects that are created and destroyed while it runs.
  • heap-use-after-free: a bug where a program uses memory from the heap after it has been freed.
  • iOS: Apple's operating system for iPhone and iPad.
  • Objective-C: a programming language used for Apple platforms, including iOS.
  • patch.diff: a file containing changes to source code, used here to simplify the trigger.
  • poc.html: a proof-of-concept web page used to trigger the bug.
  • raw pointer: a pointer that does not automatically track whether the object it points to is still alive.
  • raw_ptr: a type in Chrome that wraps a raw pointer, but does not by itself prevent use after free.
  • reply block: a piece of code that runs after a background task finishes.
  • sequence: a way of organising tasks so they run one after another in order.
  • share button: the button in Chrome that opens the sharing options.
  • SharingCoordinator: the piece of code that manages the sharing flow in Chrome on iOS.
  • ThreadPool: a set of background threads used to run tasks without blocking the main thread.
  • use after free: a bug where a program uses memory after it has been freed.
  • user gesture: an action by the user, such as a tap or click.
  • weak pointer: a pointer that does not keep the object alive and can detect when the object is gone.
  • weakSelf: a weak reference to the current object, used to avoid keeping it alive.
  • WebState: the object in Chrome that represents a web page and its state.
  • WebStateDestroy observer: a mechanism to be notified when a WebState is destroyed.

More by lime

View all

4 more disclosed reports, best first.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.