Skip to content

Secure PLC coding

The Top 20 Secure PLC Coding Practices. Part 5 - Use PLC flags as integrity checks

If the PLC code was working fine but suddenly does a divide by zero, investigate. If something is communicating peer to peer from another PLC and the function/logic does a divide b

Eugen WypiorEugen Wypior

Published 4 min read

PLCsecure codingOT securityIEC 62443ICS
Contents
  1. **Put counters on PLC error flags to capture any math problems **
  2. Guidance
  3. Example
  4. Why?
  5. References
  6. What’s next?
  7. Do you require help with secure coding of your PLCs?
  8. If you have any questions or require help in securely coding your PLCs, please contact SEQRED. SEQRED specialises in providing bespoke OT and IoT cybersecurity solutions. Our services cover such areas as Critical Infrastructure Protection, Cloud Services Security or Audits, and Threat Intelligence. For a full list of our services visit our services page – https://seqred.pl/en/services/
  9. About this article

Part 5 of the Top 20 Secure PLC Coding Practices series, originally published by admeritia GmbH (Langenfeld, Germany). SEQRED reproduces the series under the open license granted by the copyright holder. Full specification: plc-security.com.

**Put counters on PLC error flags to capture any math problems **

Security Objective Target Group
Integrity of PLC Logic Product Supplier
Integration /
Maintenance Service Provider

Guidance

If the PLC code was working fine but suddenly does a divide by zero, investigate. If something is communicating peer to peer from another PLC and the function/logic does a divide by zero when it wasn’t expected, investigate.

Most programmers will ignore the issue as a math error or worse yet, might presume their code is perfect and let the PLC enter a hard fault state. During code development, engineers need to test and validate their code modules (snippets or routines) by inputting data outside of expected bounds. This may be termed Unit Level Test.

Assign different, locked memory segments for firmware, logic, and protocol stack. Test the protocol stack for abuse cases. Abuse cases could be peculiar flag conditions in a packet header.

Example

PLC faults caused by out-of-bounds data are very common. This happens, for example, when an input value causes array indices go out of bounds, or timers with negative presets, or divide by zero exceptions.

Typical flags of interest are

  • divide by zero
  • counter overflow
  • negative counter or timer preset
  • I/O scan overrun

Why?

Beneficial for …? Why?
Security Attacks on PLCs could include changing its logic, activating a new program, testing new code, loading a new process recipe, inserting auxiliary logic to send messages, or activating some feature. Since most PLCs do not provide cryptographic integrity checks, flags can be a good indicator if one of the above logic changes happens.
**Reliability ** Flags taken seriously can avoid the PLC running with programming or I/O errors. Also, if an error occurs, the source of the failure is more obvious.
**Maintenance ** /

References

Standard / framework Mapping
**MITRE ATT &CK for ICS ** Tactic:TA010 - Impair Process Control Technique:T0836 - Modify Parameter
**ISA 62443-3-3 ** SR 3.5 : Input Validation****SR 3.6 : Deterministic Output
**ISA 62443-4-2 ** CR 3.5 : Input Validation CR 3.6 : Deterministic Output
**ISA 62443-4-1 ** SI-2: Secure coding standards SVV-1 : Security requirements testing
**MITRE CWE ** CWE-128: Wrap-around CWE-190: Integer Overflow CWE-369: Divide by Zero CWE-754: Improper Check for Unusual or Exceptional Conditions

What’s next?

In the next article of The Top 20 Secure PLC Coding Practices series, you will find out about using cryptographic and/or checksum integrity checks for PLC code.

Do you require help with secure coding of your PLCs?

If you have any questions or require help in securely coding your PLCs, please contact SEQRED. SEQRED specialises in providing bespoke OT and IoT cybersecurity solutions. Our services cover such areas as Critical Infrastructure Protection, Cloud Services Security or Audits, and Threat Intelligence. For a full list of our services visit our services page – https://seqred.pl/en/services/

About this article

This article is reproduced from the Top 20 Secure PLC Coding Practices project coordinated by Sarah Fluchs (admeritia GmbH) and Vivek Ponnada (Nozomi Networks), with support from ISA Global Cybersecurity Alliance and S4 Events.

The full copy of the document is available at plc-security.com.

License

Copyright (c) 2021 admeritia GmbH, Langenfeld/Rheinland, Germany.

Permission is hereby granted, free of charge, to any person obtaining a copy of “Top 20 Secure PLC Coding Practices” and associated documentation files, to deal in the work without restriction, including the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies, subject to preserving this copyright notice.

The work is provided “as is”, without warranty of any kind. Full license at plc-security.com.

See also

  • SEQRED’s synthesis article: Top 20 Secure PLC Coding Practices - a condensed guide
  • Full series: browse all 21 parts under the secure coding tag

Need help in this area?

Our experts will help you assess the risk and plan next steps.

Talk to an expert

We'll discuss scope, methodology, and timeline.

Book a call