TExcelTAD
Home › Security Research: Fuzzing, Vulnerability Discovery, Kernel, Browser & AI Security › JIT Compilers, Hardening and Browser Bug Bounties

JIT Compilers, Hardening and Browser Bug Bounties

JavaScript engines don't interpret hot code for long. They watch what types flow through a function, then compile it to machine code that assumes those types, and remove every check the optimiser can prove unnecessary. When the proof is wrong, the generated machine code does something the language never allows, such as reading past the end of an array. A large share of serious browser vulnerabilities in recent years were exactly this: a JIT compiler bug that turned a type or range mistake in the optimiser into memory corruption inside the renderer. This lesson builds a toy optimiser with such a bug, finds it the way engine teams do (differential fuzzing), and ends with how browser bug-bounty programmes work.

How a JIT goes wrong

A typical optimising pipeline:

  1. Profile in the interpreter: f is always called with a small integer and an array of 8 elements.
  2. Speculate: compile assuming that, with guards that deoptimise (fall back to the interpreter) if an assumption breaks.
  3. Analyse ranges and types: "x % 8 is always in [0, 7], the array has 8 elements, so the bounds check is redundant."
  4. Eliminate the check and emit a raw load.

Step 3 must match the language's semantics exactly. In JavaScript, % keeps the sign of the dividend: -9 % 8 is -1, not 7. An optimiser that treats % like a mathematician's modulo concludes the range is [0, 7], removes the check, and the compiled code reads TABLE[-1], memory before the array. Engine bugs of this shape involve integer ranges, array lengths, side effects the optimiser forgot (a callback that changes an array's length while the optimiser assumed it fixed), or types assumed stable across a call.

A toy optimiser and its differential test

The example defines f(x) = TABLE[x % 8] with JavaScript's %. The interpreter checks bounds on every access (out of range gives undefined, here None). The "JIT" asks a range analysis whether x % 8 always fits, removes the check if so, and models what raw machine code would do by raising Crash on an out-of-bounds read. The test is the one engine teams use: run both on many inputs and report any disagreement. It runs in your browser:

python · try it yourself
import math, random

class Crash(Exception):
    pass

TABLE = [10, 20, 30, 40, 50, 60, 70, 80]        # an 8-element array in the toy engine's heap

def js_mod(a, b):
    """JavaScript's %: the result has the sign of the dividend (-9 % 8 is -1)."""
    return int(math.fmod(a, b))

def interpret(x):
    """Reference semantics of  f(x) = TABLE[x % 8]  with a bounds check on every access."""
    i = js_mod(x, 8)
    return TABLE[i] if 0 <= i < len(TABLE) else None   # out of range -> undefined

def range_of_mod(divisor, correct):
    """The optimiser's range analysis for (int32 x) % divisor."""
    if correct:
        return (-(divisor - 1), divisor - 1)              # sign follows x: [-7, 7]
    return (0, divisor - 1)                                # seeded bug: assumes x % 8 >= 0

def compile_f(correct):
    lo, hi = range_of_mod(8, correct)
    check_needed = not (0 <= lo and hi < len(TABLE))
    def jitted(x):
        i = js_mod(x, 8)
        if check_needed:
            return TABLE[i] if 0 <= i < len(TABLE) else None
        if not 0 <= i < len(TABLE):                       # what raw machine code would do: read
            raise Crash(f"out-of-bounds read TABLE[{i}]")  # whatever lies before the array
        return TABLE[i]
    return jitted, check_needed

rng = random.Random(1)
inputs = [rng.randint(-2**31, 2**31 - 1) for _ in range(1000)]
for correct in (False, True):
    jitted, check = compile_f(correct)
    mismatches = []
    for x in inputs:
        try:
            got = jitted(x)
        except Crash as e:
            got = str(e)
        if got != interpret(x):
            mismatches.append((x, got))
    label = "fixed range analysis" if correct else "buggy range analysis"
    print(f"{label}: bounds check kept = {check}, mismatches on 1000 random int32 inputs: {len(mismatches)}")
    for x, got in mismatches[:2]:
        print(f"   f({x}): interpreter {interpret(x)}, JIT {got}")
buggy range analysis: bounds check kept = False, mismatches on 1000 random int32 inputs: 426
   f(-1051970500): interpreter None, JIT out-of-bounds read TABLE[-4]
   f(-216934237): interpreter None, JIT out-of-bounds read TABLE[-5]
fixed range analysis: bounds check kept = True, mismatches on 1000 random int32 inputs: 0

With the buggy range analysis the check is gone, and 426 of 1,000 random 32-bit inputs disagree: every negative x that is not a multiple of 8 reads before the array. The interpreter says undefined; the compiled code reads TABLE[-4]. In a real engine that read returns whatever lies there (a pointer, another object's length), which is the first step of the exploitation techniques this course does not cover. The fixed analysis knows that the result can be negative ([-7, 7]), keeps the check, and agrees with the interpreter on every input.

How JIT bugs are detected

  • Differential fuzzing: generate JavaScript programs, run each with the JIT forced on and forced off (or across engines), compare results. A difference is a bug even if nothing crashes.
  • Structure-aware fuzzers that mutate an intermediate representation of JavaScript, so most generated programs are valid and type-correct (Fuzzing Strategies); engine developers pair them with sanitizer builds and with flags that make the JIT compile early and often.
  • Assertions in debug builds that check the optimiser's claims at run time ("this value is in range"), turning a wrong proof into an immediate report.
  • Patch review: engine fixes often come with a regression test that is a minimal version of the bug, which is why reading those tests is part of variant analysis.

How JIT engines are hardened

Measure Effect
keep cheap checks instead of eliminating them a wrong range proof no longer becomes an out-of-bounds access; some engines stopped removing bounds checks on the strength of range analysis alone
W^X for JIT code, code-pointer checks (CFI) compiled code is never writable while executable
heap sandbox (the "V8 sandbox") engine objects live in a reserved region and refer to each other by offsets, so a corrupted length can reach only that region
Spectre mitigations (index masking, site isolation) speculative reads past a check do not reach other sites' data
JIT-less modes some high-security browser modes and lockdown features turn the optimising JIT off for most sites, trading speed for a much smaller attack surface
memory-safe rewrites new components in Rust remove whole bug classes

Browser bug-bounty programmes

All major browser vendors pay for vulnerability reports: Google's Chrome Vulnerability Reward Program (part of Google's VRP), Mozilla's bug bounty, Apple's Security Bounty, Microsoft's bounty for Edge-specific issues (Edge shares Chromium's engine), plus contests such as Pwn2Own. Their published rules are the authorisation for this kind of research, and they have common points:

  • Test on your own builds and machines. Never against other users, never on someone else's device.
  • Report through the official channel (the vendor's issue tracker or form), privately, with a reproducer, usually a minimal HTML/JS file, and a sanitizer report from a debug build if you have one.
  • Rewards scale with impact and quality: a renderer bug, a sandbox escape, a full chain, a bypass of a mitigation; a high-quality report with root-cause analysis and a suggested fix earns more. Exact amounts and categories change; read the current rules.
  • Embargo: details stay private until fixed builds reach users; the vendor publishes the advisory and credits you.
  • No selling to third parties and no public disclosure before the agreed date.

The process is the coordinated disclosure of the Disclosure section, with money attached.

Pitfalls

  • Assuming crash-only oracles find JIT bugs. Many JIT bugs only give wrong results until someone builds on them; differential testing is essential.
  • Trusting "it's a renderer bug, the sandbox will hold". Defence in depth assumes each layer can fail.
  • Testing against a live site to "prove" impact. Bounty rules forbid it, and it adds nothing to a report with a reproducer.

Practice

1. Which x values give a mismatch with the buggy analysis, exactly?

Negative x whose remainder is not zero: js_mod(x, 8) is then between -7 and -1. Non-negative x and negative multiples of 8 give an index in [0, 7] and agree.

2. Propose a fix for the compiled code that is cheaper than a full bounds check.

If the optimiser knows x is an int32, compute x & 7 only when it has proven x >= 0, or mask the index (i & 7) after a sign check; or keep the check (one compare and branch, well predicted). Engines often choose the check: correctness over a cycle.

3. You found a crash in your own Chromium build with a minimised HTML file. What goes into the report?

Version and build flags, the minimal HTML/JS reproducer, the sanitizer report or crash stack, the root cause if you found it (which optimisation, which wrong assumption), the affected process (renderer, browser, GPU), and your assessment of severity, sent privately through the vendor's security tracker.

Test yourself

Why is x % 8 not always in [0, 7] in JavaScript?

  1. Floating-point rounding
  2. The remainder takes the sign of the dividend, so negative x gives results down to -7
  3. % is not defined for integers
  4. Because of NaN

What turns a wrong range analysis into a memory bug?

  1. The interpreter
  2. Bounds-check elimination based on the wrong range
  3. The garbage collector
  4. Profiling

How did the example detect the bug without any crash in the interpreter?

  1. By reading the code
  2. Differential testing: the JIT and interpreter disagreed on the same inputs
  3. By timing
  4. By coverage

What do browser bug-bounty rules typically require?

  1. Testing on live users
  2. Testing on your own builds, private reports through the official channel, and no disclosure before the fix
  3. Public disclosure first
  4. Selling to the highest bidder