Security-oriented coding standards

Andrea Gillhuber,

In the jungle of security coding standards

The search for security-oriented coding standards for the industry is not that easy. Here's how to keep track.

© Shutterstock / Wright Studio

When searching for security-oriented coding standards, you come across various sources - from the CERT Coding Standards, OWASP and CWE to a variety of different recommendations and best practices. In addition, there are numerous subject-specific standards such as MISRA, AUTOSAR and a whole family of standards based on the IEC 61508 standard. Dealing with this flood of information is a real challenge, as is finding out which coding standards are best suited to the project at hand. It is even worse when existing software in the software development lifecycle has to be adapted to comply with one of these standards.

From CVE to the CWE Top 25

In 1999, the MITRE Corporation (a US non-profit organization that operates research and development centers sponsored by the US government) began documenting known software vulnerabilities in the CVE (Common Vulnerabilities and Exposures) list. This list quickly grew from an initial 321 entries to over 100,000 entries in September 2018; it is maintained by 92 CVE Numbering Authorities (CNAs, see Glossary box). The CVE list is widely used and is recommended by many organizations (including NIST, DISA).

As the CVE list grew, it became necessary to categorize its entries into groups according to problem type in order to better understand the causes of most common problems and take appropriate measures to prevent similar problems in the future. So MITRE started categorizing the known issues in the PLOVER document (Preliminary List of Vulnerability Examples for Researchers). Combining this work with other research resulted in the CWE (Common Weakness Enumeration) list, a formal listing of the different types of software vulnerabilities.

Advertisement

In the current version 3.1, the CWE list comprises around 700 types of vulnerabilities, divided into 250 categories and views. In order not to lose track despite the high number, the CWE, together with the SANS Institute, maintains a list of the 25 most dangerous software errors, i.e. the most widespread and critical errors that can lead to serious vulnerabilities in software. This "Top 25" list is headed by:

1. CWE-89: Incorrect neutralization of special elements used in an SQL command (SQL injection)

2. CWE-78: Incorrect neutralization of special elements used in an operating system command (OS Command Injection)

3. CWE-120: Copying to the buffer without checking the size of the input value (the classic buffer overflow)

Standards for functional safety

To ensure the functional safety of electrical, electronic and programmable electronic safety-relevant systems, the IEC 61508 standard was developed for all areas of application. It covers all aspects of a computer system, its Part 3 (Software Requirements) deals specifically with the software part of the system and contains a large number of requirements for all phases of the software development life cycle. IEC 61508-3, Table A.9 (Software Verification) contains a list of techniques recommended for software verification, including the explicit and urgent recommendation of static analysis for the higher SILs.

While IEC 61508 is a universal standard that is used in a wide variety of industries, there are also standards that are geared towards specific areas of application, such as:

  • Aviation: DO-178C / ED-12C
  • Automotive: ISO 26262
  • Railroad: IEC 62279 / EN 50128
  • Nuclear power plants: IEC 61513

Even if they address the specific characteristics of a particular area, they are similar in their basic idea - at least from a software perspective: they all require the application of static analysis to the developed code, alongside other verification techniques. They also provide general guidelines regarding the measures to be taken, but at the same time leave a wide scope for interpretation. They do not normally specify any particular coding conventions or coding standards to be applied, only ISO 26262 mentions MISRA C as an example of a coding guideline for the C programming language.

Secure coding standards (security)

The table "Designs and Coding Standards of IEC 61508-3" lists software design techniques that are recommended (Recommended - R) or strongly recommended (Highly Recommended - HR) for certain SILs. © Parasoft

Writing secure code means that the written code is not vulnerable, i.e. it does not have any potentially exploitable vulnerabilities or security gaps. In addition, the written code must have certain secure patterns (in the sense of "safe") and avoid insecure patterns. These patterns differ from one programming language to another. There is no set of "golden rules" that, if followed, guarantee the security of the software. Some widely used coding standards take the safety aspect into account:

  • For the C language: MISRA C and SEI CERT C coding standard,
  • For the C++ language: MISRA C++ and JSF AV C++ coding standards, SEI CERT C++ coding standard, AUTOSAR C++ coding guidelines (see glossary at the end of the article).

Proven procedures

When it comes to securing the code, it is important to make the right choice. If the software must be certified according to a specific functional safety standard (e.g. ISO 26262 for automotive or DO-178C for aviation applications), the first decision has already been made. Regardless of this, however, a decision must be made on the coding standard(s) or subset of the standard that the developed software must comply with. This can (but does not have to) be one of the standards mentioned above.

