what is cert c? – a secure coding standard for embedded software -凯发k8网页登录

a secure coding standard for embedded software

the cert® c and cert c coding standards are secure coding practices for the c and c languages. security vulnerabilities in embedded software increase chances of attacks from malicious actors. these attacks inject malware, steal information, or perform other unauthorized tasks. secure coding practices plug these vulnerabilities and effectively reduce the surface of attack.

why is cert c important for embedded systems?

embedded systems use handwritten or generated code in programming languages such as c. although this language allows low-level operations such as direct memory access, the associated security risks are also higher. if an attacker gains control of a system, the consequences can be catastrophic.

certain code constructs in the c language introduce security vulnerabilities. malicious actors can exploit these vulnerabilities and perform operations such as code injection, buffer overflow, and arc injection.

for example, take this very simple case:

#define size100 100
extern int tab[size100];
int lookup(int n, int aflag) 
{
    if(!aflag &&  n < size100)
      return tab[n];    
    else 
      return -1;
}

the lookup function has an obvious vulnerability to a buffer overflow since the parameter n is not checked for negative values before use as array index. negative values can cause an out-of-bounds array index, expose restricted information, or allow modification of the contents of a restricted memory location. the buffer overflow can also risk introduction of malicious code that changes the course of execution and adversely affects the functional safety of the system.

cert c rules and recommendations help reduce such risks by eliminating certain vulnerable code constructs from embedded software. cert c is especially focused on secure coding in the c language, but organizations also use , , , and other standards, or develop their own standards for secure coding. the cert c standard was developed following a community-based development process managed by the software engineering institute (sei) affiliated with carnegie mellon university. the cert c guidelines are available on the . a similar standard, cert c , was developed for the c language.

how do i ensure compliance with cert c?

cert c guidelines are written in the form of rules and recommendations. a guideline is labeled as a:

  • rule if a violation is most likely to cause a defect and if conformance can be established through automatic or manual inspection of the code alone without requiring additional assumptions. for instance, (“do not form or use out-of-bounds pointers or array subscripts”) is a rule.
  • recommendation if conformance improves the safety and security of software systems but a violation does not necessarily result in a defect. for instance, (“explicitly specify array bounds, even if implicitly defined by an initializer”) is a recommendation.

the cert c rules can be checked manually, but looking at hundreds of thousands, sometimes millions, of lines of code for rule violations is often not practical. therefore, cert c recommends use of static code analysis tools to ensure compliance.

typically, a static code analysis tool checks for security-related defects, such as tainted data, along with underlying software weaknesses, such as static and dynamic memory defects, numerical defects, and data flow defects. many of these defects come from violations of cert c rules. static analysis tools can thus automatically check for cert c rule violations.

checking cert c compliance with polyspace® static code analysis tools

polyspace bug finder™ is a static code analysis tool that supports the cert c secure coding standard out of the box. using polyspace bug finder, a developer or quality engineer can simply choose to check all or select cert c rules and find violations without performing any additional configuration.

for instance, in the code snippet shown earlier, polyspace bug finder finds a violation of cert c rule arr30-c (“do not form or use out-of-bounds pointers or array subscripts”) by detecting the array access out-of-bounds or buffer overflow defect. this violation is reported with rule information, location in code, and possible risks and fixes.

detecting cert c violations using polyspace bug finder.

in addition to supporting almost all cert c rules and many cert c recommendations, polyspace bug finder also supports related coding standards such as cwe, iso/iec ts 17961, misra c:2012 amendment 1, and a significant portion of the cert c coding standard.

with polyspace code prover™, an additional layer of checking is available. when polyspace bug finder reports a violation, you could run polyspace code prover to exhaustively check for the absence of other such violations in the software. for example, suppose you fix the previous violation by checking the array index for negative values like this:

#define size100 100
extern int tab[size100];
int lookup(int n, int aflag) 
{
    if(aflag &&  (n<0 || n >= size100))
      return -1;
    return tab[n];
}

did that fix the issue? you can run polyspace bug finder and see that rule arr30-c is still violated. to get further insight, you can run polyspace code prover. with the deeper analysis, you see that depending on the value of aflag, the value of n might not be constrained at all and there is still the possibility of the out-of-bounds array index. you can then rework the code until polyspace code prover proves the absence of the out-of-bounds index, as indicated by a green check mark.

out-of-bounds array index checking using polyspace code prover.

in summary, you can automate checking of almost all cert c rules and a significant number of cert c recommendations with polyspace bug finder. you can gain further insight into issues with polyspace code prover and, for specific rules, exhaustively check your code and prove the absence of those issues.

to learn more about the embedded security capabilities of polyspace products.


software reference

  • - documentation

see also: static analysis, verification, embedded systems, software quality objectives, software qa

网站地图