JDK imid imaximin2imin Bug ID 5045582 coll binary
经典案例 • JDK的二分查找缺陷 修复方案 imid = (imax-imin)/2+imin * "Bug ID: 5045582 (coll) binary. Search() fails for size larger than 1<<30". Java Bug Database. Oracle. 11 May 6 2004.
从一个简单例子说起 abs()函数符号执行的简单介绍 运行内存S y: _y result: - res: - 函数返回值 int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } //int main() { // return abs(10)+abs(10); //}
从一个简单例子说起 abs()函数符号执行的简单介绍 运行内存S int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } y: _y result: - res: - _y >= 0 ? √ _y < 0 ? √ 何去何从? //int main() { // return abs(10)+abs(10); //}
从一个简单例子说起 abs()函数符号执行的简单介绍 运行内存S‘ y: _y result: _y res: - 约束:_y >= 0 y: _y result: - res: - 约束:_y < 0 Then分支 int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } //int main() { // return abs(10)+abs(10); //}
从一个简单例子说起 abs()函数符号执行的简单介绍 运行内存S y: _y 运行内存S‘ y: _y result: - res: _y res: - 约束:_y >= 0 约束:_y < 0 Then分支跳出 int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } //int main() { // return abs(10)+abs(10); //}
从一个简单例子说起 abs()函数符号执行的简单介绍 运行内存S‘ y: _y result: -_y res: _y 约束:_y >= 0 res: - 约束:_y < 0 Else分支 int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } //int main() { // return abs(10)+abs(10); //}
从一个简单例子说起 abs()函数符号执行的简单介绍 运行内存S‘ y: _y result: -_y res: -_y 约束:_y >= 0 约束:_y < 0 Else分支跳出 int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } //int main() { // return abs(10)+abs(10); //}
基于函数摘要的符号执行 一次abs()分析结果 y>=0 函数摘要 y<0 Pre: y>=0 Post: res == old(y) Pre: y<0 Post: res == old(y) 函数行为 int abs(int y) { int result; if(y>=0) { result = y; } else { result = -y; } return result; } int main() { return abs(10)+abs(-10); }
具架构 C Code C-to-LLVM Compiler e. g. , Clang Error & Warning Report 辅助代码约 2. 5万行 LLVM IR Code 约 2. 5万行 Symbolic Execution Scheduler (strategy) Symbolic Execution Engine (Core) Solver 约 0. 5万行 Specs of Standard Libraries 约 1. 5万行 e. g. , STP… 实现:复用KLEE的部分框架代码,修改新增约 8万行C++代码
针对CWE测试集的评估 • CWE(Common Weakness Enumeration)介绍 • 网址: https: //cwe. mitre. org/ • CWE是美国国土安全部网络安全和通讯办公室的US-CERT赞 助(CWE is sponsored by US-CERT in the office of Cybersecurity and Communications at the U. S. Department of Homeland Security. )基于该测试集等相关技术, MITRE提供分 析 具的认证服务. • 我们评估使用的是Juliet_Testsuit_for_C_C++_1. 2版 • 该测试集包括C/C++的测试例, 用于评估分析 具的分析准确性. • 包括C++测试例,其中共有6万多个测试例
评估统计结果 文件数 代码行数 误报 漏报 “误报率 ” “漏报率 ” 运行时间 (s) CWE 121_Stack_Based_Buffer_Overflow 2844 378664 0 6 0. 00% 0. 21% 1391. 55 CWE 122_Heap_Based_Buffer_Overflow 1736 242820 0 205 0. 00% 11. 81% 845. 93 CWE 124_Buffer_Underwrite 896 140972 0 10 0. 00% 1. 12% 290 CWE 126_Buffer_Overread 708 112444 0 22 0. 00% 3. 11% 262. 16 CWE 127_Buffer_Underread 896 137084 0 10 0. 00% 1. 12% 259. 84 CWE 190_Integer_Overflow 3024 397290 312 6 10. 32% 0. 20% 590. 99 CWE 191_Integer_Underflow 1848 245186 180 4 9. 74% 0. 22% 354. 41 CWE 369_Divide_by_Zero 467 102848 0 0 0. 00% 137. 04 CWE 401_Memory_Leak 628 94579 0 89 0. 00% 14. 17% 236. 37 CWE 415_Double_Free 156 22956 12 0 7. 69% 0. 00% 26. 22 CWE 416_Use_After_Free 126 23103 0 0 0. 00% 91. 68 CWE 457_Use_of_Uninitialized_Variable 504 95582 0 0 0. 00% 83. 29 CWE 476_NULL_Pointer_Dereference 204 28748 0 0 0. 00% 30. 82 2 170 0 0 0. 00% 0. 36 520 57580 0 4 0. 00% 0. 77% 114. 08 CWE 773_Missing_Reference_to_Active_File_Desc riptor_or_Handle 52 6450 0 8 0. 00% 15. 38% 12. 72 CWE 775_Missing_Release_of_File_Descriptor_or_ Handle 52 5686 0 26 0. 00% 50. 00% 8. 99 14663 2092162 504 423 3. 44% 2. 88% 4736. 45 CWE测试种类目录 CWE 562_Return_of_Stack_Variable_Address CWE 690_NULL_Deref_From_Return 总计
例程2 int foo(int x, int y) { int result; if(x>0) { printf(“x is greater than zero”); } else { printf(“x is not greater than zero”); x>0 y>=0 x<=0 y<0 y>=0 y<0 } if(y>=0) { result = y; } else { result = -y; } return result; } 状态爆炸 Pre: x>0 / y>0 Post: res == old(y) Pre: x<=0 / y>0 Post: res == old(y) Pre: x>0 / y<=0 Post: res == -old(y) Pre: x<=0 / y<=0 Post: res == -old(y)
状态合并实验结果(部分) 1400 1200 1000 分析�� (秒) 800 合并前 600 合并后 400 200 0 nice. c paste. c tty. c mv. c dd. c Linux Core. Utils例程 shuf. c
回顾例程2 int foo(int x, int y) { int result; if(x>0) { printf(“x is greater than zero”); } else { printf(“x is not greater than zero”); x>0 缓存 y>=0 x<=0 命中 y<0 } if(y>=0) { result = y; } else { result = -y; Pre: x>0 / y>0 Post: res == old(y) Pre: x>0 / y<=0 Post: res == -old(y) Pre: y<=0 Post: res == -old(y) } return result; } 依据命中情况对已有函数行为进行变换
- Slides: 62