Inst ToolsInst ToolsInst Tools
  • Courses
  • Automation
    • PLC
    • Control System
    • Safety System
    • Communication
    • Fire & Gas System
  • Instrumentation
    • Design
    • Pressure
    • Temperature
    • Flow
    • Level
    • Vibration
    • Analyzer
    • Control Valve
    • Switch
    • Calibration
    • Erection & Commissioning
  • Interview
    • Instrumentation
    • Electrical
    • Electronics
    • Practical
  • Q&A
    • Instrumentation
    • Control System
    • Electrical
    • Electronics
    • Analog Electronics
    • Digital Electronics
    • Power Electronics
    • Microprocessor
  • Request
Search
  • Books
  • Software
  • Projects
  • Process
  • Tools
  • Basics
  • Formula
  • Power Plant
  • Root Cause Analysis
  • Electrical Basics
  • Animation
  • Standards
  • 4-20 mA Course
  • Siemens PLC Course
Reading: #9 PLC Best Practices – Validate indirections
Share
Notification Show More
Font ResizerAa
Inst ToolsInst Tools
Font ResizerAa
  • Courses
  • Design
  • PLC
  • Interview
  • Control System
Search
  • Courses
  • Automation
    • PLC
    • Control System
    • Safety System
    • Communication
    • Fire & Gas System
  • Instrumentation
    • Design
    • Pressure
    • Temperature
    • Flow
    • Level
    • Vibration
    • Analyzer
    • Control Valve
    • Switch
    • Calibration
    • Erection & Commissioning
  • Interview
    • Instrumentation
    • Electrical
    • Electronics
    • Practical
  • Q&A
    • Instrumentation
    • Control System
    • Electrical
    • Electronics
    • Analog Electronics
    • Digital Electronics
    • Power Electronics
    • Microprocessor
  • Request
Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Inst Tools > Blog > PLC Tutorials > #9 PLC Best Practices – Validate indirections

#9 PLC Best Practices – Validate indirections

PLC best practices - Validate indirections by poisoning array ends to catch fence-post errors.

Last updated: September 21, 2021 4:49 pm
Editorial Staff
PLC Tutorials
No Comments
Share
7 Min Read
SHARE

PLC best practices – Validate indirections by poisoning array ends to catch fence-post errors.

Contents
PLC Validate indirectionsInstruction List (IL) Programming1. Create array mask2. Insert poisoned ends3. Record value of indirection address without a mask4. Execute AND mask and compare values (=indirection validation)5. Execute fault/programmer alert
Security ObjectiveTarget Group
The integrity of PLC variablesProduct Supplier Integration / Maintenance Service Provider

PLC Validate indirections

An indirection is the use of the value of a register in another register. There are many reasons to use indirections.

Examples for necessary indirections are:

  • Variable frequency drives (VFDs) that trigger different actions for different frequencies using lookup tables.
  • To decide which pump to start running first based on their current run times

PLCs do not typically have an “end of an array” flag so it’s a good idea to create it in software; the goal is to avoid unusual/unplanned PLC operations.

Example

Instruction List (IL) Programming

The approach can be turned into a few function blocks and possibly even reused for other applications.

1. Create array mask

Check if the array is binary-sized. If it is not binary-sized, create a mask to the next size up on a binary scale. e.g., if you have a need for 5 registers (not binary-sized):

[21 31 41 51 61]

define an array of 8:

[x x 21 31 41 51 61 x]

Next, take the index value to pick up for the indirection – in this example, it is 3.

Caveat: Index begins at 0!

[21 31 41 51 61]

       _____ ^

Index: 3

add an offset to it making up for the poisoned end. The offset can be 1 or higher, in this case it is 2:

[x x 21 31 41 51 61 x]

        ______     ^

Index including offset: 3 + 2 = 5

and then AND the index including offset with a mask that equals the array size.

In this example the array size is 8, thus index 7, so the mask would be 0x07. The mask makes sure the maximum index you can get is 7, for example:

6 AND 0x07 would give back 6.

7 AND 0x07 would give back 7

8 AND 0x07 would give back 0.

9 AND 0x07 would give back 1.

This ensures you always address a value in the array.

2. Insert poisoned ends

Poisoning ends is optional. You would be able to detect manipulated indirections without the poisoning, but poisoning helps to catch fence-post errors because you get back a value that does not make sense.

The point is that at index 0 of the array, there should be a value that is invalid – such as -1 or 65535. This is “the poisoned end”. Likewise, at the last elements of the array you do the same:

So, for the array above, the poisoned version could look like this:

[-1 -1 21 31 41 51 61 -1]

3. Record value of indirection address without a mask

Then record the value of the indirect address without AND mask and offset:

In this example, you’d record 51 for index 3.

[21 31 41 51 61]

     _____    ^

Index 3

4. Execute AND mask and compare values (=indirection validation)

