Post · 1 min read· pp. 236–237

Avoid Shared Variables for Inter-task Communication (CON03)

Level →\rightarrow Advisory

Category : Safety: : ✓\checkmark

code
Cyber:
:   ✓\checkmark

Goal : Maintainability: : ✓\checkmark

code
Reliability:
:   ✓\checkmark

Portability:
:   ✓\checkmark

Performance:
:   ✓\checkmark

Security:

Remediation →\rightarrow High

Verification Method →\rightarrow GNATcheck rule: Volatile_Objects_Without_Address_Clauses (builtin rule)

Reference

Ada Reference Manual: D.13 The Ravenscar Profile

Description

Although the Ravenscar and Jorvik profiles allow the use of shared variables for inter-task communication, such use is less robust and less reliable than encapsulating shared variables within protected objects.

Applicable Vulnerability within ISO TR 24772-2

  • 6.56 Undefined behaviour [EWF]

Applicable Common Weakness Enumeration

Noncompliant Code Example

ada
   Global_Object : Integer
     with Volatile;
   function Get return Integer is (Global_Object);

Note that variables marked as Atomic are also Volatile, per the Ada Reference Manual: C.6 (8/3) Shared Variable Control

Compliant Code Example

When assigned to a memory address, a Volatile variable can be used to interact with a memory-mapped device, among other similar usages.

ada
   Global_Object : Integer
     with Volatile,
          Address => To_Address (16#1234_5678#);
   function Get return Integer is (Global_Object);

Notes

In addition to GNATcheck, SPARK and CodePeer can also detect conflicting access to unprotected variables.