Skip to content

Spectre-BTB

Spectre Variant 2 / Branch Target Injection: Branch Target Buffer'ı poison'la ki bir victim'in indirect branch'i attacker'ın seçtiği bir gadget'a speculatively atlasın.

Mechanism

Note

Bir indirect branch'in (register ya da memory operand üzerinden bir jmp/call) hedefini, operand mevcut olmadan önce öngörmek için CPU, son görülen branch→target ilişkilendirmelerini Branch Target Buffer (BTB)'da cache'ler. Canella et al.'ye göre, direct branch'ler için "the CPU indexes the BTB using a subset of the virtual address bits of the branch instruction"; indirect branch'ler için CPU'lar "use different mechanisms ... which may take into account global branching history accumulated in the BHB when indexing the BTB."

Spectre-BTB'nin suistimal ettiği invariant: BTB güvenlik domain'i başına partition edilmemiştir ve yalnızca address bit'lerinin bir alt kümesiyle indexlenir; bu yüzden attacker, victim'in indirect branch'inin daha sonra danışacağı bir branch→target eşlemesi kurabilir. Spectre-PHT yalnızca bir branch yönünü çevirirken (transient execution'ı yakın bir mispredict edilen path'e kısıtlayarak), Spectre-BTB transient control flow'u keyfi bir hedefe yönlendirir. Canella et al.: "Spectre-BTB allows redirecting transient control flow to an arbitrary destination." Bu, bir uygulama güvenlik açığı yerine BTB poisoning'i suistimal ederek transient domain'de victim "gadget"larının ROP tarzı zincirlenmesini mümkün kılar — return-oriented programming'in spekülatif analoğu.

Walkthrough

  1. Victim indirect branch'ini ve bir disclosure gadget'ı bul. Victim'de bir indirect call/jmp (örn. bir function pointer ya da vtable üzerinden) ve victim'in address space'inde secret-dependent bir bellek erişimi yapan bir gadget bul (Spectre-v1'deki aynı array[secret * stride] şekli).

  2. BTB'yi poison'la. Branch'leri öyle çalıştır ki predictor, victim'in indirect-branch site'ını gadget'ın address'iyle ilişkilendirsin. Kocher et al.: attacker "mistrains the branch predictor with malicious destinations", böylece speculation "continues at a location chosen by the adversary." Poison'layan branch'in nasıl yerleştirildiği (same vs different address space, same vs congruent virtual address), mistraining stratejisidir — aşağıdaki dört alt-tekniğe bak.

attacker:  repeatedly execute branch(es) that install
           BTB[ index(victim_indirect_br) ] -> &disclosure_gadget
victim:    call *fnptr;     // operand not yet resolved
           # CPU speculatively jumps to disclosure_gadget
  1. Transient sızıntı + kurtarma. Victim'in indirect branch'i gadget'a mispredict eder; gadget transiently bir secret okur ve bir probe array'e dokunur. Misprediction architecturally squash edilir ama cache footprint kalır ve FLUSH+RELOAD ile geri okunur.
flush(probe);                  // evict probe array
victim_indirect_call();        // mispredicts into poisoned gadget target
reload_and_time(probe);        // cached line reveals leaked byte
Tanımlama (Canella et al. / Kocher et al.)
Variant:        Spectre Variant 2 (Branch Target Injection)
CVE:            CVE-2017-5715
Predictor:      Branch Target Buffer (BTB), indirect-branch prediction
Effect:         transient control-flow hijack to an arbitrary in-victim target
Demonstrated:   Intel, AMD, ARM (Kocher et al., cross-address-space in-place)

Detection

Tüm transient-execution saldırılarında olduğu gibi, misprediction architecturally geri alınır; yalnızca gürültülü microarchitectural vekiller (branch-misprediction ve cache-miss counter'ları) gözlemlenebilir. Savunma preventive'dir.

Mitigation

Canella et al.'ye göre, Intel ve AMD ISA'yı üç indirect-branch kontrolüyle genişletti:

  • IBRS (Indirect Branch Restricted Speculation) — "prevents indirect branches executed in privileged code from being influenced by those in less privileged code."
  • STIBP (Single Thread Indirect Branch Prediction) — "restricts sharing of branch prediction mechanisms among code executing across hyperthreads."
  • IBPB (Indirect Branch Predictor Barrier) — "prevents code that executes before it from affecting the prediction of code following it by flushing the BTB."

Google'ın retpoline'u "replaces indirect branches with return instructions, to prevent branch poisoning"; RSB üzerinden benign bir trap'e speculate eder. Skylake ve yenisinde Intel, bir hardware Spectre-BTB savunması olarak enhanced IBRS (eIBRS) önerir (retpoline, CET-capable CPU'larda CET ile çakışabilir).

Warning

eIBRS/CSV2, enjekte edilen target'ları privilege domain'leri boyunca izole eder ama global branch history'sini izole etmez; history tabanlı poisoning (Branch History Injection) hâlâ in-domain indirect branch'leri yönlendirebilir. Bkz. Branch History Injection ve Retbleed.

References