Compare your recorded value to the value after you have done the offset and the AND mask.

4a. Case A: Correct Indirection

First, offset:

Index + Offset = 3 + 2 = 5

Second, mask:

5 AND 0x07 = 5

Third, indirection check:

[-1 -1 21 31 41 51 61 -1]

    _______          ^

Index including offset: 5

Value = 51 equals the recorded value, so everything is fine.

4b. Case B: Manipulated Indirection

If you now had a manipulated indirection, let’s say 7, let us see what happens:

First, offset:

Index + Offset = 7 + 2 = 9

Second, mask:

9 AND 0x07 = 1

Third, indirection check:

[-1 -1 21 31 41 51 61 -1]

____^

Index including offset: 1

Value = -1 does not equal the recorded value and also indicates your poisoned end, so you’d know your indirection is manipulated.

5. Execute fault/programmer alert

If this validated value is different from your recorded one, then you know something is wrong. Raise a software quality alarm.

Then, check the indirection value. If it is a poisoned value, you should raise another software quality alarm. This is an indication of a fence-post error.

Why?

Beneficial for…?Why?
              SecurityMost PLCs do not have any feature to handle out-of-bounds indices for arrays. There are two potentially dangerous scenarios that can stem from indirection mistakes:

First, if an indirection leads to reading from the wrong register, the program executes using the wrong values.

Second, if a wrong indirection leads to writing to the wrong register, the program overwrites code or values you want to keep. In both cases, indirection errors can be hard to spot and can have serious impacts. They can be caused by human error but also be inserted maliciously.
ReliabilityIdentifies non-malicious human errors in programming.
Maintenance/

References

Standard/frameworkMapping
  MITRE ATT&CK for ICSTactic:  TA010 – Impair Process Control
Technique:  T0836 – Modify Parameter
  ISA 62443-3-3SR 3.5: Input Validation
SR 3.6: Deterministic Output
  ISA 62443-4-2CR 3.5: Input Validation
CR 3.6: Deterministic Output
  ISA 62443-4-1SI-2: Secure coding standards
SVV-1: Security requirements testing
MITRE CWECWE-129: Improper Validation of Array Index

Source: PLC Security

Don't Miss Our Updates
Be the first to get exclusive content straight to your email.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address
You've successfully subscribed !

Continue Reading

Toggle Switch & Sensor: Conveyor and Puncher PLC Program
Drilling Process using PLC Program
Animation of Electromagnetic Relay
What are Faceplates? How to Create a Faceplate? HMI Visualization
Count and Pack Objects from Conveyor using PLC Ladder Logic
PLC Program to Drain Same Products from Two Tanks
Share This Article
Facebook Whatsapp Whatsapp LinkedIn Copy Link
Share
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

128.3kFollowersLike
69.1kFollowersFollow
210kSubscribersSubscribe
38kFollowersFollow

Categories

Explore More

Troubleshoot the Status of a PLC Via CPU Indicators
How to implement SR Flip Flop using PLC Ladder Logic
SCADA Communication and Protocols
MODBUS ASCII Communication Protocol Explained
Control Room and Field Instruments Questions and Answers
Electrical Switches Principle & Types
PLC Programmer Salary and Future Career Scope
The Purpose of Marshalling Cabinet or Marshalling Panel

Keep Learning

PLC Digital Inputs

PLC Digital Input and Digital Output Modules

PLC Program for fan control unit system

PLC Programming for Fan Control Unit System for Industry

S7 1200 PLC Program

Siemens S7 1200 PLC configuration in TIA Portal

Automatic Coffee Machine

Automatic Coffee Vending Machine – PLC Logic Programming

Advanced Skills Required for a PLC Programmer to Get a Job

Advanced Skills Required for a PLC Programmer to Get a Job

PLC programming for clothes washing machine automation

LS Electric PLC Program Example: Clothes Washing System

If Else Statement in SCL Language

If Else Statement in SCL Language

Industrial PLC Communication Network

Basics of Industrial Communication Networks

Learn More

Feedback Accelerometer System Objective Questions

Feedback Accelerometer System Objective Questions

Allen-Bradley PLC Program

Troubleshoot Allen Bradley PLC Logic

Substation Safety Clearances

Substation Safety Clearances

Differential Pressure Gauge Principle

Differential Pressure Gauge Principle

Convert-Linear-%-to-Square-root-%

Formula for Linear % to Square root % conversion

Control Valves Chemical attack Problems

Control Valves Chemical attack Problems

Electrical Machines Questions and Answers

Power Flow Through an Inductive Impedance Questions

Air Pressure Regulator cut-away diagram

Air Pressure Regulator Questions

Menu

  • About
  • Privacy Policy
  • Copyright

Quick Links

  • Learn PLC
  • Helping Hand
  • Part Time Job

YouTube Subscribe

Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?