The next step is to select a suitable static analysis tool because it is not possible to verify compliance with all these rules manually. Both open source and commercial static analysis tools are available. Here are some selection criteria:

  • Is the selected coding standard(s) fully or partially supported by the tool?
  • If the functional safety standard in question requires tool qualification, ask if the tool is certified and if it provides the qualification kit?
  • Can the tool provide the analysis reports in the form required for the conformity analysis?
  • Can it generate the analysis reports in a form that is easy for developers to read?
  • Does the tool integrate smoothly with the IDEs, build and CI systems used?
  • Does it allow selective analysis of new, changed or existing code?
  • Does the tool support flexible configuration of the analysis?
  • Does the tool use risk scoring algorithms to help prioritize the defects found?

In addition, the CWE community runs the CWE Compatibility and Effectiveness Program, a formal testing and evaluation process for a product or service. The list of products and services that are classified as "Officially CWE-Compatible" currently comprises 55 entries. If the selected tool is on this list, this ensures that it has reached the final stage of the MITRE organization's formal CWE Compatibility Program.

Once you have defined the coding standard and the necessary tools, the rest of the work for software projects started from scratch should be easy: Just integrate the tool into the CI system and make sure that no defect is left unconsidered.

The individual standards sometimes contain a large number of rules. To facilitate an overview, the rules in the standards are normally divided into several categories. © Parasoft

As a rule, however, coding standards must also be enforced for software that is already under development. Then blindly running the analysis with the entire code base can lead to hundreds of defect messages that are difficult to handle in their entirety. Fortunately, the market offers several techniques to simplify this process.

It is advisable to concentrate on the newly written or modified code first. This prevents new defects from arising after the coding standard has been set up. Another tried and tested procedure is to classify the reported defects according to their importance, so that the most serious defects are processed first.

There is a risk assessment for the CERT-C and CERT-C++ rules, which enables a simple prioritization of the errors found. © Parasoft

A prioritized list of defects in combination with the configurable list of rules to be enforced is helpful to focus on the rules with the highest severity first and expand the number of rules after the most serious defects have been fixed.

The best static analysis reports are useless if the developers do not use them to fix the code. That is why it is most important to ensure that the development team follows up the analysis with appropriate measures - as a prerequisite for better software in terms of safety and security.

Michal Rozenau, Project Lead Engineer at Parasoft / ag

Literature

[1] Hicken Arthur, Parasoft, Embedded Cybersecurity Through Secure Coding Standards CWE and CERT

  1. MITRE Corporation, Common Vulnerabilities and Exposures (CVE)
  2. MITRE Corporation, Common Weakness Enumeration (CWE)
  3. IEC, IEC 61508-3:2010 Functional safety of electrical/electronic/programmable electronic safety-related systems - Part 3: Software requirements
  4. ISO, ISO 26262-6:2011(en) Road vehicles - Functional safety - Part 6: Product development at the software level
  5. Carnegie Mellon University, SEI CERT C Coding Standard
  6. Carnegie Mellon University, SEI CERT C++ Coding Standard

Glossary:

CVE Numbering Authorities (CNAs) are various organizations (including vulnerability researchers, product vendors, and bug bounty programs that offer a bounty for the discovery of bugs) around the world that have the authority to assign CVE IDs to identified issues.

MISRA C and MISRA C++ were developed by the MISRA (Motor Industry Software Reliability Association), while the AUTOSAR C++ coding guidelines were developed by the AUTOSAR (AUTomotive Open System ARchitecture) development partnership. Lockheed Martin Corporation is responsible for the development of the JSF AV C++ coding standard. The SEI CERT C and C++ coding standards contain general rules designed to ensure the safety, reliability and security of software systems developed in the C and C++ programming languages.

  • Xing Icon
  • LinkedIn Icon
Advertisement
Advertisement

You might also be interested in

Advertisement

Display

Protection against electrostatic discharge

StoFloor ESD KU 614 from StoCretec: dissipative flooring with the latest technology meets all ESD standards, is economical, extremely durable, mechanically and chemically resistant. The surface can be adjusted to be slip-resistant. The system is...

read more...
Advertisement
Advertisement
Advertisement
Advertisement
Advertisement
Advertisement
Subscribe to our newsletter
Advertisement
Back to home