Component: V8 Maglev JIT compiler (src/maglev/maglev-graph-builder.cc)
Affects: All platforms running Chrome/V8 with Maglev enabled (default since Chrome 117)
Status: Fixed by Victor Gomes (CL 7651434)
Chromium issue: 489577364
MaglevGraphBuilder::SaveCallSpeculationScope saves and restores current_speculation_feedback_ but fails to save current_speculation_mode_ before overwriting it. The destructor restores current_speculation_mode_ from the uninitialized member saved_mode_, which is undefined behavior (CWE-457).
SpeculationMode controls whether Maglev emits speculative type-specialized code or safe generic code:
enum class SpeculationMode {
kAllowSpeculation = 0, // Emit speculative type-specialized code
kDisallowBoundsCheckSpeculation = 1, // Allow speculation but not bounds check elision
kDisallowSpeculation = 3 // Emit safe generic code only
};The dangerous value kAllowSpeculation is 0 — the most common value in uninitialized stack memory. V8 explicitly removes -ftrivial-auto-var-init in release builds (gni/v8.gni:405-410).
File: src/maglev/maglev-graph-builder.cc, lines 362-393
class V8_NODISCARD MaglevGraphBuilder::SaveCallSpeculationScope {
public:
explicit SaveCallSpeculationScope(
MaglevGraphBuilder* builder,
compiler::FeedbackSource feedback_source = compiler::FeedbackSource())
: builder_(builder) {
saved_ = builder_->current_speculation_feedback(); // Saves feedback OK
// BUG: saved_mode_ is NEVER set to builder_->current_speculation_mode_
SpeculationMode mode = MaglevGraphBuilder::GetSpeculationMode(
builder_->broker(), feedback_source);
if (mode != SpeculationMode::kDisallowSpeculation) {
builder_->reducer_.set_current_speculation_feedback(feedback_source);
builder_->current_speculation_mode_ = mode; // Overwrites mode
} else {
builder->reducer_.set_current_speculation_feedback(
compiler::FeedbackSource());
builder_->current_speculation_mode_ =
SpeculationMode::kDisallowSpeculation; // Overwrites mode
}
}
~SaveCallSpeculationScope() {
builder_->reducer_.set_current_speculation_feedback(saved_); // Restores feedback OK
builder_->current_speculation_mode_ = saved_mode_; // Restores from UNINIT
}
private:
MaglevGraphBuilder* builder_;
compiler::FeedbackSource saved_;
SpeculationMode saved_mode_; // NEVER INITIALIZED
};The constructor overwrites builder_->current_speculation_mode_ but never saves the old value into saved_mode_ first. Contrast with saved_ which correctly saves and restores current_speculation_feedback().
CanSpeculateCall() is the primary guard at 30+ locations throughout the Maglev graph builder:
bool CanSpeculateCall() const {
return current_speculation_mode_ == SpeculationMode::kAllowSpeculation;
}Affected paths include speculative reductions for:
Array.prototype.push/pop/at— array type specialization, bounds check elisionDataViewget/set — typed array accessMath.absand other Math builtins — integer overflow checksString.prototype.charAt/charCodeAt— uses extended mode checkFunction.prototype.apply— call target speculation- All Array iteration builtins (forEach, map, filter, some, every, find, reduce, includes)
The scope is instantiated at 6 locations (lines 9156, 10350, 11482, 12186, 13552, 13948).
The V8 team assessed this as a bug, not a vulnerability — the deopt guards in generated code are the real safety net, so the worst case scenario is a deopt loop rather than type confusion. The speculation mode only controls whether optimization is attempted, not whether safety checks exist in the generated code. See Victor Gomes' comment.
# Build V8 with MSAN
gn gen out/msan --args='is_msan=true is_debug=false v8_enable_maglev=true target_cpu="x64"'
autoninja -C out/msan d8
# Run PoC — triggers all 6 SaveCallSpeculationScope paths
out/msan/d8 --maglev --no-turbofan poc.jsExpected MSAN output:
WARNING: MemorySanitizer: use-of-uninitialized-value
#0 MaglevGraphBuilder::SaveCallSpeculationScope::~SaveCallSpeculationScope()
src/maglev/maglev-graph-builder.cc:384
One line added to the constructor (CL 7651434):
saved_ = builder_->current_speculation_feedback();
+ saved_mode_ = builder_->current_speculation_mode_;
SpeculationMode mode = MaglevGraphBuilder::GetSpeculationMode(- 2026-03-03: Reported to Chrome VRP
- 2026-03-06: Triaged, assigned P1/S1 (Milestone 145)
- 2026-03-10: Downgraded to P2/S2 Bug. Fixed by Victor Gomes
- 2026-03-11: Added to
reward-topanelhotlist