How to Track Non Atomic Data Types
In general, processes do not execute atomically, since the operating system may interrupt processes between essentially any two instructions, allowing other processes to run. If your application's process is not prepared for these interruptions, another process may be able to interfere with it, causing the data structures to end up in inconsistent states if arbitrary code is executed between them.
A non atomic condition is a vulnerability to interference caused by untrusted processes. These are conditions caused by processes running other, different programs, which introduce other actions between steps of the program. These other programs might be invoked by an attacker.
This use case illustrates how to use Ocular to analze for non atomic data types, using the FreeRTOS real-time operating system kernel as the example target application.
Downloading the FreeRTOS Application
Download the FreeRTOS application and unzip the source code into the Ocular subjects directory, for example subjects/FreeRTOS.
Creating the FreeRTOS Application CPG
importCpg("subjects/FreeRTOS")FreeRTOS's CPG is automatically loaded into memory and your workspace.
Declaring an Array of Primitive Types
val primitiveTypes = List("int", "float", "double", "void", "size_t", "ANY", "void", "char", "short")Calling a Convenience Function to get LineNumber
def getLineNumber(ln : Option[Integer]) = (ln match { case Some(x) => x ; case None => 0 }).asInstanceOf[Int]Declaring a Data Structure of User Defined Types
Acquiring all Identifiers into UDT Data Structure
Negative filter on primitive types.
Storing Findings in a Multimap Keyed by Identified methodName
Storing Findings in a Multimap Keyed by Identified Type
Calling a Convenience Function to get Range Given Start and End
Giving functionName Return all callOuts within Scope of the Function
Optimizing Name Replacement
Calling a Convenience Function for Holding Functions with CRITICAL SECTIONS with Ranges
Specifying Functions to Optimize Ranging
For situations in which multiple critical sections exists in a method (function).
Getting Entire callOut Trace for Each Method that Encompasses taskENTER_CRITICAL
Getting Entire callOut Trace for Each Method that DOES NOT Encompass taskENTER_CRITICAL
Optimizing Replacement
Filtering callMap and Fitting into WithCriticalSection
Navigating using an Identifier
For example called xQueueAddToSet. Pick any type from udtMapByType say for instance tfp_format.
If (nonAtomicUsedInCS.size > 0 && nonAtomicUsedInNoCS.size > 0), this implies that a non atomic data type is used both in guarded context and not in guarded context, possibly leading to deadlock or starvation.
Determining the Location Details of Where the Non Atomic Data type is Used
Last updated
Was this helpful?