[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,95 +2,237 @@
|
||||
id: wiki-2026-0508-도달-가능성-분석-reachability-analysis
|
||||
title: 도달 가능성 분석 (Reachability Analysis)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-03E8DE]
|
||||
aliases: [Reachability Analysis, Control Flow Reachability, Dead Code Detection]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [static-analysis, compiler, control-flow, dead-code, type-narrowing]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - 도달 가능성 분석 (Reachability [[Analysis]])"
|
||||
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: compiler-domain
|
||||
framework: TypeScript/Java/LLVM
|
||||
---
|
||||
|
||||
# [[도달 가능성 분석 ([[Reachability Analysis]])]]
|
||||
# 도달 가능성 분석 (Reachability Analysis)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> 도달 가능성 분석(Reachability Analysis)은 소스 코드 내의 데이터 흐름이나 호출 그래프(Call Graph)를 추적하여 특정 취약점이 실제 프로덕션 환경이나 실행 경로에서 도달 가능한지를 판별하는 보안 분석 기법입니다 [1, 2]. 이를 통해 신뢰할 수 없는 오염된 데이터가 민감한 싱크(sink)나 취약한 함수에 도달할 수 있는지 검증합니다 [3]. 결과적으로 실제 실행되지 않는 경로의 취약점을 필터링하여 경고 피로(alert fatigue)를 줄이고 보안 취약점 해결의 우선순위를 명확히 지정하는 데 핵심적인 역할을 합니다 [2, 4].
|
||||
## 매 한 줄
|
||||
> **"매 program point 가 매 실행될 수 있는지 매 control flow graph 위에서 결정"**. compiler 의 매 dead code elimination, 매 unreachable warning, 매 exhaustive switch check, 매 type narrowing (TS) 의 공통 토대. 매 forward / backward CFG traversal + 매 lattice 위 fixed-point.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **작동 원리**: 도달 가능성 분석은 소스 코드의 엔드포인트를 분석하고 취약한 함수로 향하는 호출 그래프를 생성하여 취약점의 실제 도달 여부를 보여줍니다 [1]. 특히 데이터 흐름을 추적하여 오염된 데이터(tainted data)가 민감한 영역(sensitive sinks)으로 흘러 들어갈 수 있는지 파악하는 데 중점을 둡니다 [3].
|
||||
- **오탐 및 알림 피로 감소**: 해당 분석 기법은 취약한 함수가 실제로 호출되는지, 또는 신뢰할 수 없는 사용자 입력에 노출되는지와 같은 문맥(context)을 기반으로 스캔 결과를 필터링합니다 [2]. 이를 통해 무의미한 오탐(False Positive)으로 인한 알림 피로도를 줄이고, 개발자가 실제 위험이 존재하는 취약점을 기반으로 리스크 우선순위를 지정할 수 있도록 돕습니다 [4].
|
||||
- **주요 보안 도구([[SAST]]/SCA)에서의 활용**:
|
||||
- **Endor Labs**: 서드파티(third-party)와 퍼스트파티(first-party) 코드 전반에 걸쳐 매우 세밀한 함수 수준(function-level)의 도달 가능성을 분석하여, 코드의 취약점이 실제 실행 경로와 어떻게 연결되는지 파악합니다 [2, 4].
|
||||
- **Veracode**: 오염된 데이터가 민감한 영역에 접근하는지 확인하기 위해 데이터 흐름 추적 및 도달 가능성 분석을 수행합니다 [3].
|
||||
- **[[Corgea]]**: 엔드포인트를 해석하고 호출 그래프를 구축하여 실질적인 도달 가능성을 증명합니다 [1].
|
||||
- **Qwiet AI (Harness)**: 스캔 속도 향상 및 도달 가능성을 기반으로 한 취약점 필터링에 중점을 두어 결과를 도출합니다 [5, 6].
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
|
||||
### 매 정의
|
||||
- **CFG (Control Flow Graph)**: 매 basic block 노드 + 매 control edge.
|
||||
- **Reachable**: 매 entry 에서 매 path 가 존재.
|
||||
- **Forward analysis**: 매 entry → 매 모든 노드.
|
||||
- **Backward analysis**: 매 exit ← 매 모든 노드 (liveness 등).
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[정적 애플리케이션 보안 테스트 (SAST)]], 소프트웨어 구성 분석 (SCA), 데이터 흐름 분석 (Data Flow Analysis), 호출 그래프 (Call Graph)
|
||||
- **Projects/Contexts:** Endor Labs, Veracode, [[Corgea]], Qwiet AI
|
||||
- **Contradictions/Notes:** 단순 규칙이나 패턴 기반의 전통적인 정적 분석 도구는 문맥 파악의 한계로 인해 오탐을 다수 발생시킬 수 있으나, 도달 가능성 분석이 결합된 최신 분석 도구들은 도달 불가능한 경로의 노이즈를 필터링하여 실제 문제 해결 효율을 크게 높여줍니다 [4, 7].
|
||||
### 매 lattice
|
||||
- 매 `{Reachable, Unreachable}` — 매 simple Boolean lattice.
|
||||
- 매 transfer function: 매 block end 에서 매 successor 로 propagate.
|
||||
- 매 join: 매 OR (predecessor 중 하나라도 reachable 이면 reachable).
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-18*
|
||||
### 매 응용
|
||||
1. Dead code elimination (compile-time).
|
||||
2. Unreachable code warning (TS, Java, Rust).
|
||||
3. Exhaustive switch check (TS `never`, Rust `!`).
|
||||
4. Liveness analysis (register allocation).
|
||||
5. Type narrowing (TypeScript control-flow analysis).
|
||||
|
||||
---
|
||||
## 💻 패턴
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### CFG construction (simple imperative)
|
||||
```ts
|
||||
type BB = { id: string; stmts: Stmt[]; succ: string[] };
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(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
|
||||
function buildCFG(fn: FunctionAST): Map<string, BB> {
|
||||
const blocks = new Map<string, BB>();
|
||||
let cur: BB = { id: "entry", stmts: [], succ: [] };
|
||||
blocks.set("entry", cur);
|
||||
for (const s of fn.body) {
|
||||
if (s.kind === "if") {
|
||||
const thenId = freshId(), elseId = freshId(), joinId = freshId();
|
||||
cur.succ = [thenId, elseId];
|
||||
const thenB: BB = { id: thenId, stmts: s.then, succ: [joinId] };
|
||||
const elseB: BB = { id: elseId, stmts: s.else ?? [], succ: [joinId] };
|
||||
const joinB: BB = { id: joinId, stmts: [], succ: [] };
|
||||
blocks.set(thenId, thenB);
|
||||
blocks.set(elseId, elseB);
|
||||
blocks.set(joinId, joinB);
|
||||
cur = joinB;
|
||||
} else if (s.kind === "return") {
|
||||
cur.stmts.push(s);
|
||||
cur.succ = [];
|
||||
cur = { id: freshId(), stmts: [], succ: [] };
|
||||
blocks.set(cur.id, cur);
|
||||
} else {
|
||||
cur.stmts.push(s);
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Forward reachability (worklist)
|
||||
```ts
|
||||
function reachableSet(cfg: Map<string, BB>): Set<string> {
|
||||
const reachable = new Set<string>(["entry"]);
|
||||
const worklist: string[] = ["entry"];
|
||||
while (worklist.length > 0) {
|
||||
const id = worklist.pop()!;
|
||||
const bb = cfg.get(id)!;
|
||||
for (const s of bb.succ) {
|
||||
if (!reachable.has(s)) {
|
||||
reachable.add(s);
|
||||
worklist.push(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return reachable;
|
||||
}
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
function unreachableBlocks(cfg: Map<string, BB>): string[] {
|
||||
const r = reachableSet(cfg);
|
||||
return [...cfg.keys()].filter(id => !r.has(id));
|
||||
}
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### TS exhaustive switch (`never` reach)
|
||||
```ts
|
||||
type Shape =
|
||||
| { kind: "circle"; r: number }
|
||||
| { kind: "square"; side: number }
|
||||
| { kind: "triangle"; base: number; height: number };
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
function area(s: Shape): number {
|
||||
switch (s.kind) {
|
||||
case "circle": return Math.PI * s.r ** 2;
|
||||
case "square": return s.side ** 2;
|
||||
case "triangle": return s.base * s.height / 2;
|
||||
default:
|
||||
const _exhaustive: never = s;
|
||||
throw new Error(`unreachable: ${_exhaustive}`);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### TS control-flow type narrowing (reachability + narrowing)
|
||||
```ts
|
||||
function process(input: string | null) {
|
||||
if (input === null) {
|
||||
return "no input";
|
||||
}
|
||||
return input.toUpperCase();
|
||||
}
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
function withReturn(x: number) {
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
}
|
||||
return x * 2;
|
||||
}
|
||||
```
|
||||
|
||||
### Dead code after return
|
||||
```ts
|
||||
function foo() {
|
||||
return 42;
|
||||
console.log("unreachable"); // 매 TS warning ts(7027)
|
||||
}
|
||||
```
|
||||
|
||||
### Java unreachable statement (JLS 14.21)
|
||||
```java
|
||||
void example() {
|
||||
while (true) {
|
||||
if (cond()) break;
|
||||
}
|
||||
System.out.println("ok");
|
||||
|
||||
while (true) {}
|
||||
System.out.println("dead"); // 매 compile error
|
||||
}
|
||||
```
|
||||
|
||||
### LLVM dead-code elimination (conceptual)
|
||||
```llvm
|
||||
; 매 before
|
||||
define i32 @foo() {
|
||||
entry:
|
||||
ret i32 42
|
||||
%dead = add i32 1, 2
|
||||
ret i32 %dead
|
||||
}
|
||||
|
||||
; 매 after DCE pass
|
||||
define i32 @foo() {
|
||||
entry:
|
||||
ret i32 42
|
||||
}
|
||||
```
|
||||
|
||||
### Liveness (backward reachability)
|
||||
```ts
|
||||
function liveness(cfg: Map<string, BB>): Map<string, Set<string>> {
|
||||
const liveOut = new Map<string, Set<string>>();
|
||||
for (const id of cfg.keys()) liveOut.set(id, new Set());
|
||||
let changed = true;
|
||||
while (changed) {
|
||||
changed = false;
|
||||
for (const [id, bb] of cfg) {
|
||||
const live = new Set<string>();
|
||||
for (const s of bb.succ) {
|
||||
for (const v of liveOut.get(s) ?? []) live.add(v);
|
||||
}
|
||||
const def = defsOf(bb), use = usesOf(bb);
|
||||
const liveIn = new Set([...use, ...[...live].filter(v => !def.has(v))]);
|
||||
if (!eqSet(liveIn, liveOut.get(id)!)) {
|
||||
liveOut.set(id, liveIn);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return liveOut;
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 목적 | 알고리즘 |
|
||||
|---|---|
|
||||
| Dead code elimination | Forward reachability + DCE pass |
|
||||
| Exhaustive switch | Type narrowing → `never` 도달 |
|
||||
| Unreachable warning | Forward reach + report unreachable BB |
|
||||
| Liveness (register alloc) | Backward dataflow |
|
||||
| Static deadlock / null check | Symbolic + reach |
|
||||
|
||||
**기본값**: Forward worklist algorithm + Boolean lattice. 매 type narrowing 매 data-flow + reach 결합.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Static Analysis]] · [[Compiler]]
|
||||
- 변형: [[Liveness Analysis]] · [[Constant Propagation]] · [[Available Expressions]]
|
||||
- 응용: [[Dead Code Elimination]] · [[Register Allocation]] · [[Type Narrowing]]
|
||||
- Adjacent: [[Control Flow Graph]] · [[Data Flow Analysis]] · [[Abstract Interpretation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 compiler 설계, 매 linter 작성, 매 IDE feature, 매 type system 분석.
|
||||
**언제 X**: 매 application code 작성 (매 compiler 가 자동 처리).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Path-sensitive 가정 X**: 매 conditional reach 무시 — 매 false positive 폭증.
|
||||
- **Loop fixed-point 누락**: 매 1-pass 만 — 매 cycle 미처리.
|
||||
- **Exception edge 무시**: 매 throw 후 reach 잘못 — 매 catch 매 edge.
|
||||
- **Switch fallthrough 모델링 X**: 매 C/Java fall-through case 매 단일 successor.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Aho/Lam/Sethi/Ullman "Compilers" Ch. 9, Java Language Specification §14.21, TypeScript Compiler API).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — CFG + 8 reachability patterns |
|
||||
|
||||
Reference in New Issue
Block a user