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

Use after free in Translate (CVE-2024-12382)

A use-after-free exists in Chrome's language detection model loading code: while iterating over pending model-loaded callbacks, a callback can re-enter the code and invalidate the iterator. An attacker could trigger a heap use-after-free in the renderer, which the report demonstrates with an AddressSanitizer crash.

lime Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 23 days

Steps to reproduce the problem

repro:

  1. launch chrome with --enable-features=LanguageDetectionAPI

  2. apply patch.diff which simplify trigger

  3. run poc.html.

Problem Description

  1. In the function LanguageDetectionModel:: NotifyModelLoaded, there is an iterator operation. When AILanguageDetector performs detection, the callback OnDetectComplete will be added to the model_loaded_callbacks_, and the OnDetectComplete function body will have a user-defined callback resolve ->Resolve. The following is the reverse reference of the chain.
C++
void LanguageDetectionModel::NotifyModelLoaded() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  for (auto&& callback_ : model_loaded_callbacks_) {
    std::move(callback_).Run(*this);
  }
  loaded_ = true;
  model_loaded_callbacks_.clear();
}
------------------------
void LanguageDetectionModel::AddOnModelLoadedCallback(
    ModelLoadedCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  if (loaded_ || model_loaded_callbacks_.size() >= kMaxPendingCallbacksCount) {
    std::move(callback).Run(*this);
  } else {
    model_loaded_callbacks_.emplace_back(std::move(callback));
  }
}
------------------------
void DetectLanguage(const WTF::String& text,
                    DetectLanguageCallback on_complete) {
  auto& model = language_detection::GetLanguageDetectionModel();
  model.AddOnModelLoadedCallback(
      WTF::BindOnce(DetectLanguageWithModel, text, std::move(on_complete)));
}
------------------------
ScriptPromise<IDLSequence<LanguageDetectionResult>> AILanguageDetector::detect(
    ScriptState* script_state,
    const WTF::String& input,
    AILanguageDetectorDetectOptions* options,
    ExceptionState& exception_state) {
[...]

  DetectLanguage(input, WTF::BindOnce(AILanguageDetector::OnDetectComplete,
                                      WrapPersistent(resolver)));
  return resolver->Promise();
}
-----------------------
void AILanguageDetector::OnDetectComplete(
    ScriptPromiseResolver<IDLSequence<LanguageDetectionResult>>* resolver,
    base::expected<WTF::Vector<LanguagePrediction>, DetectLanguageError>
        result) {
  if (result.has_value()) {
    // Order the result from most to least confident.
    std::sort(result.value().rbegin(), result.value().rend());
    resolver->Resolve(ConvertResult(result.value()));
  } else {
    switch (result.error()) {
      case DetectLanguageError::kUnavailable:
        resolver->Reject("Model not available");
    }
  }
}
  1. LanguageDetectionModel:: NotifyModelLoaded is called in LanguageDetectionAgent:: updateLanguageDetectionModel, which can be traced back to LanguageDetectionAgent:: WasShown. However, in thisWasShown, Mojo calls are made to communicate with the browser through` VNet anguageDetectionHandler () ->VNet anguageDetectionModel ``

The final callback returns the renderer for calling, which represents an asynchronous process in the middle of the renderer execution. This means that we can construct a POC. Before running the LanguageDetectionAgent:: Updating LanguageDetectionModel, we will fill the corresponding quantity and contain user-defined iterator invalidation code in the model_loaded_callback. Ultimately, it will lead to the failure of iterators. Causing UAF.

C++
void LanguageDetectionAgent::WasShown() {
  // Check if the the render frame was initially hidden and
  // the model request was delayed until the frame was in
  // the foreground.
[...]
  GetLanguageDetectionHandler()->GetLanguageDetectionModel(
      base::BindOnce(&LanguageDetectionAgent::UpdateLanguageDetectionModel,
                     weak_pointer_factory_.GetWeakPtr()));
}
  1. https://source.chromium.org/chromium/chromium/src/+/main:components/language_detection/core/language_detection_model.cc;l=230?q=LanguageDetectionModel::NotifyModelLoaded&ss=chromium%2Fchromium%2Fsrc

  2. https://source.chromium.org/chromium/chromium/src/+/main:components/language_detection/content/renderer/language_detection_agent.cc;l=107?q=LanguageDetectionAgent::WasShown&ss=chromium%2Fchromium%2Fsrc

bitset: https://source.chromium.org/chromium/chromium/src/+/6742751ccf591d9ba1670c3082efbf345084b7d0

why need patch? simplify trigger progress. No impact on the vulnerability principle.

fix sugesstions: swap the model_loaded_callbacks_. see fix.diff

Summary

AddressSanitizer:heap-use-after-free on LanguageDetectionModel::NotifyModelLoaded

Custom Questions

Type of crash:

tab

Crash state:

see asan.log

Reporter credit:

lime(@limeSec)

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.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the callback loop in NotifyModelLoaded runs user-influenced code that can re-enter AddOnModelLoadedCallback and mutate model_loaded_callbacks_ during iteration, invalidating the iterator.

What the attacker needed

Chrome with LanguageDetectionAPI enabled; Victim opens a crafted page

The fix

The suggested fix is to swap the callback list before iterating so that re-entrant additions do not invalidate the iterator.

How it was found

  1. Launch Chrome with the LanguageDetectionAPI feature enabled.
  2. Apply the provided patch that simplifies the trigger.
  3. Open the proof-of-concept HTML page to trigger the crash.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a web page asks Chrome to detect the language of some text, Chrome queues a callback until its language model has loaded. The code that runs those queued callbacks can, in turn, add or change the same list while it is still being looped over. That leaves the loop pointing at memory that has been freed, which is a use-after-free and can crash or potentially be abused.

What is Memory corruption?

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

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.