[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,95 +1,169 @@
|
||||
---
|
||||
id: wiki-2026-0508-cache-side-channel-attack
|
||||
title: Cache Side Channel Attack
|
||||
title: Cache Side-Channel Attack
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-55C813]
|
||||
aliases: [Cache Timing Attack, Flush+Reload, Prime+Probe, Spectre]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [security, hardware, microarchitecture, side-channel, crypto]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - Cache [[Side-channel Attack|Side-channel Attack]]"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: C/Assembly
|
||||
framework: Linux/perf
|
||||
---
|
||||
|
||||
# [[Cache Side-Channel Attack|Cache Side-Channel Attack]]
|
||||
# Cache Side-Channel Attack
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> 캐시 사이드 채널 공격(Cache Side-Channel Attack)은 공격자가 고정밀 타이머를 사용하여 CPU 또는 GPU 캐시의 접근 속도(예: L1 캐시와 메인 메모리 간의 지연 시간 차이)를 측정함으로써, 보호된 비밀 메모리의 내용을 추론하고 유출하는 보안 취약점입니다 [1-3]. 현대 프로세서의 추측 실행([[Speculative Execution|Speculative Execution]])과 분기 예측을 악용하는 스펙터(Spectre)와 멜트다운(Meltdown)이 대표적이며, 이를 방어하기 위해 웹 브라우저들은 타이머 정밀도를 의도적으로 낮추고 분기 없는 보안 검사([[Branchless Security Checks|Branchless Security Checks]])를 도입해야 했습니다 [4-7].
|
||||
## 매 한 줄
|
||||
> **"매 캐시 access timing 의 secret 를 leak"**. CPU cache 의 shared resource — attacker 가 victim 의 access pattern 을 timing 으로 observe 해서 key/data 를 복원. 2018 Spectre/Meltdown 이후 매 modern CPU 의 systemic threat — 2026 에도 hardware mitigation (Intel CET, ARM MTE) + software (constant-time crypto) 의 combo 가 필수.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **작동 원리 및 추측 실행 악용:** 공격자는 고해상도 타이밍 측정을 통해 캐시 적중률(Cache hit rate)과 메모리 접근 패턴을 관찰합니다 [1, 8]. 스펙터(Spectre) 공격의 경우, 현대 CPU가 성능 최적화를 위해 제공하는 '추측 실행'을 악용합니다. CPU가 조건부 분기(Branch)를 예측하여 미리 실행할 때 메인 메모리에서 가장 빠르고 작은 L1 캐시로 데이터를 로드하는데, 예측이 틀려 실행이 롤백되더라도 L1 캐시로 가져온 데이터는 그대로 남게 됩니다 [3, 9, 10]. 공격자는 타이밍 속도를 측정하여 CPU가 추측 실행 단계에서 어떤 메모리(캐시 라인)를 로드했는지 알아낼 수 있습니다 [3, 11].
|
||||
* **GPU 환경에서의 캐시 공격:** CPU뿐만 아니라 GPU 환경에서도 캐시 사이드 채널 공격이 보고되었습니다. [[WebGL|WebGL]] 환경에서 GPU에 Rowhammer 공격을 수행한 사례가 있으며, 이때 타임스탬프 쿼리([[Timestamp Queries|Timestamp Queries]])가 제공하는 고정밀 타이밍을 통해 GPU 캐시 미스율을 확인하고 물리적 메모리 구조를 파악하는 방식을 사용했습니다 [8].
|
||||
* **웹 브라우저의 방어 메커니즘 (Mitigations):**
|
||||
* **타이머 정밀도 감소(Timer [[Quantization|Quantization]]) 및 지터(Jitter) 도입:** 브라우저 엔진들은 `performance.now()`와 같은 타이머의 해상도를 1ms 또는 100 마이크로초 등으로 대폭 낮추었습니다 [4, 7, 12]. 또한 공격자가 통계적 평균을 내어 고해상도 클럭을 재구성하는 것을 막기 위해, 반환되는 시간에 무작위 변동 값인 '지터(Jitter)'를 추가했습니다 [4]. [[WebGPU|WebGPU]] 환경의 타임스탬프 쿼리 역시 보안을 위해 해상도가 제한(Quantized 및 Coarsened)됩니다 [1, 13, 14].
|
||||
* **위험 기능 비활성화:** 고해상도 타이머를 생성하는 데 악용될 수 있는 `SharedArrayBuffer` 기능과 정밀한 타이밍을 제공하던 `EXT_disjoint_timer_query` 확장 기능 등을 비활성화하거나 접근을 엄격히 제한했습니다 [1, 6, 7].
|
||||
* **분기 없는 보안 검사(Branchless Security Checks):** 공격자가 추측 실행의 분기(Branch)를 제어할 수 있게 됨에 따라, 분기 명령어에 의존하는 기존의 보안 체계는 무력화되었습니다 [5, 11, 15]. 이에 대응하기 위해 [[WebKit|WebKit]]과 Blink 같은 엔진은 인덱스 마스킹(Index Masking)과 포인터 포이즈닝([[Pointer Poisoning|Pointer Poisoning]])과 같이 조건부 분기를 사용하지 않는 형태의 보안 검사 방식을 새롭게 도입했습니다 [4, 7, 16, 17].
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
|
||||
### 매 attack primitives
|
||||
- **Flush+Reload**: 매 shared memory (libcrypto) — `clflush` 후 victim run, 다시 access timing 으로 hit/miss 판별. L3 inclusive cache 의 cross-core leak.
|
||||
- **Prime+Probe**: 매 shared memory 없을 때 — attacker 가 cache set 을 fill, victim run, attacker 의 reload 시 evicted line 의 timing spike.
|
||||
- **Evict+Time**: 매 victim 의 own execution time 측정 — coarser 매 cache state 무관.
|
||||
- **Flush+Flush**: 매 `clflush` 의 latency 자체로 hit/miss — quieter 매 PMU detection 회피.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[Spectre|Spectre]], Meltdown, Speculative Execution, [[Timestamp Quantization|Timestamp Quantization]]
|
||||
- **Projects/Contexts:** [[WebKit|WebKit]], WebGPU, [[WebGL|WebGL]]
|
||||
- **Contradictions/Notes:** 소스에 따르면, 그래픽 파이프라인 최적화 및 렌더링 병목 현상을 해결하려는 개발자들은 나노초 단위의 고정밀 타이머를 절대적으로 필요로 하지만, 보안 측면에서는 이러한 고해상도 타이머가 캐시 사이드 채널 공격의 주요 수단이 되기 때문에 브라우저 벤더들이 타이머의 해상도를 의도적으로 제한(Coarsening)해야만 하는 기능적 상충 관계(Trade-off)가 발생하고 있습니다 [1, 13, 14, 18].
|
||||
### 매 transient execution (Spectre/Meltdown)
|
||||
- **Spectre v1**: bounds-check bypass — speculative load of out-of-bounds → cache trace.
|
||||
- **Spectre v2**: branch target injection — indirect branch poisoning.
|
||||
- **Meltdown**: kernel memory leak via deferred permission check.
|
||||
- **MDS/L1TF/RIDL**: microarchitectural buffer leaks.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-19*
|
||||
### 매 응용
|
||||
1. AES key recovery (T-table lookup leak).
|
||||
2. RSA key bit recovery (modular exponentiation pattern).
|
||||
3. Cross-VM leak in cloud (Xen/KVM).
|
||||
4. Cross-process key extraction (libssl shared library).
|
||||
|
||||
---
|
||||
## 💻 패턴
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### Flush+Reload (skeleton, x86_64)
|
||||
```c
|
||||
#include <x86intrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
static inline uint64_t rdtscp_serialized(void) {
|
||||
uint32_t aux;
|
||||
_mm_lfence();
|
||||
uint64_t t = __rdtscp(&aux);
|
||||
_mm_lfence();
|
||||
return t;
|
||||
}
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
int probe(const void *addr) {
|
||||
uint64_t t0 = rdtscp_serialized();
|
||||
(void)*(volatile const uint8_t *)addr;
|
||||
uint64_t t1 = rdtscp_serialized();
|
||||
_mm_clflush(addr);
|
||||
return (int)(t1 - t0); // < ~120 cycles → cached (hit)
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Prime+Probe set-associative eviction
|
||||
```c
|
||||
// Build eviction set for target cache set (LLC)
|
||||
void prime(uint8_t **set, size_t ways) {
|
||||
for (size_t i = 0; i < ways; i++) {
|
||||
(void)*(volatile uint8_t *)set[i];
|
||||
}
|
||||
}
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
int probe_set(uint8_t **set, size_t ways) {
|
||||
uint64_t total = 0;
|
||||
for (size_t i = 0; i < ways; i++) {
|
||||
uint64_t t0 = rdtscp_serialized();
|
||||
(void)*(volatile uint8_t *)set[i];
|
||||
uint64_t t1 = rdtscp_serialized();
|
||||
total += (t1 - t0);
|
||||
}
|
||||
return total > THRESHOLD; // victim accessed this set
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Constant-time AES (defensive)
|
||||
```c
|
||||
// 매 T-table lookup 의 X — bitsliced AES 의 use
|
||||
// libgcrypt / OpenSSL 3.x 의 AES-NI fallback path 의 default
|
||||
#include <wmmintrin.h>
|
||||
__m128i aes_round(__m128i state, __m128i rk) {
|
||||
return _mm_aesenc_si128(state, rk); // hardware, no table
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Spectre v1 mitigation (LFENCE fence)
|
||||
```c
|
||||
if (idx < array_len) {
|
||||
_mm_lfence(); // serialize speculation
|
||||
uint8_t v = array[idx];
|
||||
secret_dependent_load(v);
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Speculative load hardening (Clang)
|
||||
```bash
|
||||
clang -mspeculative-load-hardening -O2 victim.c -o victim
|
||||
# 매 conditional masking 의 inject — speculative path 의 secret 을 0 으로 mask
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### Constant-time comparison
|
||||
```c
|
||||
int ct_memcmp(const void *a, const void *b, size_t n) {
|
||||
const uint8_t *x = a, *y = b;
|
||||
uint8_t diff = 0;
|
||||
for (size_t i = 0; i < n; i++) diff |= x[i] ^ y[i];
|
||||
return diff; // 매 early-exit 의 X
|
||||
}
|
||||
```
|
||||
|
||||
### Cache partitioning (Intel CAT)
|
||||
```bash
|
||||
# 매 LLC ways 의 isolate — victim domain 의 dedicated partition
|
||||
pqos -e "llc:1=0x00ff;llc:2=0xff00"
|
||||
pqos -a "core:1=1;core:2=2"
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Crypto library 작성 | Constant-time + AES-NI/VAES intrinsics |
|
||||
| Cloud multi-tenant | CAT partitioning + SMT off + KPTI |
|
||||
| Browser (JS sandbox) | Site isolation + COOP/COEP + jittered timers |
|
||||
| Embedded ARM | MTE + speculative barriers (CSDB) |
|
||||
| Detection | Intel PMU `MEM_LOAD_RETIRED.L3_MISS` anomaly |
|
||||
|
||||
**기본값**: constant-time crypto + KPTI + retpoline/IBRS + browser site isolation.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[CPU Microarchitecture]] · [[Memory Hierarchy]]
|
||||
- 변형: [[Spectre]] · [[Meltdown]] · [[Rowhammer]]
|
||||
- 응용: [[AES Key Recovery]] · [[Cross-VM Attack]]
|
||||
- Adjacent: [[Constant-Time Crypto]] · [[Speculative Execution]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: red-team threat model 의 enumerate, mitigation review, constant-time code audit.
|
||||
**언제 X**: 매 actual exploit chain — practical attack 은 매 hardware-specific 의 measurement, LLM 의 hallucinate 가능.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Table-based AES in shared lib**: 매 T-table 의 cache footprint 가 key-dependent — Flush+Reload 의 즉시 leak.
|
||||
- **Branch on secret**: 매 BTB poisoning 의 vector — constant-time control flow 의 use.
|
||||
- **`memcmp` on secrets**: 매 early-exit timing — `ct_memcmp` 의 substitute.
|
||||
- **SMT enabled in cloud**: sibling thread 의 L1 share — 매 disable.
|
||||
- **Trusting `rdtsc` jitter as defense**: 매 attacker 의 amplify 가능 — fundamental fix 가 필요.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Yarom & Falkner USENIX Security 2014; Kocher et al. 2018; Intel SDM Vol 3 §11).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Flush+Reload, Spectre, constant-time mitigation 정리 |
|
||||
|
||||
Reference in New Issue
Block a user