消除冗餘的 C/C++ Sanitizers 檢查:以 EffectiveSan 為例
Eliminating Redundant Checks in C/C++ Sanitizers: A Case Study on EffectiveSan
摘要
程式語言 C/C++ 在世界上被廣泛應用於開發那些以效能與效率為主要考量的軟體。 然而,因為 C/C++ 所擁有的高度彈性,以 C/C++ 所開發的軟體容易出現缺陷進而導致安全性上的問題。因此,有許多研究致力於評估 C/C++ 程式的安全性。其中一個能夠有效偵測軟體漏洞的方法就是使用 sanitizers,sanitizers 會在編譯時期安插額外的程式碼在程式裡,這些額外的程式碼便可在執行期間去偵測不管是空間上 (e.g., buffer overflow and type confusion) 還是時間上 (e.g., use-after-free) 的記憶體濫用行為。儘管如此,因為 sanitizers 的設計機制上的緣故,使用 sanitizers 通常伴隨著相當大的執行成本。我們提出一個能夠定位並移除不需要或是多餘的空間相關檢查的工具 Sanitizer-Reduce。Sanitizer-Reduce 透過分析被檢查的指標是否為安全的來決定一個檢查是否為非必要的,以及分析是否有其他檢查相同指標的檢查已經被執行過了,來決定一個檢查是否為多餘的。我們將 Sanitizer-Reduce 應用在 SPEC CPU2006 benchmarks 上,並以 Effective Type Sanitizer (EffectiveSan) 作為基準點去做實驗。實驗結果顯示,Sanitizer-Reduce 能夠有效地減少 sanitizers 所帶來的執行成本 (8.9%),同時也能夠保有 EffectiveSan 偵測空間相關的記憶體濫用行為的能力。
The C/C++ language has been widely used for developing software that takes performance and efficiency as top priority. However, software written in C/C++ is more likely to be defective due to its high programming flexibility. Consequently, there have been extensive research efforts to evaluate the safety of C/C++ programs. One of effective approaches for detecting potential vulnerability is to design a sanitizer, which performs compile-time instrumentation to check spatial memory errors (e.g., buffer overflow and type confusion) or/and temporal memory errors (e.g., use-after-free) at runtime. Nevertheless, sanitizers usually incur a considerable runtime overhead. In this thesis, we propose a tool, called Sanitizer-Reduce, that removes unnecessary and redundant spatial checks generated by sanitizers. Sanitizer-Reduce determines whether a check is unnecessary by verifying if the pointer to check is intrinsically secure and whether a check is redundant by examining if the check has been performed. We evaluated the proposed tool with the SPEC CPU2006 benchmark suite by taking the Effective Type Sanitizer (EffectiveSan) as a case study. Experiments demonstrated that Sanitizer-Reduce effectively reduced the overhead of EffectiveSan by 8.9% while retaining the effectiveness in detecting spatial memory errors.