You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new security query cpp/mmio-unsanitized-memcpy targeting unsanitized memory copy operations (memcpy, memmove, strncpy) where size parameters derive directly from hardware registers (MMIO/DMA) without relational bounds checks.
Motivation & Domain Context
Standard buffer overflow queries (UnboundedWrite.ql, OverrunWrite.ql) model user-space strings and generic memory ops, but do not model volatile register macro reads (READ_REG, GET_MMIO) commonly found in microcontroller drivers, RTOS kernels, and embedded hardware stacks. This query fills a gap for embedded C/C++ static analysis.
Query Design & Architecture
Taint Engine: Modern DataFlow::ConfigSig with TaintTracking::Global.
Sinks: Parameter index 2 (size/count) of memcpy, memmove, strncpy, wmemcpy, wmemmove.
Barriers: Public IRGuards via DataFlow::BarrierGuard<lessThanOrEqual/3> to recognize if (len <= MAX) conditions and prevent false positives. lessThanOrEqual uses the public Operand + getConvertedResultExpression() pattern.
Public API Compliance: Uses only public APIs (cpp, TaintTracking, IRGuards). Zero internal. / DataFlowImplCommon dependencies.
Verification & Test Results
Test Command:codeql test run cpp/ql/test/query-tests/Security/CWE/CWE-120/MmioUnsanitizedMemcpy/
Summary
Adds a new security query
cpp/mmio-unsanitized-memcpytargeting unsanitized memory copy operations (memcpy,memmove,strncpy) where size parameters derive directly from hardware registers (MMIO/DMA) without relational bounds checks.Motivation & Domain Context
Standard buffer overflow queries (
UnboundedWrite.ql,OverrunWrite.ql) model user-space strings and generic memory ops, but do not model volatile register macro reads (READ_REG,GET_MMIO) commonly found in microcontroller drivers, RTOS kernels, and embedded hardware stacks. This query fills a gap for embedded C/C++ static analysis.Query Design & Architecture
DataFlow::ConfigSigwithTaintTracking::Global.READ_REG,GET_MMIO,REG_READ,DMA_READ).memcpy,memmove,strncpy,wmemcpy,wmemmove.IRGuardsviaDataFlow::BarrierGuard<lessThanOrEqual/3>to recognizeif (len <= MAX)conditions and prevent false positives.lessThanOrEqualuses the publicOperand+getConvertedResultExpression()pattern.cpp,TaintTracking,IRGuards). Zerointernal./DataFlowImplCommondependencies.Verification & Test Results
codeql test run cpp/ql/test/query-tests/Security/CWE/CWE-120/MmioUnsanitizedMemcpy/All 1 tests passed(3 positive alerts, 3 false-positive barrier test cases clean).codeql generate query-helppassed DTD verification and rendered clean markdown.includeofcpp/mmio-unsanitized-memcpyincpp-security-extended.qls.Checklist
@kind path-problem,@precision medium,@security-severity 8.6)..qhelpfile provided with valid DTD structure and Bad/Good examples..qlref,test.c, and verified.expectedoutput..qlssuite.internal.module imports used.