Safety certification for open-source systems
This year's Linaro Connect in Lisbon, Portugal featured a number of talks about the use of open-source components in safety-critical systems. Kate Stewart gave a keynote on the topic on the first day of the conference. In it, she highlighted several projects that have been working to pursue safety certification and spoke about the importance of being able to trace software's origins to safety. In a talk on the second day, Roberto Bagnara shared his experience with working on one of those projects, the Xen hypervisor, to conform to a formal set of rules for safety-critical code.
Automotive open source
Stewart is the owner of a 1996 Volvo car. Its air conditioning failed earlier this year, she explained, so with no replacement parts to be found and summer in Texas fast approaching, she recently bought a new car. Her original car is just hardware, she said, but now software is playing an increasingly important role in modern automobiles.
The difference is obvious just from comparing the dashboards: Stewart's
original Volvo has physical dials and knobs, but her new Honda has displays and
touchscreens. The obvious differences aren't what worry her, though. New cars
also have backup cameras, radar, assistive lane following, and many more
electronic features that have a real impact on the safety of the vehicle. A car
is, after all, "a couple of ton piece of equipment that could easily kill
someone
". All of
this new hardware needs to be powered by software β and a lot of that software
is open source.
So how can we ensure that a complicated system like a modern car is safe? Traditional supply chains for safety-critical systems have ensured this using "needs" that are fulfilled with "requirements", Stewart explained. A component is designed out of smaller components. Assuming that the smaller components meet some standard, the engineer designing the larger component is responsible for making that component safe. The assumptions that a larger component makes about its constituents are called needs; the standards that a smaller component meets are called requirements. Every need is matched with a requirement, to produce a graph of components where, at every step, it is clear exactly what is required for the overall system to be safe.
This doesn't really work for open source. 59% of the software in Stewart's new car is open source, she said, according to a disclosure by Honda. That's great, but those components may not be designed for use in safety-critical systems. Even if they are, they're exceedingly unlikely to have reliable documentation, certified by an engineer, that lays out their safety needs. That's not something that open source has really been designed to handle.
So how can these gaps be addressed? The first step, Stewart said, is just to know what components are actually going into a system. For physical hardware, this is usually called a bill of materials (BOM); a software bill of materials (SBOM) is similar. The SBOM lists the exact version of every dependency used by a piece of software.
Safety standards for software are mostly concerned with trying to "minimize
and mitigate systemic faults in the code base for an application
". In order
to do that, they need some way to track what the components in a system are,
what faults have been discovered with them, which bugs are known, and how all of
this changes over time. Today, "it's being done, quite frankly, with
spreadsheets
", which is "really inefficient
".
Since 2009, Stewart has been involved with the System Package Data Exchange (SPDX) project, which creates standardized formats and tools for exchanging and processing SBOM information. For version 3.0 of the SPDX format, she has been specifically working to include the information needed by someone trying to comply with a safety standard. In particular, SPDX 3.0 focuses less on a static document describing a particular component, and more on relationships between components. This allows SBOM tooling to capture all kinds of information about source code, build information, licensing, datasets, AI models, provenance, and everything else that goes into understanding what is part of a software system.
The next hurdle is actually persuading open-source projects to generate SBOM information. Stewart has been trying to make this as easy as possible with SPDX tooling, and many build systems can be configured to generate SBOMs with few changes. Still, like with any change in open source, it does require someone to actually do the work. Once a project has an SBOM, there is existing tooling, from the SPDX project and elsewhere, that can process the SBOM to produce various useful reports or track changes over time.
There are more potential next steps.
Several projects, especially in the embedded space, have
been working to be formally certified under various safety standards,
including
ELISA (where Stewart serves on the technical steering committee),
Zephyr,
Xen, and
Yocto.
But adopting SBOMs is a good place to start β and Stewart concluded her talk
with the hope that
"we'll get there soon.
"
MISRA compliance in Xen
MISRA, the motor industry software reliability association, is perhaps best known for its extensive set of rules on how to produce high quality software, the MISRA C guidelines. Bagnara is a member of the MISRA committee, and works with bugseng, a company that produces tools to help with MISRA compliance, among other things.
The biggest benefit of following MISRA's coding guidelines comes when a project enforces them from the beginning, Bagnara said, but that is often not possible. Especially when an open-source project is started and only later incorporated into a safety-critical system.
Open-source maintainers generally take pride in their software; many projects have existing standards for their code. The problem is that these existing standards rarely match up with what a functional-safety standard mandates. In many cases, artifacts showing that these standards have been followed β such as tests or documentation on requirements β are also missing. This is understandable, since open-source projects are largely driven by volunteers, only a subset of whom will care about safety qualification.
There are also more minor problems. For example, open-source software is often highly configurable, and any given project only cares about the safety of its specific configuration. Also, development of open-source software often moves much faster than traditional safety-critical software does, which makes keeping up to date difficult.
So, faced with this dilemma, with the obvious benefit and utility of open-source software on the one hand, and its attendant challenges on the other, what can be done? Well, we could give up on certifying the software itself, Bagnara said. For example, a project could instead qualify some kind of monitor or hypervisor that ensures the correct operation of the rest of the software. Better than that would be to fork the project. Everybody wants to avoid permanent forks, but a temporary fork is probably inevitable when working on a large change like safety qualification.
The most challenging and most rewarding approach, however, is "retrofitting
safety
", a topic that he has been
studying for some time.
Projects should create or adapt a coding standard after the fact, he said, and let the
subset of volunteers who care about such things do the work of getting the
existing code up to snuff.
That's what the Xen hypervisor project chose to do. As a hypervisor, Xen's safety underlies the safety of many other components in products that incorporate it. In order for Xen to be used in safety-critical systems, Bagnara has been working to bring Xen's existing coding guidelines in line with the MISRA C standard.
There are a lot of misconceptions about MISRA, Bagnara said. Although he is a member of the MISRA committee, he emphasized that his personal responses to these common misconceptions should not be understood as the official position of the committee. People frequently think that the MISRA rules are too strict, he said, to the detriment of actually making code that works. That's not the case; for MISRA, code quality always comes first. If a rule makes it harder to write quality code for some reason, there is a "deviation" process that lets the developer justify departing from the MISRA guidelines.
An example that came up while working on Xen was MISRA rule 10.1 ("Operands
shall not be of an inappropriate essential type
"). Among other
things, the rule disallows some implicit casts, which are a frequent source of
subtle errors in C programs. But there are implicit casts that are safe; in Xen,
this mostly appeared in the form of value-preserving conversions of integer
constants. Rather than pointlessly requiring all of these places in the code to
be marked with a manual cast, "rule 10.1 can be tailored by regarding those
instances as safe
", Bagnara explained, as long as there is a tool that can
be used to check the places where the implicit casts are used.
Another common complaint he sees is that MISRA rules mix too many
concerns under a single rule, and that this makes them complicated. "We have
more than 200 rules
", he explained. "We don't want 2,000 rules.
" So
each rule has to be fairly general, to cover all of the relevant cases.
The general nature of the rules is also a reason some projects will need to deviate from them. Xen uses a number of bit-twiddling tricks, as might be expected from low-level software. For example, there were four places in the Xen code base that used this trick, which contravenes a MISRA rule, without explanation:
variable &= -variable
This construction isolates the least-significant set bit of a value by using the fact that in the common two's complement representation of numbers, the least-significant set bit is the only one shared by both a number and its negation. Bagnara moved it into a macro with a meaningful name and an explanatory comment. That macro is covered by a global deviation that allows the project to use it wherever it is needed; the code is now easier to read for anyone who hasn't seen this particular construct before.
This kind of thing is generally needed in order for an upstream project to accept changes, he said. Maintainers don't want to accept lots of tiny changes in the name of MISRA compliance; they would much rather accept some documentation and additional tooling to justify and check the needed deviations from MISRA rules, instead.
In some cases, that did require making improvements to the proprietary static analyzer that Bagnara works on and with, ECLAIR. For existing high-quality code such as Xen, he said, someone working on MISRA compliance can expect to create more deviations than in a green-field project, because the code is likely to be correct already. Once those deviations have been accounted for and checked, however, the remaining problems highlighted by MISRA rules stand out even more. In the end, attempting to adopt MISRA for Xen did actually improve the code.
Today, Xen is "nearly 100% MISRA compliant
". As always, the last portion
of the work will be the hardest part. Bagnara is optimistic, however, that Xen
will soon be completely MISRA compliant, and that this will make its inclusion
in products with functional-safety requirements much easier.
[Thanks to Linaro for covering my travel expenses to Linaro Connect.]
Addendum: Video from Stewart's keynote and Bagnara's talk are now available. The slides can also be found on Linaro's website.
| Index entries for this article | |
|---|---|
| Conference | Linaro Connect/2025 |
