Loading...
Loading...
Compare original and translation side by side
| Concept | Description |
|---|---|
| Instrumentation | ASan adds runtime checks to memory operations during compilation |
| Shadow Memory | Maps 20TB of virtual memory to track allocation state |
| Performance Cost | Approximately 2-4x slowdown compared to non-instrumented code |
| Detection Scope | Finds buffer overflows, use-after-free, double-free, and memory leaks |
| Concept | 描述 |
|---|---|
| Instrumentation | ASan会在编译阶段为内存操作添加运行时检查 |
| Shadow Memory | 映射20TB虚拟内存以跟踪内存分配状态 |
| Performance Cost | 与未插桩的代码相比,性能大约下降2-4倍 |
| Detection Scope | 可检测缓冲区溢出、释放后使用、重复释放以及内存泄漏问题 |
| Task | Command/Pattern |
|---|---|
| Enable ASan (Clang/GCC) | |
| Enable verbosity | |
| Disable leak detection | |
| Force abort on error | |
| Multiple options | |
| 任务 | 命令/配置 |
|---|---|
| 启用ASan(Clang/GCC) | |
| 启用详细日志 | |
| 禁用泄漏检测 | |
| 检测到错误时强制终止 | |
| 多选项配置 | |
-fsanitize=addressclang -fsanitize=address -g -o my_program my_program.c-g-fsanitize=addressclang -fsanitize=address -g -o my_program my_program.c-gASAN_OPTIONSexport ASAN_OPTIONS=verbosity=1:abort_on_error=1:detect_leaks=0ASAN_OPTIONSexport ASAN_OPTIONS=verbosity=1:abort_on_error=1:detect_leaks=0./my_program./my_program-rss_limit_mb=0-m none-rss_limit_mb=0-m noneclang -o fuzz_target fuzz_target.c
./fuzz_targetclang -fsanitize=address -g -o fuzz_target fuzz_target.c
ASAN_OPTIONS=verbosity=1:abort_on_error=1 ./fuzz_targetclang -o fuzz_target fuzz_target.c
./fuzz_targetclang -fsanitize=address -g -o fuzz_target fuzz_target.c
ASAN_OPTIONS=verbosity=1:abort_on_error=1 ./fuzz_targetgcc -o test_suite test_suite.c -lcheck
./test_suitegcc -fsanitize=address -g -o test_suite test_suite.c -lcheck
ASAN_OPTIONS=detect_leaks=1 ./test_suitegcc -o test_suite test_suite.c -lcheck
./test_suitegcc -fsanitize=address -g -o test_suite test_suite.c -lcheck
ASAN_OPTIONS=detect_leaks=1 ./test_suite| Tip | Why It Helps |
|---|---|
Use | Provides detailed stack traces for debugging |
Set | Confirms ASan is enabled before program starts |
| Disable leaks during fuzzing | Leak detection doesn't cause immediate crashes, clutters output |
Enable | Some fuzzers require |
| 技巧 | 作用 |
|---|---|
使用 | 提供详细的堆栈跟踪以辅助调试 |
设置 | 在程序启动前确认ASan已启用 |
| 模糊测试时禁用泄漏检测 | 泄漏检测不会导致立即崩溃,会使输出信息杂乱 |
启用 | 部分模糊测试工具需要 |
==12345==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000eff4 at pc 0x00000048e6a3
READ of size 4 at 0x60300000eff4 thread T0
#0 0x48e6a2 in main /path/to/file.c:42==12345==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000eff4 at pc 0x00000048e6a3
READ of size 4 at 0x60300000eff4 thread T0
#0 0x48e6a2 in main /path/to/file.c:42clang -fsanitize=address,undefined -g -o fuzz_target fuzz_target.cclang -fsanitize=address,undefined -g -o fuzz_target fuzz_target.c| Anti-Pattern | Problem | Correct Approach |
|---|---|---|
| Using ASan in production | Can make applications less secure | Use ASan only for testing |
| Not disabling memory limits | Fuzzer may kill process due to 20TB virtual memory | Set |
| Ignoring leak reports | Memory leaks indicate resource management issues | Review leak reports at end of fuzzing campaign |
| 反模式 | 问题 | 正确做法 |
|---|---|---|
| 在生产环境中使用ASan | 会降低应用程序的安全性 | 仅在测试阶段使用ASan |
| 未禁用内存限制 | 模糊测试工具可能因20TB虚拟内存需求而终止进程 | 设置 |
| 忽略泄漏报告 | 内存泄漏表明存在资源管理问题 | 在模糊测试结束后查看泄漏报告 |
clang++ -fsanitize=fuzzer,address -g harness.cc -o fuzz./fuzz -rss_limit_mb=0-fsanitize=fuzzer-fsanitize=address-gASAN_OPTIONS=abort_on_error=1clang++ -fsanitize=fuzzer,address -g harness.cc -o fuzz./fuzz -rss_limit_mb=0-fsanitize=fuzzer-fsanitize=address-gASAN_OPTIONS=abort_on_error=1AFL_USE_ASANAFL_USE_ASAN=1 afl-clang-fast++ -g harness.cc -o fuzzafl-fuzz -m none -i input_dir -o output_dir ./fuzzAFL_USE_ASAN=1-m noneAFL_MAP_SIZEAFL_USE_ASANAFL_USE_ASAN=1 afl-clang-fast++ -g harness.cc -o fuzzafl-fuzz -m none -i input_dir -o output_dir ./fuzzAFL_USE_ASAN=1-m noneAFL_MAP_SIZE--sanitizer=addresscargo fuzz run fuzz_target --sanitizer=addressfuzz/Cargo.toml[profile.release]
opt-level = 3
debug = true--sanitizer=addresscargo fuzz run fuzz_target --sanitizer=addressfuzz/Cargo.toml[profile.release]
opt-level = 3
debug = truehonggfuzz -i input_dir -o output_dir -- ./fuzz_target_asanhfuzz-clang -fsanitize=address -g target.c -o fuzz_target_asanhonggfuzz -i input_dir -o output_dir -- ./fuzz_target_asanhfuzz-clang -fsanitize=address -g target.c -o fuzz_target_asan| Issue | Cause | Solution |
|---|---|---|
| Fuzzer kills process immediately | Memory limit too low for ASan's 20TB virtual memory | Use |
| "ASan runtime not initialized" | Wrong linking order or missing runtime | Ensure |
| Leak reports clutter output | LeakSanitizer enabled by default | Set |
| Poor performance (>4x slowdown) | Debug mode or unoptimized build | Compile with |
| ASan not detecting obvious bugs | Binary not instrumented | Check with |
| False positives | Interceptor conflicts | Check ASan FAQ for known issues with specific libraries |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 模糊测试工具立即终止进程 | ASan需要20TB虚拟内存,而工具的内存限制过低 | 使用 |
| "ASan runtime not initialized" | 链接顺序错误或缺少运行时库 | 确保编译和链接阶段都使用了 |
| 泄漏报告使输出杂乱 | LeakSanitizer默认启用 | 设置 |
| 性能极差(慢于4倍) | 调试模式或未优化的构建 | 结合 |
| ASan未检测到明显的bug | 二进制文件未被插桩 | 使用 |
| 误报 | 拦截器冲突 | 查看ASan FAQ了解特定库的已知问题 |
| Skill | How It Applies |
|---|---|
| libfuzzer | Compile with |
| aflpp | Use |
| cargo-fuzz | Use |
| honggfuzz | Compile target with |
| 技术 | 应用方式 |
|---|---|
| libfuzzer | 使用 |
| aflpp | 编译时使用 |
| cargo-fuzz | 使用 |
| honggfuzz | 使用 |
| Skill | Relationship |
|---|---|
| undefined-behavior-sanitizer | Often used together with ASan for comprehensive bug detection (undefined behavior + memory errors) |
| fuzz-harness-writing | Harnesses must be designed to handle ASan-detected crashes and avoid false positives |
| coverage-analysis | Coverage-guided fuzzing helps trigger code paths where ASan can detect memory errors |
| 技术 | 关系 |
|---|---|
| undefined-behavior-sanitizer | 常与ASan结合使用,实现全面的漏洞检测(未定义行为+内存错误) |
| fuzz-harness-writing | 测试桩需要设计为能处理ASan检测到的崩溃并避免误报 |
| coverage-analysis | 覆盖导向的模糊测试有助于触发ASan可检测到内存错误的代码路径 |
verbositylog_pathsymbolizeexternal_symbolizer_pathdetect_leaksabort_on_errorabort()_exit()detect_stack_use_after_returncheck_initialization_orderverbositylog_pathsymbolizeexternal_symbolizer_pathdetect_leaksabort_on_errorabort()_exit()detect_stack_use_after_returncheck_initialization_order