Using the SEI CERT Secure Cod- Ing Standard to Reduce Vulnera- Bilities
Total Page:16
File Type:pdf, Size:1020Kb
Linköping University | Department of Computer and Information Science Master’s thesis, 30 ECTS | Datateknik 2021 | LIU-IDA/LITH-EX-A--21/018--SE Using the SEI CERT Secure Cod- ing Standard to Reduce Vulnera- bilities Johan Fisch Carl Haglund Supervisors : Senyang Huang, Rahul Hiran, Ioannis Avgouleas Examiner : Andrei Gurtov Linköpings universitet SE–581 83 Linköping +46 13 28 10 00 , www.liu.se Upphovsrätt Detta dokument hålls tillgängligt på Internet - eller dess framtida ersättare - under 25 år från publicer- ingsdatum under förutsättning att inga extraordinära omständigheter uppstår. Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka ko- pior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervis- ning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säker- heten och tillgängligheten finns lösningar av teknisk och administrativ art. Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsman- nens litterära eller konstnärliga anseende eller egenart. För ytterligare information om Linköping University Electronic Press se förlagets hemsida http://www.ep.liu.se/. Copyright The publishers will keep this document online on the Internet - or its possible replacement - for a period of 25 years starting from the date of publication barring exceptional circumstances. The online availability of the document implies permanent permission for anyone to read, to down- load, or to print out single copies for his/hers own use and to use it unchanged for non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional upon the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility. According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement. For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its www home page: http://www.ep.liu.se/. Johan Fisch © Carl Haglund Abstract Security is a critical part of every software developed today and it will be even more important going forward when more devices are getting connected to the internet. By striv- ing to improve the quality of the code, in particular the security aspects, there might be a reduction in the number of vulnerabilities and improvements of the software developed. By looking at issues from past problems and studying the code in question to see whether it follows the SEI CERT secure coding standards, it is possible to tell if compliance to this standard would be helpful to reduce future problems. In this thesis an analysis of vulner- abilities, written in C and C++, reported in Common Vulnerabilities and Exposures (CVE), will be done to verify whether applying the SEI CERT secure coding standard will help reduce vulnerabilities. This study also evaluates the SEI CERT rule coverage of three dif- ferent static analysis tools, Rosecheckers, PVS-Studio and CodeChecker by executing them on these vulnerabilities. By using three different metrics, true positive, false negative and the run time. The results of the study are promising since it shows that compliance to the SEI CERT standard does indeed reduce vulnerabilities. Of the analyzed vulnerabilities it was found that about 60% of these could have been avoided, if the standard had been fol- lowed. The results of the tools were of great interest as well, it showed that the tools did not perform as well as the manual analysis, however, all of them found some SEI CERT rule vi- olations in different areas. Conclusively, a combination of manual analysis and these three static analysis tools would have resulted in the highest number of vulnerabilities avoided. Acknowledgments We would like to thank Ericsson and their employees that have been involved in our work. A special thanks goes out to Rahul Hiran, our supervisor at Ericsson. Without his interesting ideas and help throughout the whole process, the results of the thesis would not have been the same. We would also like to thank the developers of the tool CodeChecker at Ericsson, especially Daniel Krupp who took the time to have a meeting with us and explain more about the tool. Appreciation also goes out to Linköping University. We would like to thank our supervisors Senyang Huang and Ioannis Avgouleas as well as our examiner Andrei Gurtov who have assisted us with the thesis writing and provided us with interesting and valuable thoughts about the area. iv Contents Abstract iii Acknowledgments iv Contents v List of Figures vii List of Tables ix Listings x 1 Introduction 1 1.1 Motivation . 2 1.2 Aim............................................ 2 1.3 Research questions . 2 1.4 Delimitations . 2 2 Theory 4 2.1 Secure software development . 4 2.2 CVE............................................ 5 2.3 SEI CERT Coding Standard . 5 2.4 SEI CERT C Coding Standard . 5 2.5 SEI CERT C++ Coding Standard . 11 2.6 CVSS . 11 2.7 Static Analysis Tools . 11 2.8 Programming languages . 13 3 Related Work 15 3.1 Secure coding . 15 3.2 Benefits of coding standards . 16 3.3 Evaluation of static analysis tools . 17 3.4 Collection of vulnerabilities . 18 4 Method 20 4.1 Approach . 20 4.2 Gathering of vulnerabilities in CVE . 20 4.3 Analyzing vulnerabilities in CVE . 21 4.4 Gathering rule specific CVE vulnerabilities . 25 4.5 Analyzing rule specific CVE vulnerabilities . 26 4.6 Case studies . 26 5 Results 28 5.1 Gathering of vulnerabilities in CVE . 28 v 5.2 Analyzing vulnerabilities in CVE . 28 6 Discussion 41 6.1 Method . 41 6.2 Results . 44 6.3 The work in a wider context . 47 7 Conclusion 48 7.1 How can vulnerabilities be reduced in the early phase of software development? 48 7.2 To what extent does SEI CERT compliance help reduce vulnerabilities? . 48 7.3 What tools can help complying with the SEI CERT secure coding standard? . 49 7.4 Future work . 49 Bibliography 50 A Script for gathering EXP34-C CVE vulnerabilities. 54 B Script to gather C++ CVE:s 55 C C CVE:s 56 D C++ CVE:s 58 E Rule Specific CVE:s 60 F Rule Specific figures 63 F.1 ARR30-C . 63 F.2 EXP33-C . 65 F.3 EXP34-C . 66 F.4 FIO47-C . 67 F.5 INT30-C . 68 F.6 INT32-C . 69 F.7 INT33-C . 69 F.8 MEM30-C . 70 F.9 MEM35-C . 71 F.10 STR31-C . 72 vi List of Figures 2.1 Abstract syntax tree generated for the code in Listing 2.9 . 13 4.1 Description of a CVE vulnerability. 21 4.2 Example of PVS-Studio output. 23 4.3 Example of Rosecheckers output. 24 4.4 Rules that Rosecheckers covers for memory management [rose_source]. 24 4.5 Example of CodeChecker HTML output. 25 5.1 SEI CERT C Rule vs. No Rule distribution for the 60 CVE:s analyzed. 29 5.2 SEI CERT C Rule distribution for the 38 CVE:s where a rule could be found. 29 5.3 Risk level distribution for the 16 different rules found during C analysis. 30 5.4 Number of SEI CERT C violations found per rule during C analysis. 30 5.5 Percentages of violations found per rule during C analysis. 31 5.6 Violations found in relation to size during C analysis. 31 5.7 SEI CERT C++ Rule vs. No Rule distribution for the 60 CVE:s analyzed. 32 5.8 SEI CERT C++ Rule distribution for the 37 CVE:s where a rule could be found. 33 5.9 Risk level distribution for the 12 different rules found during C++ analysis. 33 5.10 Number of SEI CERT C++ violations found per rule during C++ analysis. 34 5.11 Percentages of violations found per rule during C++ analysis. 34 5.12 Static analysis tools Run time comparison. 35 5.13 PVS & Rosecheckers Run time in relation to project size. 35 5.14 PVS & Rosecheckers Run time in relation to number of files. 36 5.15 CodeChecker Run time in relation to project size. 36 5.16 CodeChecker Run time in relation to number of files. 36 5.17 Rule specific violations found per static analysis tool. 37 5.18 Rule specific project size in relation to found violations per static analysis tool. 38 5.19 Rule specific project run time in relation to size per static analysis tool. 39 5.20 Rule specific number of violations found in relation to CVSS per static analysis tool. 39 F.1 ARR30-C Size related to run time. 63 F.2 ARR30-C Size related to number of found violations. 64 F.3 ARR30-C CVSS related to number of found violations. 64 F.4 EXP33-C Size related to run time. 65 F.5 EXP33-C Size related to number of found violations. 65 F.6 EXP33-C CVSS related to number of found violations. 65 F.7 EXP34-C Size related to run time. 66 F.8 EXP34-C Size related to number of found violations. 66 F.9 EXP34-C CVSS related to number of found violations. 66 F.10 FIO47-C Size related to run time.