This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Hardening of firmware

Here is a link to a number of suggestions I have compiled for hardening of firmware.

I'm pretty sure that a lot can be said about the list, so please post coding tips or links to pages with good information of software hardening.

iapetus.neab.net/.../hardening.html

Parents
  • Hardening Code. Hmmm. This is where my Rule-book Against [Radical] Code-Monkeys comes into play. Its mine, and you can't have it...

    *   ----------------------------------------------------------------------
    *   WARNING - This document contains technical data whose export is
    *   restricted by the Arms Export Control Act (Title 22, U.S.C., Sec 2751
    *   et seq.) or  the Export Administration Act of 1979, as amended, Title
    *   50 U.S.C., App 2401 et seq. Violation of these export laws are subject
    *   to severe criminal penalties. Dissemination in accordance with
    *   provisions of DOD Directive 5230.25 (Reference C).
    *   ----------------------------------------------------------------------
    


    ... thus I can't give it to you anyway.

    Unfortunately, too many code monkeys think they're good software engineers because they also think they're good at doing the code-monkey work.

    Per, I know you know this stuff, but for those hobbyists out there, and embedded professionals who jump right in and code themselves up a mini-van (Delbert Reference there), coding is only a SMALL part of the hardening process.

    If a failure occurs the following list of things should be re-visited:

    The Application or Product Concept is wrong
    - Use Cases, Alternate Courses of Actions, Actors, Environment, pre and post conditions are in error.
    - The high level expectations were wrong

    The Translations were wrong
    - Ambiguities in the language or mis-interpretations occurred somewhere in the chain of design documents occurred
    - An incomplete set of information
    - Requirements fell through the cracks
    - Your UML or whatever modeling tool failed to capture the higher level needs

    The data-flows are wrong
    - Data elements: range, units, update-rates, saturation, overflows
    - Accessors/Mutators aren't vetted properly
    - Source & Sink errors
    - Model (UML) errors
    - Interrupt information handling
    - Semaphore/Task exchanges

    The "SRS" does not capture the expected behaviors
    - The SRS cross-checking and system requirements matrix is incomplete
    - SRS to sub-document links are broken: SDDs, etc

    The Algorithms are wrong
    - "Code Review" style failed to catch the error
    - "PC" simulations of the algorithms aren't right or were not translated into the proper format for the target application

    Coding Errors (that is YOU Mr. Code-Monkey)
    (this is where most 'software engineers' live and breath and don't do the above groundwork prior to 'hacking' the code together)

    - Language Stupidity errors (e.g. violation of the standards, etc)
    - Code does not comply with the requirements & algorithms
    - Stupid Errors (the typical "human errors" like misspelling, forgetting, etc)
    - [un] Clarity of code that leads to hiding artifacts
    - lack of experience (e.g. embedded techniques)
    


    (and this ends most of the hobbyist's and semi-pro engineering effort)

    Platform Errors
    - System Architecture (whole schematic, or just CPU, or both, or more) does not support the requirements expected (e.g. marginal memory space, insufficient MIPS, etc)
    - Code vs Platform misunderstandings on how it really works

    Component Specification Errors
    - Data-sheets are wrong
    - Data-sheets are misinterpreted
    - Vagueness in both data-sheets and your understanding of the component

    Tool-Chain Errors
    - IDE has errors in translation
    - Code-Monkey misapplied the Tool-Chain

    Configuration Management
    - Revision-itis
    - Stable Hardware-In-the-Loop (HIL): parts not swapped out with slightly different subsystems, etc.

    Test-Methods Errors
    - The chosen methods of testing did not capture the potential errors
    - Failed to account for X, Y, or Z requirements or conditions

    END OF Ad-Hoc LIST

    Much of this stuff is covered in a SQEM (Software Quality Engineering Manual) that your company had developed... typically as a result of Mil/Aero/FDA standards.

    In a lean company, the full-boat Mil/Aero/FDA standards takes too much time and resources, so a slimmed down SQEM that captures the intent of the Mil/Aero/FDA standards is used. These SQEMs are usually reviewed by the contracting party for compliance, and are stamped as "Acceptable" or not.

    After you do all of the up-front [paper] work, you will find that the Code-Monkey stage is actually very trivial and very easy.

    The process is very iterative, so Mr. CodeMonkey must not only understand the documents, detect any problems, but also up-flow any deviations as required.

    IF I MIGHT SUGGEST...
    If you haven't done a *real* embedded system with the full SQEM documentation, I think you should do it on a small project. Do something simple like your own version of Blinky. It would be good for you to fully spec the system before grabbing the bowl of plantains and banging on the keyboard.

    Per,
    (BTW 404 on that link---but over the weekend I saw that the link worked, but didn't have the time to read it)

    So when you speak of code "hardening" I think you mean the methods used during the Code-Monkey stages. And there is plenty out there to do in that respect.

    The best piece of advice I can quickly offer is to think about what your code is doing, and be as CLEAR as possible when doing it... lots of white-space, lots of comments, lots of attention to detail.

    Look into how your tool-chain is generating the code. We/I used the 0 vs 1 TRUE vs FALSE example of avoiding the 1-bit away from the other state. Your CPU will have instructions that depend upon single-bit states (I can't think of any reason to expect otherwise), but you have the ability to generate code that doesn't use the "JB Label" and uses the "CNJE R0,#A5,Label" instead... (but optimization may wipe that out). Either way, you need to look into what gets generated, and how/why it occurs that way, then figure out if it is solid for your needs. Sacrificing CPU/MIPS for the sake of safety is a good trade.

    Good code-monkeys know whats going on, and the best 'hardening' at the code-monkey stage is based upon this knowledge.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Reply
  • Hardening Code. Hmmm. This is where my Rule-book Against [Radical] Code-Monkeys comes into play. Its mine, and you can't have it...

    *   ----------------------------------------------------------------------
    *   WARNING - This document contains technical data whose export is
    *   restricted by the Arms Export Control Act (Title 22, U.S.C., Sec 2751
    *   et seq.) or  the Export Administration Act of 1979, as amended, Title
    *   50 U.S.C., App 2401 et seq. Violation of these export laws are subject
    *   to severe criminal penalties. Dissemination in accordance with
    *   provisions of DOD Directive 5230.25 (Reference C).
    *   ----------------------------------------------------------------------
    


    ... thus I can't give it to you anyway.

    Unfortunately, too many code monkeys think they're good software engineers because they also think they're good at doing the code-monkey work.

    Per, I know you know this stuff, but for those hobbyists out there, and embedded professionals who jump right in and code themselves up a mini-van (Delbert Reference there), coding is only a SMALL part of the hardening process.

    If a failure occurs the following list of things should be re-visited:

    The Application or Product Concept is wrong
    - Use Cases, Alternate Courses of Actions, Actors, Environment, pre and post conditions are in error.
    - The high level expectations were wrong

    The Translations were wrong
    - Ambiguities in the language or mis-interpretations occurred somewhere in the chain of design documents occurred
    - An incomplete set of information
    - Requirements fell through the cracks
    - Your UML or whatever modeling tool failed to capture the higher level needs

    The data-flows are wrong
    - Data elements: range, units, update-rates, saturation, overflows
    - Accessors/Mutators aren't vetted properly
    - Source & Sink errors
    - Model (UML) errors
    - Interrupt information handling
    - Semaphore/Task exchanges

    The "SRS" does not capture the expected behaviors
    - The SRS cross-checking and system requirements matrix is incomplete
    - SRS to sub-document links are broken: SDDs, etc

    The Algorithms are wrong
    - "Code Review" style failed to catch the error
    - "PC" simulations of the algorithms aren't right or were not translated into the proper format for the target application

    Coding Errors (that is YOU Mr. Code-Monkey)
    (this is where most 'software engineers' live and breath and don't do the above groundwork prior to 'hacking' the code together)

    - Language Stupidity errors (e.g. violation of the standards, etc)
    - Code does not comply with the requirements & algorithms
    - Stupid Errors (the typical "human errors" like misspelling, forgetting, etc)
    - [un] Clarity of code that leads to hiding artifacts
    - lack of experience (e.g. embedded techniques)
    


    (and this ends most of the hobbyist's and semi-pro engineering effort)

    Platform Errors
    - System Architecture (whole schematic, or just CPU, or both, or more) does not support the requirements expected (e.g. marginal memory space, insufficient MIPS, etc)
    - Code vs Platform misunderstandings on how it really works

    Component Specification Errors
    - Data-sheets are wrong
    - Data-sheets are misinterpreted
    - Vagueness in both data-sheets and your understanding of the component

    Tool-Chain Errors
    - IDE has errors in translation
    - Code-Monkey misapplied the Tool-Chain

    Configuration Management
    - Revision-itis
    - Stable Hardware-In-the-Loop (HIL): parts not swapped out with slightly different subsystems, etc.

    Test-Methods Errors
    - The chosen methods of testing did not capture the potential errors
    - Failed to account for X, Y, or Z requirements or conditions

    END OF Ad-Hoc LIST

    Much of this stuff is covered in a SQEM (Software Quality Engineering Manual) that your company had developed... typically as a result of Mil/Aero/FDA standards.

    In a lean company, the full-boat Mil/Aero/FDA standards takes too much time and resources, so a slimmed down SQEM that captures the intent of the Mil/Aero/FDA standards is used. These SQEMs are usually reviewed by the contracting party for compliance, and are stamped as "Acceptable" or not.

    After you do all of the up-front [paper] work, you will find that the Code-Monkey stage is actually very trivial and very easy.

    The process is very iterative, so Mr. CodeMonkey must not only understand the documents, detect any problems, but also up-flow any deviations as required.

    IF I MIGHT SUGGEST...
    If you haven't done a *real* embedded system with the full SQEM documentation, I think you should do it on a small project. Do something simple like your own version of Blinky. It would be good for you to fully spec the system before grabbing the bowl of plantains and banging on the keyboard.

    Per,
    (BTW 404 on that link---but over the weekend I saw that the link worked, but didn't have the time to read it)

    So when you speak of code "hardening" I think you mean the methods used during the Code-Monkey stages. And there is plenty out there to do in that respect.

    The best piece of advice I can quickly offer is to think about what your code is doing, and be as CLEAR as possible when doing it... lots of white-space, lots of comments, lots of attention to detail.

    Look into how your tool-chain is generating the code. We/I used the 0 vs 1 TRUE vs FALSE example of avoiding the 1-bit away from the other state. Your CPU will have instructions that depend upon single-bit states (I can't think of any reason to expect otherwise), but you have the ability to generate code that doesn't use the "JB Label" and uses the "CNJE R0,#A5,Label" instead... (but optimization may wipe that out). Either way, you need to look into what gets generated, and how/why it occurs that way, then figure out if it is solid for your needs. Sacrificing CPU/MIPS for the sake of safety is a good trade.

    Good code-monkeys know whats going on, and the best 'hardening' at the code-monkey stage is based upon this knowledge.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Children