Try Embedded

Safety and security standards

IEC 61508, ISO 26262, IEC 62304, DO-178C and MISRA C.

Why standards exist

When software can kill someone (a car's brakes, an insulin pump, a flight control computer, a factory robot) "we tested it" is not enough. Functional safety standards define processes that make it demonstrably unlikely that the system fails dangerously: how requirements are written and traced, how the design is analysed for hazards, how code is written and verified, and what evidence must exist. Security standards do the same for deliberate attacks. Products in regulated markets must comply, and auditors check the evidence.

The main functional safety standards

StandardDomainIntegrity levels
IEC 61508Generic: electrical, electronic and programmable safety systems; the parent of the othersSIL 1 to SIL 4
ISO 26262Road vehiclesASIL A to ASIL D (plus QM: not safety relevant)
IEC 62304Medical device softwareClass A, B, C
DO-178CAirborne softwareDAL E (no effect) to DAL A (catastrophic)
EN 50128 / EN 50716Railway softwareSIL 0 to SIL 4
IEC 61511, IEC 62061, ISO 13849Process industry, machinerySIL / PL a to e

The integrity level is set by a hazard and risk analysis: how severe the harm, how often people are exposed, and whether they can avoid it. Higher levels demand more rigorous methods: stricter coding rules, more independent review, more test coverage (up to MC/DC), formal methods recommended at the top levels.

What they require, in practice

  • Requirements traceability: every safety requirement traced down to design, code and tests, and back. Every line of code exists because of a requirement.
  • A defined life cycle: planning, requirements, architecture, design, implementation, verification, validation, with reviews and documented outputs at each step.
  • Hazard analysis: FMEA (failure modes and effects), FTA (fault tree analysis), HAZOP.
  • Safety mechanisms in the design (see safety mechanisms): watchdogs, memory protection, plausibility checks, redundancy.
  • Verification proportional to the level: reviews, static analysis, unit and integration testing with structural coverage targets.
  • Tool qualification: confidence that the compiler, static analyser and test tools do not introduce or hide errors.
  • Configuration and change management: every change analysed for safety impact.

IEC 62304 specifics

Medical software is classified by the harm a failure could cause: Class A (no injury possible), B (non-serious injury), C (death or serious injury). Requirements scale with the class; Class C demands detailed design and unit verification. It works with ISO 14971 (risk management) and, for the overall device, IEC 60601. Third-party software (an RTOS, a library) is "SOUP" (software of unknown provenance) and must be identified, its risks assessed and its anomalies tracked.

DO-178C specifics

Avionics software is assigned a Design Assurance Level from the failure condition's severity. Level A requires MC/DC coverage of the code, independence of verification, and full traceability to object code where the compiler could introduce untraceable code. Supplements cover model-based development (DO-331), object-oriented techniques (DO-332), formal methods (DO-333), and tool qualification (DO-330).

MISRA C

MISRA C is a set of guidelines for a safer subset of C, used far beyond automotive: medical, industrial, aerospace and any team wanting fewer bugs. The current edition is MISRA C:2023 (consolidating MISRA C:2012 and its amendments).

Guidelines are classified Mandatory, Required or Advisory; required ones can be deviated from only with a documented, approved justification. Examples of what the rules target:

TopicGuidance (paraphrased)
Undefined and unspecified behaviourAvoid it; no reliance on evaluation order with side effects
TypesUse fixed-width types; no implicit conversions that lose information or change signedness (the "essential type" model)
Control flowNo unreachable code; every switch has a default; limited goto
PointersNo arithmetic outside arrays; restrictions on casts between pointer types
MemoryNo dynamic heap allocation (malloc, free)
PreprocessorParenthesise macro parameters; prefer functions to function-like macros
Standard libraryAvoid setjmp/longjmp, <stdio.h> input functions, and other unsafe facilities
RecursionAvoided, because stack usage must be bounded
#include <stdio.h>
#include <stdint.h>

/* A few habits MISRA-style rules encourage, in one function. */
static uint16_t scale_reading(uint16_t raw, uint16_t gain_percent) {
  uint32_t wide = (uint32_t)raw * (uint32_t)gain_percent;   /* widen before multiplying: no overflow */
  uint32_t result = wide / 100U;                             /* unsigned constant with U suffix */
  if (result > 0xFFFFU) {
    result = 0xFFFFU;                                        /* explicit saturation, no silent truncation */
  }
  return (uint16_t)result;                                   /* explicit narrowing cast */
}

int main(void) {
  printf("%u\n", (unsigned)scale_reading(1000U, 150U));
  printf("%u\n", (unsigned)scale_reading(60000U, 200U));
  return 0;
}

Related: CERT C (secure coding rules focused on security vulnerabilities), AUTOSAR C++14 and MISRA C++:2023 for C++.

Security standards

Safety standards assume random failures and mistakes; security assumes an intelligent attacker. Relevant ones:

StandardScope
ISO/SAE 21434Automotive cybersecurity engineering; UNECE R155/R156 make cybersecurity and software-update management mandatory for vehicle type approval
IEC 62443Industrial automation and control systems; security levels SL 1 to 4, requirements for components and processes
ETSI EN 303 645Consumer IoT baseline: no default passwords, vulnerability disclosure, software updates, secure storage of credentials
EU Cyber Resilience ActLegal cybersecurity requirements for products with digital elements sold in the EU, phasing in through 2027
FDA premarket cybersecurity guidanceMedical devices in the US: threat modelling, SBOM, update plans
NIST IR 8259, PSA Certified, SESIPIoT device security baselines and certification schemes

Common threads: threat modelling, secure boot and updates, no default credentials, a software bill of materials (SBOM), vulnerability handling, and support for security updates over the product's life.

Note: Following a standard's process from the start is far cheaper than retrofitting evidence at the end. If a product might enter a regulated market, establish traceability, coding rules and reviews on day one.

Interview question: Why does MISRA C forbid dynamic memory allocation?

Answer: Heap allocation has failure modes that are hard to bound or verify: allocation can fail at run time when memory is exhausted or fragmented, execution time of malloc and free is not deterministic, and misuse (leaks, double free, use after free) causes undefined behaviour. Safety-related software must have predictable memory use and timing, so memory is allocated statically or from fixed-size pools at start-up, making worst-case usage analysable.

Interview question: What does it mean that safety standards require traceability?

Answer: Each safety requirement must be linked to the architecture and design elements that implement it, to the code, and to the tests that verify it, and every design element and piece of code must trace back to a requirement. This proves that all requirements are implemented and verified, that no untested or unjustified functionality exists, and allows impact analysis when something changes. It is usually maintained with requirement-management tools and checked during audits.

Build it: classify the parking brake's hazards

This is step 1 of the module project, an electronic parking brake: the ECU behind the button that replaced the handbrake lever, driving a motor on each rear caliper. Under ISO 26262, the work starts with a hazard analysis that gives each hazard an ASIL, and every later requirement, test and review is as strict as that ASIL demands. The team keeps the hazard list in a file and has a tool compute the ASILs, so nobody reads the table wrongly; the tool is safety-relevant itself, so it is written to MISRA C.

Lab: ASIL from severity, exposure and controllability

Each hazard is rated for severity S0 to S3, exposure E0 to E4 and controllability C0 to C3. The ISO 26262 table can be read as a sum:

  • if any of the three is 0, the hazard is QM (no ASIL: ordinary quality management is enough);
  • otherwise S + E + C of 10 is ASIL D, 9 is C, 8 is B, 7 is A, and 6 or less is QM.

asil_of(s, e, c) returns QM to ASIL_D, or -1 for a rating outside its range. goal_asil(h, n) returns the ASIL of a safety goal that covers hazards h[0] to h[n-1]: the highest of theirs, or -1 if any rating is invalid.

The code must follow the MISRA C rules listed above: conditions must be truly Boolean (if (x != 0), not if (x)), every if, else and loop body goes in braces, and every switch ends each case with break and has a default.

Going deeper

Interview question: How does a safety standard such as IEC 62304 or ISO 26262 change how you write firmware?

Answer: It sets a process: requirements derived from a hazard analysis, an architecture that separates safety functions, coding standards and static analysis, verification with defined coverage, and traceability from each requirement to code and tests, all documented. The safety level decides how rigorous each step must be, and changes go through the same process.

Interview question: What is a software bill of materials and why is it increasingly required?

Answer: An SBOM lists every software component in a product, including open-source libraries, with versions and licences, in a standard format such as SPDX or CycloneDX. It lets manufacturers and customers find which products are affected when a vulnerability is published and track licence obligations. Regulations such as the EU Cyber Resilience Act and US FDA guidance for medical devices expect one.

Interview question: What does tool qualification mean in functional safety?

Answer: Gaining confidence that development and verification tools, such as compilers, static analysers and test tools, do not introduce errors into the product or fail to detect errors, to a degree proportional to the safety level and the tool's impact. Methods include using pre-qualified tools with certification kits, validation testing, and verifying the tool's output independently.

Explain it: In your own words, explain why safety standards focus on processes rather than just testing the final product.

Answer: Testing can show the presence of bugs but never prove their absence, especially in complex software with countless possible states and inputs. Safety standards therefore require a disciplined development process that makes dangerous failures unlikely and leaves evidence: analysing hazards up front, deriving requirements from them, tracing every requirement through design, code and tests, following coding rules, reviewing work independently and measuring test coverage. The rigour scales with the integrity level, so the more harm a failure could cause, the more evidence is required.