|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP LINKS YOU MUST CLICK ON Interviews
"Secure Coding in C and C++" A Linux.SYS-CON.com Interview With Robert Seacord
An interview with Robert Seacord, senior vulnerability analyst at CERT
By: Ibrahim Haddad
Dec. 24, 2005 02:15 PM
Digg This!
Page 1 of 2
next page »
Robert C. Seacord, a senior vulnerability analyst at the CERT/Coordination Center at Carnegie Mellon University, has just published the book Secure Coding in C and C++ (Addison-Wesley, 2005). I sat down with him to discuss software security in the Linux environment and elsewhere.
RCS: I agree there's no real security through obscurity, but obscurity does provide an impediment. Attackers can "reuse" sections of code to develop exploits that have the same properties as the code they're attacking - an unintended but unfortunate consequence of reuse. A number of security experts have argued that Open Source software is more secure because it's open to review by a broad range of individuals. However, Open Source software provides no guarantee that the software is reviewed or that those reviewing it understand the program's context in a larger system or the program's external interactions. In other words, just being able to read the code doesn't mean you have the wherewithal to do anything with it or about it. On the other hand, attackers have also become adept at reverse-engineering executables so not releasing the source only slows attackers down. An analysis of CERT/CC vulnerability reports conducted by Omar Alhazmi at Colorado State University shows vulnerabilities accruing in both Windows and Linux operating systems at similar rates. LWM: In your experience, which programming languages (e.g., C, C++, Java) provide the most secure programming safeguards and the most tools to ensure the code doesn't contain vulnerabilities? RCS: While languages like Java that have automatic garbage collection, lack pointers, and have strict type checking can limit or prevent vulnerabilities resulting from buffer overflows and common dynamic memory management errors, programming errors that result in security vulnerabilities can happen in any language. There are tradeoffs that have to be considered in language and application development platforms that can't always be objectively reduced to "Which is more secure?" Java programs can be vulnerable to SQL injection and cross-site scripting (XSS) vulnerabilities. Integer errors can also occur undetected, although the consequence of these errors is typically not as severe as they may be in C and C++ language programs. Interestingly, Java language security may be due more to the reasons given above and less to Java bytecodes than typically understood. C++ programs compiled to MSIL in the Microsoft .NET environment are as susceptible to buffer overflows and other common vulnerabilities as their compiled counterparts, although additional security can be gained by using the new system-level data structures for arrays, strings, and other data types. Because of the history of security vulnerabilities in C and C++, a number of tools and products have been developed to make these languages more secure. So, ironically, these languages generally have the best tool support. LWM: What's the most important coding practice that we can implement to develop more secure software? Can you also provide us your Top 5 best practices for writing secure C/C++ code? RCS: The most important coding practice is to be extremely paranoid in handling any data that originated with the user, either directly or indirectly. As for the remaining four:
RCS: I would have to say gets(), strcpy(), and sprintf(). The gets() function is on the list because it can't be used safely. The function reads a line from standard input into the buffer until a terminating new line or EOF is found. In fact, the Linux man page for this function contains the following advice: Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. There are two alternative functions that can be used: fgets() and gets_s(). The following example shows how these calls are used:
1. #define BUFFSIZE 8 The fgets() function is defined in C99 and has similar behavior to gets().The fgets() function accepts two additional arguments: the number of characters to read and an input stream. The gets_s() function is defined in ISO/IEC TR 24731 to provide a compatible version of gets() that was less prone to buffer overflow. The strcpy() function is on the list because, even though it can generally be used safely, it's often used in an insecure fashion, for example by dynamically allocating the required storage as shown below:
1. int main(int argc, char *argv[]) { There are also many, many alternatives to using strcpy() that are generally less error prone, including strcpy_s(), strlcpy() (available for many flavors of Unix but not GCC/Linux), strdup(), and others. Page 1 of 2 next page »
LATEST LINUX STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||