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.
- Fix shipped in 23 days
Steps to reproduce the problem
repro:
-
launch chrome with --enable-features=LanguageDetectionAPI
-
apply patch.diff which simplify trigger
-
run poc.html.
Problem Description
- In the function
LanguageDetectionModel:: NotifyModelLoaded, there is an iterator operation. When AILanguageDetector performs detection, the callbackOnDetectCompletewill be added to themodel_loaded_callbacks_, and the OnDetectComplete function body will have a user-defined callbackresolve ->Resolve. The following is the reverse reference of the chain.
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");
}
}
}
LanguageDetectionModel:: NotifyModelLoadedis called inLanguageDetectionAgent:: updateLanguageDetectionModel, which can be traced back toLanguageDetectionAgent:: 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.
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()));
}
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
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
- Launch Chrome with the LanguageDetectionAPI feature enabled.
- Apply the provided patch that simplifies the trigger.
- 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.