cpp: Add 'cpp/mmio-unsanitized-memcpy' query - #22438
Open
Tito0015 wants to merge 1 commit into
Open
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.