<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>cpg on SecMate Blog</title><link>https://blog.secmate.dev/tags/cpg/</link><description>What we find. What we share.</description><generator>Hugo</generator><language>en-us</language><managingEditor>noreply@blog.secmate.dev//blog.secmate.dev/ (SecMate Team)</managingEditor><lastBuildDate>Tue, 25 Aug 2026 06:06:13 +0000</lastBuildDate><atom:link href="https://blog.secmate.dev/tags/cpg/index.xml" rel="self" type="application/rss+xml"/><item><title>From USB to ESP: CPG-Guided Local Analysis</title><link>https://blog.secmate.dev/posts/espressif-usb-cpg-findings/</link><pubDate>Wed, 19 Aug 2026 00:00:00 +0000</pubDate><dc:creator>Maxime Rossi Bellom</dc:creator><dc:creator>Ramtine Tofighi Shirazi</dc:creator><category>Security</category><category>Vulnerability Research</category><category>Embedded</category><guid>https://blog.secmate.dev/posts/espressif-usb-cpg-findings/</guid><description>How SecMate uses source-backed CPG slices and local models to analyze three disclosed vulnerabilities in Espressif USB host drivers.</description><content:encoded><![CDATA[<p>Frontier systems such as Mythos can inspect a repository <a href="#ref19">[19]</a>. That is not the hard part. Security work still needs a record of the code that was analyzed, the paths considered, the assumptions left open, and the source behind a finding.</p>
<p>SecMate was built for cases where source code cannot leave the operator&rsquo;s environment and where repeatedly handing a model a large repository is too expensive. Our current workflow runs <code>gpt-oss</code>. It does not give the model a repository and hope for the best. It first recovers the program relations that matter, then gives the model a small question with the relevant source attached.</p>
<p>We do not call this model agnostic. The prompts, tools, context, and validation process are tuned for the models we use today. Switching to another model family, such as DeepSeek or Qwen, would require integration and evaluation work. Adopting a new version of a model already in use would also require evaluation and, if its interface or behavior changed, integration work. For a fixed source revision, build configuration, semantic models, candidate query, and evidence package, the graph extraction is repeatable. The model’s conclusion remains a judgment.</p>
<p>We presented this work at LeHack 2026 in <a href="https://lehack.org/2026/tracks/conferences/#from-usb-to-esp-security-vulnerabilities-in-espressif-firmware" rel="noopener noreferrer" target="_blank"><em>From USB to ESP: Security Vulnerabilities in Espressif Firmware</em></a>. This post is the analysis part: three vulnerabilities in Espressif USB host drivers that SecMate found automatically with this workflow. Researchers validated them, completed responsible disclosure, and received CVE assignments. The cases span bounds, lifetime, and concurrency.</p>
<h2 id="the-engineering-problem">The Engineering Problem</h2>
<p>These constraints are common in product security. The source may contain customer intellectual property, fall under an NDA, or live in an environment with data residency requirements. Sending it to an external model service may be prohibited. Some teams also want control over what leaves their environment. That can include whether a provider attaches provenance metadata to generated files. Anthropic&rsquo;s marking of generated images is one current example <a href="#ref20">[20]</a>. Cost matters too. A security analysis reads the same repository repeatedly as it follows paths, revisits callers and callees, and gathers support for each result.</p>
<p>SecMate was built for those constraints. Its analysis and inference run inside infrastructure controlled by the operator. The workflow uses the open-weight <code>gpt-oss-20b</code> and <code>gpt-oss-120b</code> models. OpenAI states that the smaller model can run with 16 GB of memory and that the larger model fits on a single 80 GB GPU <a href="#ref1">[1]</a>.</p>
<p>Keeping inference local solves where it runs. It does not decide what code the model should see. A repository that is too large or noisy for a hosted model is still too large or noisy on premises.</p>
<h2 id="why-reduce-before-reasoning">Why Reduce Before Reasoning</h2>
<p>Security bugs are rarely contained in one function. A length can enter through a parser, cross several fields, influence an allocation, and later reach a copy. A pointer can be stored in a structure, freed during teardown, and used again through a local alias.</p>
<p>Giving a model every file leaves it with two jobs: discover which code matters, then decide whether that code is vulnerable. The first job consumes most of the context and must be repeated for every candidate. It also makes the result difficult to audit because the model&rsquo;s conclusion is no longer attached to a small, inspectable path.</p>
<p>SecMate treats the first job as program analysis. It indexes an exact source revision with its build context and semantic models. For each candidate, it extracts the relevant calls, control conditions, values, aliases, and source locations into a small package for review.</p>
<p>A frontier model can search with <code>rg</code>, open files, and follow a hypothesis. That is useful. Without an equivalent persistent analysis layer, it must find and retain those relationships while it investigates. SecMate keeps them outside the model.</p>
<p>For a fixed analysis configuration, that extraction follows the same graph relations every time. A reviewer can inspect the source path without rerunning the model.</p>
<h2 id="method-from-repository-to-evidence-slice">Method: From Repository to Evidence Slice</h2>
<p>Here is the path from a USB descriptor to a reportable finding.</p>
<style>
  :root{--ink-red:#a4123a;--ink-purple:#6d28d9;--ink-amber:#8a5200}
  html.dark{--ink-red:#ff8fa8;--ink-purple:#c4b5fd;--ink-amber:#fbbf24}
  .figure-scroll{width:100%;overflow-x:auto;margin:1.75rem 0}
  .sc-bg{fill:var(--color-bg-card);stroke:var(--color-border);stroke-width:1.4}
  .sc-panel{fill:none;stroke:var(--color-text-secondary);stroke-width:1.2;stroke-dasharray:5 6;opacity:.38}
  .sc-file{fill:var(--color-text-secondary);font-family:var(--font-mono,ui-monospace,Menlo,monospace);opacity:.85}
  .sc-node{fill:var(--color-muted-bg);stroke:color-mix(in srgb,var(--color-text-secondary) 42%,transparent);stroke-width:1.4}
  .sc-entry{fill:var(--color-muted-bg);stroke:var(--color-accent);stroke-width:2.6}
  .sc-sink{fill:var(--color-accent);stroke:var(--color-accent);stroke-width:2}
  .sc-free{fill:var(--color-muted-bg);stroke:var(--color-secondary);stroke-width:2.6}
  .sc-hit{fill:color-mix(in srgb,#e11d48 26%,var(--color-muted-bg));stroke:#e11d48;stroke-width:2.6}
  .sc-dim{opacity:.28}
  .sc-num{fill:var(--color-text);font-family:var(--font-mono,ui-monospace,Menlo,monospace);font-weight:700}
  .sc-num-inv{fill:#0b1220;font-family:var(--font-mono,ui-monospace,Menlo,monospace);font-weight:700}
  .sc-title{fill:var(--color-text);font-family:var(--font-sans,system-ui,sans-serif)}
  .sc-muted{fill:var(--color-text-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
  .sc-tag{font-family:var(--font-mono,ui-monospace,Menlo,monospace);font-weight:700}
  .sc-ast{stroke:var(--color-text-secondary);stroke-width:1.3;fill:none;stroke-dasharray:2 4;opacity:.6}
  .sc-faint{opacity:.2}
  .figure-scroll svg{display:block;width:100%;min-width:720px;height:auto}
  .finding-summary{display:grid;gap:.8rem;margin:2rem 0}
  .finding-summary__item{display:grid;grid-template-columns:1.15fr 1fr 2.1fr 1.1fr 1fr;gap:1rem;margin:0;padding:1rem;border:1px solid var(--color-border);border-radius:8px;background:var(--color-bg-card)}
  .finding-summary__field{min-width:0}
  .finding-summary dt{margin:0 0 .35rem;color:var(--color-text-secondary);font-size:.68rem;font-weight:700;letter-spacing:.05em;text-transform:uppercase}
  .finding-summary dd{margin:0;color:var(--color-text);font-size:.88rem;line-height:1.45;overflow-wrap:anywhere}
  .evidence-package{margin:1.75rem 0;border:1px solid var(--color-border);border-radius:8px;background:var(--color-muted-bg);overflow:hidden}
  .evidence-package__head{padding:.75rem 1.1rem;border-bottom:1px solid var(--color-border);color:var(--color-text);font-weight:700;font-size:.92rem}
  .evidence-package__grid{display:grid;grid-template-columns:auto minmax(0,1fr);gap:.7rem 1.2rem;margin:0;padding:1.1rem}
  .evidence-package__grid dt{color:var(--color-text-secondary);font-size:.68rem;font-weight:700;letter-spacing:.05em;text-transform:uppercase;padding-top:.2rem}
  .evidence-package__grid dd{margin:0;color:var(--color-text);font-family:var(--font-mono,ui-monospace,Menlo,monospace);font-size:.8rem;line-height:1.55;white-space:pre-wrap;overflow-wrap:anywhere}
  .ep-bad{color:var(--ink-red);font-weight:600}
  .ep-alias{color:var(--ink-purple)}
  .ep-data{color:var(--color-secondary)}
  @media (max-width:800px){.finding-summary__item{grid-template-columns:1fr 1fr}.finding-summary__field--wide{grid-column:1/-1}}
  @media (max-width:600px){.evidence-package__grid{grid-template-columns:1fr;gap:.25rem}.evidence-package__grid dd{margin-bottom:.6rem}}
  @media (max-width:480px){.finding-summary__item{grid-template-columns:1fr}.finding-summary__field--wide{grid-column:auto}}
  @media print{
    .figure-scroll{overflow:visible!important;break-inside:avoid}
    .figure-scroll svg{width:auto!important;max-width:100%!important;min-width:0!important;height:auto!important;max-height:82vh!important;margin:0 auto!important}
    .evidence-package,.finding-summary__item{break-inside:avoid}
  }
</style>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 660" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="ar-title ar-desc">
  <title id="ar-title">The SecMate pipeline from device input to disclosed finding</title>
  <desc id="ar-desc">Attacker-controlled USB input enters a build-aware program index, which is enriched into a CPG with analysis overlays. API and semantic models classify operations on the graph. Class-specific traversals produce a bounded evidence slice, a local model tests the hypothesis, and a researcher validates before disclosure. The three Espressif CVEs are the outcome.</desc>
  <defs>
    <marker id="ar-gray" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto"><path d="M0,0 L10,4 L0,8 Z" fill="var(--color-text-secondary)"/></marker>
    <style>
      .ar-bg{fill:var(--color-muted-bg);stroke:var(--color-border);stroke-width:1.4}
      .ar-node{fill:var(--color-bg-card);stroke:var(--color-border);stroke-width:1.5}
      .ar-input{fill:color-mix(in srgb,var(--color-secondary) 13%,var(--color-bg-card));stroke:var(--color-secondary);stroke-width:1.6}
      .ar-model{fill:var(--color-bg-card);stroke:var(--color-text-secondary);stroke-width:1.5;stroke-dasharray:6 4}
      .ar-cve{fill:color-mix(in srgb,#dc2626 8%,var(--color-bg-card));stroke:#dc2626;stroke-width:1.4}
      .ar-strong{fill:var(--color-text);font-family:var(--font-sans,system-ui,sans-serif);font-weight:700}
      .ar-code{fill:var(--color-text);font-family:var(--font-mono,ui-monospace,Menlo,monospace)}
      .ar-muted{fill:var(--color-text-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
      .ar-flow{stroke:var(--color-text-secondary);stroke-width:2;fill:none;marker-end:url(#ar-gray)}
    </style>
  </defs>
  <rect class="ar-bg" x="1" y="1" width="898" height="658" rx="12"/>
  <text class="ar-strong" x="36" y="42" font-size="20">From USB device to disclosed finding</text>
  <text class="ar-muted" x="36" y="66" font-size="13">The pipeline, the models that feed it, and the split between model review and human validation.</text>
  <rect class="ar-input" x="60" y="96" width="300" height="58" rx="7"/>
  <text class="ar-strong" x="76" y="118" font-size="13">USB device</text>
  <text class="ar-muted" x="76" y="138" font-size="11">attacker-controlled descriptors, lengths, timing</text>
  <path class="ar-flow" d="M210 154 V180"/>
  <rect class="ar-node" x="60" y="184" width="300" height="74" rx="7"/>
  <text class="ar-strong" x="76" y="206" font-size="13">Selected build targets</text>
  <text class="ar-muted" x="76" y="226" font-size="11">exact commit · compilation commands</text>
  <text class="ar-muted" x="76" y="244" font-size="11">macros, configuration, generated sources</text>
  <path class="ar-flow" d="M210 258 V280"/>
  <rect class="ar-node" x="60" y="284" width="300" height="74" rx="7"/>
  <text class="ar-strong" x="76" y="306" font-size="13">Enriched CPG and analysis overlays</text>
  <text class="ar-muted" x="76" y="326" font-size="11">source span and provenance on every node</text>
  <text class="ar-muted" x="76" y="344" font-size="11">control flow, dependences, call/return, aliases</text>
  <path class="ar-flow" d="M210 358 V380"/>
  <text class="ar-muted" x="222" y="374" font-size="11">class-specific traversal</text>
  <rect class="ar-node" x="60" y="384" width="300" height="58" rx="7"/>
  <text class="ar-strong" x="76" y="406" font-size="13">Evidence slice</text>
  <text class="ar-muted" x="76" y="426" font-size="11">bounded, source-backed package per candidate</text>
  <path class="ar-flow" d="M210 442 V464"/>
  <rect class="ar-node" x="60" y="468" width="300" height="58" rx="7"/>
  <text class="ar-strong" x="76" y="490" font-size="13">Local model review</text>
  <text class="ar-muted" x="76" y="510" font-size="11">tests the bounded hypothesis</text>
  <path class="ar-flow" d="M210 526 V548"/>
  <rect class="ar-node" x="60" y="552" width="300" height="58" rx="7"/>
  <text class="ar-strong" x="76" y="574" font-size="13">Researcher validation</text>
  <text class="ar-muted" x="76" y="594" font-size="11">accepts, rejects, or requests more evidence</text>
  <rect class="ar-model" x="480" y="284" width="340" height="106" rx="7"/>
  <text class="ar-strong" x="496" y="308" font-size="13">API and semantic models</text>
  <text class="ar-muted" x="496" y="328" font-size="11">allocator and release summaries</text>
  <text class="ar-muted" x="496" y="346" font-size="11">copy and write semantics, locking primitives</text>
  <text class="ar-muted" x="496" y="364" font-size="11">project-specific function summaries</text>
  <text class="ar-muted" x="496" y="382" font-size="11">callback and task registration</text>
  <path class="ar-flow" d="M480 337 C400 337 300 356 218 368"/>
  <text class="ar-muted" x="352" y="330" font-size="11" text-anchor="middle">classifies operations</text>
  <rect class="ar-cve" x="480" y="470" width="340" height="44" rx="7"/>
  <text class="ar-code" x="496" y="488" font-size="12">CVE-2025-68656</text>
  <text class="ar-muted" x="496" y="506" font-size="11">HID descriptor use-after-free</text>
  <rect class="ar-cve" x="480" y="528" width="340" height="44" rx="7"/>
  <text class="ar-code" x="496" y="546" font-size="12">CVE-2025-68657</text>
  <text class="ar-muted" x="496" y="564" font-size="11">HID close-path double-free race</text>
  <rect class="ar-cve" x="480" y="586" width="340" height="44" rx="7"/>
  <text class="ar-code" x="496" y="604" font-size="12">CVE-2025-68622</text>
  <text class="ar-muted" x="496" y="622" font-size="11">UVC descriptor stack overflow</text>
  <path class="ar-flow" d="M360 581 C420 581 428 550 474 550"/>
  <text class="ar-muted" x="408" y="566" font-size="11">disclosed</text>
</svg>
</div>
<p><em>Figure 1. The pipeline used in this article. The model reviews a focused hypothesis. A researcher decides whether it supports disclosure.</em></p>
<h3 id="1-build-a-program-index">1. Build a program index</h3>
<p>Full-codebase analysis is not a glob over sources and headers. For this C/C++ work, the unit is a translation unit plus the compilation command used for it. Headers are interpreted under specific macro definitions, include paths, and build options. The same <code>.c</code> file may appear more than once under different configurations. Clang&rsquo;s JSON compilation database records those per-translation-unit commands <a href="#ref18">[18]</a>. Other languages need an equivalent front end for their compilation or runtime model. SecMate starts from an exact commit, the compilation commands, the macros and configuration in force, and any generated sources. The frontend preprocesses and parses the translation units, records source spans, resolves declarations and types, and links calls across files where the available information permits it.</p>
<p>Every node retains its file, line, and column. In this C/C++ analysis, it also retains the relevant build variant, translation unit, and macro expansion context. Within a run, a reviewer can open the exact line and build variant behind a claim.</p>
<p>That scope is part of the result. Conditional compilation, generated sources, missing build metadata, function pointers, and unresolved external code can all limit coverage. They must remain visible as unresolved facts instead of being silently treated as complete.</p>
<h3 id="2-build-the-ast-then-identify-what-it-is-missing">2. Build the AST, then identify what it is missing</h3>
<p>The Abstract Syntax Tree records declarations, expressions, calls, assignments, and scopes. A call node shows that call syntax exists. It does not necessarily identify every function that can run. An <code>if</code> node records a branch. It does not establish which later statements the condition controls.</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 470" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="ast-t ast-d">
<title id="ast-t">The AST gives local structure only</title>
<desc id="ast-d">The syntax tree records local structure in usb_host_hid.c and the two functions in hid_host.c. It does not by itself resolve the control flow, data flow, or calls that connect them.</desc>
<defs>
<marker id="ast-cf" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#d97706"/></marker>
<marker id="ast-dd" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-accent)"/></marker>
<marker id="ast-cl" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-secondary)"/></marker>
<marker id="ast-vu" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#e11d48"/></marker>
<style>
.ast-cf{stroke:#d97706;stroke-width:2.2;fill:none;marker-end:url(#ast-cf)}
.ast-dd{stroke:var(--color-accent);stroke-width:2.2;fill:none;marker-end:url(#ast-dd)}
.ast-cl{stroke:var(--color-secondary);stroke-width:2.4;fill:none;marker-end:url(#ast-cl)}
.ast-vu{stroke:#e11d48;stroke-width:2.6;fill:none;marker-end:url(#ast-vu)}
</style>
</defs>
<rect class="sc-bg" x="1" y="1" width="898" height="468" rx="12"/>
<text class="sc-title" x="32" y="40" font-size="18" font-weight="700">The AST is local structure, not behavior</text>
<text class="sc-muted" x="32" y="62" font-size="12.5">Syntax is local; resolved cross-file behavior is not yet represented.</text>
<rect class="sc-panel" x="28" y="96" width="248" height="316" rx="9"/>
<text class="sc-file" x="44" y="122" font-size="12">usb_host_hid.c</text>
<rect class="sc-panel" x="300" y="72" width="300" height="340" rx="9"/>
<text class="sc-file" x="316" y="98" font-size="12">hid_host.c · get_descriptor()</text>
<rect class="sc-panel" x="624" y="112" width="248" height="300" rx="9"/>
<text class="sc-file" x="640" y="138" font-size="12">hid_host.c · transfer()</text>
<path class="sc-ast" d="M85 179 L97 197"/>
<path class="sc-ast" d="M121 221 L179 253"/>
<path class="sc-ast" d="M142 137 L94 160"/>
<path class="sc-ast" d="M75 306 L118 335"/>
<path class="sc-ast" d="M144 342 L198 333"/>
<path class="sc-ast" d="M385 161 L360 215"/>
<path class="sc-ast" d="M406 153 L499 200"/>
<path class="sc-ast" d="M363 240 L430 288"/>
<path class="sc-ast" d="M506 217 L486 235"/>
<path class="sc-ast" d="M523 220 L538 248"/>
<path class="sc-ast" d="M375 337 L415 368"/>
<path class="sc-ast" d="M439 377 L492 373"/>
<path class="sc-ast" d="M696 179 L712 248"/>
<path class="sc-ast" d="M772 211 L824 239"/>
<path class="sc-ast" d="M674 249 L698 260"/>
<path class="sc-ast" d="M730 273 L782 293"/>
<path class="sc-ast" d="M811 287 L829 259"/>
<path class="sc-ast" d="M685 319 L668 259"/>
<circle class="sc-node" cx="78" cy="168" r="11"/>
<circle class="sc-node" cx="152" cy="132" r="9"/>
<circle class="sc-node" cx="108" cy="214" r="13"/>
<circle class="sc-node" cx="196" cy="262" r="12"/>
<circle class="sc-node" cx="66" cy="300" r="9"/>
<circle class="sc-node" cx="132" cy="344" r="10"/>
<circle class="sc-node" cx="214" cy="330" r="9"/>
<circle class="sc-node" cx="392" cy="146" r="14"/>
<circle class="sc-node" cx="352" cy="232" r="12"/>
<circle class="sc-node" cx="446" cy="300" r="13"/>
<circle class="sc-node" cx="516" cy="208" r="12"/>
<circle class="sc-node" cx="474" cy="246" r="9"/>
<circle class="sc-node" cx="546" cy="262" r="9"/>
<circle class="sc-node" cx="366" cy="330" r="9"/>
<circle class="sc-node" cx="428" cy="378" r="9"/>
<circle class="sc-node" cx="508" cy="372" r="9"/>
<circle class="sc-node" cx="694" cy="168" r="9"/>
<circle class="sc-node" cx="762" cy="206" r="9"/>
<circle class="sc-node" cx="664" cy="244" r="9"/>
<circle class="sc-node" cx="716" cy="268" r="13"/>
<circle class="sc-node" cx="802" cy="300" r="14"/>
<circle class="sc-node" cx="838" cy="246" r="9"/>
<circle class="sc-node" cx="688" cy="330" r="9"/>
<path class="sc-ast" d="M32 440 H58"/>
<text class="sc-muted" x="66" y="444" font-size="11.5">syntax (within a file)</text>
</svg>
</div>
<p><em>Figure 2. The syntax tree of the three files involved in the HID finding. It records local syntax, but not resolved cross-file control flow, data flow, or call/return behavior. The descriptor length read in one function and the release and later use in another are not related by those semantic edges here.</em></p>
<p>Security analysis therefore needs relations that are not present in the AST:</p>
<table>
<thead>
<tr>
<th>Security question</th>
<th>Required relation or analysis</th>
</tr>
</thead>
<tbody>
<tr>
<td>What can execute next?</td>
<td>Control Flow Graph (CFG)</td>
</tr>
<tr>
<td>Which condition governs this operation?</td>
<td>dominance, post-dominance, and control dependence</td>
</tr>
<tr>
<td>Where did this value come from?</td>
<td>definitions, uses, and data dependence</td>
</tr>
<tr>
<td>Does the path cross a function boundary correctly?</td>
<td>call graph and call/return context</td>
</tr>
<tr>
<td>Do two expressions refer to the same object?</td>
<td>points-to and alias analysis</td>
</tr>
<tr>
<td>Can two paths execute concurrently on the same object?</td>
<td>task or callback concurrency, shared-state, and synchronization analysis</td>
</tr>
</tbody>
</table>
<p>A CFG over-approximates possible execution order. It does not prove that every graph path is feasible. Alias and indirect call resolution are approximations too. Those limits matter when a candidate is validated.</p>
<h3 id="3-enrich-the-graph">3. Enrich the graph</h3>
<p>The Code Property Graph described by Yamaguchi and colleagues brings syntax, control flow, and program dependence into one queryable representation <a href="#ref5">[5]</a>. At repository scale, the graph also needs resolved symbols and types, call and return relations, and alias information. Control and data dependence support slicing, which retains the statements relevant to a chosen operation and value <a href="#ref2">[2]</a> <a href="#ref3">[3]</a>. Interprocedural traversal must preserve call and return context instead of accepting arbitrary paths through the call graph <a href="#ref4">[4]</a>.</p>
<p>Not every relation has the same status. Syntax and source spans come from the frontend. Control flow, dependence, call targets, and aliases are computed. Context-sensitive call and return relations, alias results, and classifications such as allocations, releases, copies, and locks sit on top of the base graph. Modern CPG specifications describe those calculated layers as overlays <a href="#ref17">[17]</a>. A parser error and an imprecise alias result create different kinds of uncertainty.</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 470" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="cpg-t cpg-d">
<title id="cpg-t">The Code Property Graph links the same nodes across files</title>
<desc id="cpg-d">Control flow, data dependence and call edges connect the same nodes across the three files, so an attacker-controlled source can be followed to a sink.</desc>
<defs>
<marker id="cpg-cf" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#d97706"/></marker>
<marker id="cpg-dd" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-accent)"/></marker>
<marker id="cpg-cl" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-secondary)"/></marker>
<marker id="cpg-vu" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#e11d48"/></marker>
<style>
.cpg-cf{stroke:#d97706;stroke-width:2.2;fill:none;marker-end:url(#cpg-cf)}
.cpg-dd{stroke:var(--color-accent);stroke-width:2.2;fill:none;marker-end:url(#cpg-dd)}
.cpg-cl{stroke:var(--color-secondary);stroke-width:2.4;fill:none;marker-end:url(#cpg-cl)}
.cpg-vu{stroke:#e11d48;stroke-width:2.6;fill:none;marker-end:url(#cpg-vu)}
</style>
</defs>
<rect class="sc-bg" x="1" y="1" width="898" height="468" rx="12"/>
<text class="sc-title" x="32" y="40" font-size="18" font-weight="700">Code Property Graph</text>
<text class="sc-muted" x="32" y="62" font-size="12.5">The same nodes, now carrying execution order, value flow, and calls across files.</text>
<rect class="sc-panel" x="28" y="96" width="248" height="316" rx="9"/>
<text class="sc-file" x="44" y="122" font-size="12">usb_host_hid.c</text>
<rect class="sc-panel" x="300" y="72" width="300" height="340" rx="9"/>
<text class="sc-file" x="316" y="98" font-size="12">hid_host.c · get_descriptor()</text>
<rect class="sc-panel" x="624" y="112" width="248" height="300" rx="9"/>
<text class="sc-file" x="640" y="138" font-size="12">hid_host.c · transfer()</text>
<path class="sc-ast" d="M85 179 L97 197"/>
<path class="sc-ast" d="M121 221 L179 253"/>
<path class="sc-ast" d="M142 137 L94 160"/>
<path class="sc-ast" d="M75 306 L118 335"/>
<path class="sc-ast" d="M144 342 L198 333"/>
<path class="sc-ast" d="M385 161 L360 215"/>
<path class="sc-ast" d="M406 153 L499 200"/>
<path class="sc-ast" d="M363 240 L430 288"/>
<path class="sc-ast" d="M506 217 L486 235"/>
<path class="sc-ast" d="M523 220 L538 248"/>
<path class="sc-ast" d="M375 337 L415 368"/>
<path class="sc-ast" d="M439 377 L492 373"/>
<path class="sc-ast" d="M696 179 L712 248"/>
<path class="sc-ast" d="M772 211 L824 239"/>
<path class="sc-ast" d="M674 249 L698 260"/>
<path class="sc-ast" d="M730 273 L782 293"/>
<path class="sc-ast" d="M811 287 L829 259"/>
<path class="sc-ast" d="M685 319 L668 259"/>
<path class="cpg-cf" d="M121 221 L179 253"/>
<path class="cpg-cf" d="M385 161 L360 215"/>
<path class="cpg-cf" d="M363 240 L430 288"/>
<path class="cpg-cf" d="M482 239 L502 221"/>
<path class="cpg-dd" d="M397 161 L439 281"/>
<path class="cpg-dd" d="M508 219 L458 284"/>
<path class="cpg-cl" d="M208 255 Q314 245 374 157"/>
<path class="cpg-cl" d="M407 152 Q520 291 697 261"/>
<path class="cpg-cl" d="M407 152 Q587 243 782 293"/>
<circle class="sc-node" cx="78" cy="168" r="11"/>
<circle class="sc-node" cx="152" cy="132" r="9"/>
<circle class="sc-entry" cx="108" cy="214" r="13"/>
<circle class="sc-node" cx="196" cy="262" r="12"/>
<circle class="sc-node" cx="66" cy="300" r="9"/>
<circle class="sc-node" cx="132" cy="344" r="10"/>
<circle class="sc-node" cx="214" cy="330" r="9"/>
<circle class="sc-node" cx="392" cy="146" r="14"/>
<circle class="sc-node" cx="352" cy="232" r="12"/>
<circle class="sc-node" cx="446" cy="300" r="13"/>
<circle class="sc-node" cx="516" cy="208" r="12"/>
<circle class="sc-node" cx="474" cy="246" r="9"/>
<circle class="sc-node" cx="546" cy="262" r="9"/>
<circle class="sc-node" cx="366" cy="330" r="9"/>
<circle class="sc-node" cx="428" cy="378" r="9"/>
<circle class="sc-node" cx="508" cy="372" r="9"/>
<circle class="sc-node" cx="694" cy="168" r="9"/>
<circle class="sc-node" cx="762" cy="206" r="9"/>
<circle class="sc-node" cx="664" cy="244" r="9"/>
<circle class="sc-node" cx="716" cy="268" r="13"/>
<circle class="sc-sink" cx="802" cy="300" r="14"/>
<circle class="sc-node" cx="838" cy="246" r="9"/>
<circle class="sc-node" cx="688" cy="330" r="9"/>
<text class="sc-tag" x="108" y="184" font-size="11" text-anchor="middle" fill="var(--color-accent)">source</text>
<text class="sc-tag" x="802" y="336" font-size="11" text-anchor="middle" fill="var(--color-accent)">sink</text>
<path class="cpg-cf" d="M32 440 H58"/>
<text class="sc-muted" x="66" y="444" font-size="11.5">control flow</text>
<path class="cpg-dd" d="M147 440 H173"/>
<text class="sc-muted" x="181" y="444" font-size="11.5">data dependence</text>
<path class="cpg-cl" d="M281 440 H307"/>
<text class="sc-muted" x="315" y="444" font-size="11.5">call · across files</text>
</svg>
</div>
<p><em>Figure 3. The same nodes, now carrying execution order, value flow, and resolved calls. The graph can now be traversed from an attacker-controlled source to a sink across file and function boundaries.</em></p>
<h3 id="4-run-security-analyses-on-the-cpg">4. Run security analyses on the CPG</h3>
<p>Lifetime is not an AST edge. To find a use-after-free, the analysis has to connect object identity, aliases, execution order, a release, and a later use of the same object. The same applies to the other bug classes:</p>
<ul>
<li>a bounds analysis starts at a copy or write and recovers the input length, destination extent, governing checks, and interprocedural path;</li>
<li>a lifetime analysis connects allocation, aliases, release, replacement, and later use of the same abstract object;</li>
<li>a race or double-free analysis identifies a candidate overlap between task or callback paths, then compares their access to shared state and the synchronization that should order them.</li>
</ul>
<p>The graph does not know on its own that <code>usb_host_transfer_free()</code> ends an object&rsquo;s lifetime, that <code>usb_host_transfer_alloc()</code> creates or replaces one, or that a project function provides synchronization. SecMate gets that knowledge from API and semantic models. They cover allocators, releases, copies, writes, locking primitives, and project functions. Those models are explicit inputs to the analysis.</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 470" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="ann-t ann-d">
<title id="ann-t">Semantic models annotate the graph</title>
<desc id="ann-d">Entry points, security-relevant sinks and lifetime operations such as free are classified on the graph by API and semantic models before any traversal runs.</desc>
<defs>
<marker id="ann-cf" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#d97706"/></marker>
<marker id="ann-dd" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-accent)"/></marker>
<marker id="ann-cl" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-secondary)"/></marker>
<marker id="ann-vu" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#e11d48"/></marker>
<style>
.ann-cf{stroke:#d97706;stroke-width:2.2;fill:none;marker-end:url(#ann-cf)}
.ann-dd{stroke:var(--color-accent);stroke-width:2.2;fill:none;marker-end:url(#ann-dd)}
.ann-cl{stroke:var(--color-secondary);stroke-width:2.4;fill:none;marker-end:url(#ann-cl)}
.ann-vu{stroke:#e11d48;stroke-width:2.6;fill:none;marker-end:url(#ann-vu)}
</style>
</defs>
<rect class="sc-bg" x="1" y="1" width="898" height="468" rx="12"/>
<text class="sc-title" x="32" y="40" font-size="18" font-weight="700">Discovery and annotation</text>
<text class="sc-muted" x="32" y="62" font-size="12.5">API and semantic models mark entry points, sinks, and lifetime operations.</text>
<rect class="sc-panel" x="28" y="96" width="248" height="316" rx="9"/>
<text class="sc-file" x="44" y="122" font-size="12">usb_host_hid.c</text>
<rect class="sc-panel" x="300" y="72" width="300" height="340" rx="9"/>
<text class="sc-file" x="316" y="98" font-size="12">hid_host.c · get_descriptor()</text>
<rect class="sc-panel" x="624" y="112" width="248" height="300" rx="9"/>
<text class="sc-file" x="640" y="138" font-size="12">hid_host.c · transfer()</text>
<path class="sc-ast" d="M85 179 L97 197"/>
<path class="sc-ast" d="M121 221 L179 253"/>
<path class="sc-ast" d="M142 137 L94 160"/>
<path class="sc-ast" d="M75 306 L118 335"/>
<path class="sc-ast" d="M144 342 L198 333"/>
<path class="sc-ast" d="M385 161 L360 215"/>
<path class="sc-ast" d="M406 153 L499 200"/>
<path class="sc-ast" d="M363 240 L430 288"/>
<path class="sc-ast" d="M506 217 L486 235"/>
<path class="sc-ast" d="M523 220 L538 248"/>
<path class="sc-ast" d="M375 337 L415 368"/>
<path class="sc-ast" d="M439 377 L492 373"/>
<path class="sc-ast" d="M696 179 L712 248"/>
<path class="sc-ast" d="M772 211 L824 239"/>
<path class="sc-ast" d="M674 249 L698 260"/>
<path class="sc-ast" d="M730 273 L782 293"/>
<path class="sc-ast" d="M811 287 L829 259"/>
<path class="sc-ast" d="M685 319 L668 259"/>
<circle class="sc-node" cx="78" cy="168" r="11"/>
<circle class="sc-node" cx="152" cy="132" r="9"/>
<circle class="sc-entry" cx="108" cy="214" r="13"/>
<text class="sc-num" x="108" y="218" font-size="11" text-anchor="middle">in</text>
<circle class="sc-node" cx="196" cy="262" r="12"/>
<circle class="sc-node" cx="66" cy="300" r="9"/>
<circle class="sc-node" cx="132" cy="344" r="10"/>
<circle class="sc-node" cx="214" cy="330" r="9"/>
<circle class="sc-node" cx="392" cy="146" r="14"/>
<text class="sc-num" x="392" y="150" font-size="11" text-anchor="middle">1</text>
<circle class="sc-node" cx="352" cy="232" r="12"/>
<text class="sc-num" x="352" y="236" font-size="11" text-anchor="middle">2</text>
<circle class="sc-free" cx="446" cy="300" r="13"/>
<text class="sc-num" x="446" y="304" font-size="11" text-anchor="middle">3</text>
<circle class="sc-node" cx="516" cy="208" r="12"/>
<text class="sc-num" x="516" y="212" font-size="11" text-anchor="middle">4</text>
<circle class="sc-node" cx="474" cy="246" r="9"/>
<circle class="sc-node" cx="546" cy="262" r="9"/>
<circle class="sc-node" cx="366" cy="330" r="9"/>
<circle class="sc-node" cx="428" cy="378" r="9"/>
<circle class="sc-node" cx="508" cy="372" r="9"/>
<circle class="sc-node" cx="694" cy="168" r="9"/>
<circle class="sc-node" cx="762" cy="206" r="9"/>
<circle class="sc-node" cx="664" cy="244" r="9"/>
<circle class="sc-node" cx="716" cy="268" r="13"/>
<text class="sc-num" x="716" y="272" font-size="11" text-anchor="middle">5</text>
<circle class="sc-sink" cx="802" cy="300" r="14"/>
<text class="sc-num-inv" x="802" y="304" font-size="11" text-anchor="middle">6</text>
<circle class="sc-node" cx="838" cy="246" r="9"/>
<circle class="sc-node" cx="688" cy="330" r="9"/>
<text class="sc-tag" x="108" y="184" font-size="11" text-anchor="middle" fill="var(--color-accent)">entry point</text>
<text class="sc-tag" x="446" y="334" font-size="11" text-anchor="middle" fill="var(--color-secondary)">free()</text>
<text class="sc-tag" x="802" y="336" font-size="11" text-anchor="middle" fill="var(--color-accent)">sink</text>
<circle class="sc-entry" cx="38" cy="440" r="7"/>
<text class="sc-muted" x="52" y="444" font-size="11.5">entry points</text>
<circle class="sc-free" cx="168" cy="440" r="7"/>
<text class="sc-muted" x="182" y="444" font-size="11.5">release and lifetime operations</text>
<circle class="sc-sink" cx="416" cy="440" r="7"/>
<text class="sc-muted" x="430" y="444" font-size="11.5">sinks</text>
</svg>
</div>
<p><em>Figure 4. Entry points, sinks, and lifetime operations such as the release are not syntactic facts. API and semantic models classify them on the graph before any vulnerability traversal runs.</em></p>
<p>Each analysis follows only the relations relevant to its question. Resolved call and return context stays with the path. So do the branch conditions. Before disclosure, the researcher checks concurrency eligibility, path feasibility, alias precision, and build coverage.</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 470" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="slice-t slice-d">
<title id="slice-t">The traversal keeps only the path that carries the evidence</title>
<desc id="slice-d">A lifetime traversal from the free operation retains the entry point, the governing branch, the release and the later use; the rest of the graph is dropped from the evidence slice.</desc>
<defs>
<marker id="slice-cf" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#d97706"/></marker>
<marker id="slice-dd" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-accent)"/></marker>
<marker id="slice-cl" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-secondary)"/></marker>
<marker id="slice-vu" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#e11d48"/></marker>
<style>
.slice-cf{stroke:#d97706;stroke-width:2.2;fill:none;marker-end:url(#slice-cf)}
.slice-dd{stroke:var(--color-accent);stroke-width:2.2;fill:none;marker-end:url(#slice-dd)}
.slice-cl{stroke:var(--color-secondary);stroke-width:2.4;fill:none;marker-end:url(#slice-cl)}
.slice-vu{stroke:#e11d48;stroke-width:2.6;fill:none;marker-end:url(#slice-vu)}
</style>
</defs>
<rect class="sc-bg" x="1" y="1" width="898" height="468" rx="12"/>
<text class="sc-title" x="32" y="40" font-size="18" font-weight="700">The right analysis, then the slice</text>
<text class="sc-muted" x="32" y="62" font-size="12.5">A lifetime traversal keeps six nodes; everything else leaves the evidence package.</text>
<rect class="sc-panel" x="28" y="96" width="248" height="316" rx="9"/>
<text class="sc-file" x="44" y="122" font-size="12">usb_host_hid.c</text>
<rect class="sc-panel" x="300" y="72" width="300" height="340" rx="9"/>
<text class="sc-file" x="316" y="98" font-size="12">hid_host.c · get_descriptor()</text>
<rect class="sc-panel" x="624" y="112" width="248" height="300" rx="9"/>
<text class="sc-file" x="640" y="138" font-size="12">hid_host.c · transfer()</text>
<path class="sc-ast" d="M121 221 L179 253"/>
<path class="sc-ast" d="M385 161 L360 215"/>
<path class="sc-ast" d="M406 153 L499 200"/>
<path class="sc-ast" d="M363 240 L430 288"/>
<path class="sc-ast" d="M730 273 L782 293"/>
<g class="sc-faint"><path class="sc-ast" d="M85 179 L97 197"/></g>
<g class="sc-faint"><path class="sc-ast" d="M142 137 L94 160"/></g>
<g class="sc-faint"><path class="sc-ast" d="M75 306 L118 335"/></g>
<g class="sc-faint"><path class="sc-ast" d="M144 342 L198 333"/></g>
<g class="sc-faint"><path class="sc-ast" d="M506 217 L486 235"/></g>
<g class="sc-faint"><path class="sc-ast" d="M523 220 L538 248"/></g>
<g class="sc-faint"><path class="sc-ast" d="M375 337 L415 368"/></g>
<g class="sc-faint"><path class="sc-ast" d="M439 377 L492 373"/></g>
<g class="sc-faint"><path class="sc-ast" d="M696 179 L712 248"/></g>
<g class="sc-faint"><path class="sc-ast" d="M772 211 L824 239"/></g>
<g class="sc-faint"><path class="sc-ast" d="M674 249 L698 260"/></g>
<g class="sc-faint"><path class="sc-ast" d="M811 287 L829 259"/></g>
<g class="sc-faint"><path class="sc-ast" d="M685 319 L668 259"/></g>
<path class="slice-cf" d="M121 221 L179 253"/>
<path class="slice-cf" d="M385 161 L360 215"/>
<path class="slice-cf" d="M363 240 L430 288"/>
<path class="slice-cf" d="M455 288 L504 223"/>
<path class="slice-dd" d="M397 161 L439 281"/>
<path class="slice-cl" d="M208 255 Q305 229 374 157"/>
<path class="slice-vu" d="M407 152 Q523 284 697 261"/>
<path class="slice-vu" d="M407 152 Q598 214 782 293"/>
<circle class="sc-node sc-dim" cx="78" cy="168" r="11"/>
<circle class="sc-node sc-dim" cx="152" cy="132" r="9"/>
<circle class="sc-entry" cx="108" cy="214" r="13"/>
<text class="sc-num" x="108" y="218" font-size="11" text-anchor="middle">in</text>
<circle class="sc-node" cx="196" cy="262" r="12"/>
<circle class="sc-node sc-dim" cx="66" cy="300" r="9"/>
<circle class="sc-node sc-dim" cx="132" cy="344" r="10"/>
<circle class="sc-node sc-dim" cx="214" cy="330" r="9"/>
<circle class="sc-node" cx="392" cy="146" r="14"/>
<text class="sc-num" x="392" y="150" font-size="11" text-anchor="middle">1</text>
<circle class="sc-node" cx="352" cy="232" r="12"/>
<text class="sc-num" x="352" y="236" font-size="11" text-anchor="middle">2</text>
<circle class="sc-free" cx="446" cy="300" r="13"/>
<text class="sc-num" x="446" y="304" font-size="11" text-anchor="middle">3</text>
<circle class="sc-node" cx="516" cy="208" r="12"/>
<text class="sc-num" x="516" y="212" font-size="11" text-anchor="middle">4</text>
<circle class="sc-node sc-dim" cx="474" cy="246" r="9"/>
<circle class="sc-node sc-dim" cx="546" cy="262" r="9"/>
<circle class="sc-node sc-dim" cx="366" cy="330" r="9"/>
<circle class="sc-node sc-dim" cx="428" cy="378" r="9"/>
<circle class="sc-node sc-dim" cx="508" cy="372" r="9"/>
<circle class="sc-node sc-dim" cx="694" cy="168" r="9"/>
<circle class="sc-node sc-dim" cx="762" cy="206" r="9"/>
<circle class="sc-node sc-dim" cx="664" cy="244" r="9"/>
<circle class="sc-hit" cx="716" cy="268" r="13"/>
<text class="sc-num" x="716" y="272" font-size="11" text-anchor="middle">5</text>
<circle class="sc-hit" cx="802" cy="300" r="14"/>
<text class="sc-num" x="802" y="304" font-size="11" text-anchor="middle">6</text>
<circle class="sc-node sc-dim" cx="838" cy="246" r="9"/>
<circle class="sc-node sc-dim" cx="688" cy="330" r="9"/>
<text class="sc-tag" x="108" y="184" font-size="11" text-anchor="middle" fill="var(--color-accent)">source</text>
<text class="sc-tag" x="446" y="334" font-size="11" text-anchor="middle" fill="var(--color-secondary)">free</text>
<text class="sc-tag" x="742" y="242" font-size="11" fill="#e11d48">use-after-free</text>
<path class="slice-cf" d="M32 440 H58"/>
<text class="sc-muted" x="66" y="444" font-size="11.5">control flow</text>
<path class="slice-dd" d="M147 440 H173"/>
<text class="sc-muted" x="181" y="444" font-size="11.5">data dependence</text>
<path class="slice-cl" d="M281 440 H307"/>
<text class="sc-muted" x="315" y="444" font-size="11.5">call</text>
<path class="slice-vu" d="M346 440 H372"/>
<text class="sc-muted" x="380" y="444" font-size="11.5">lifetime violation</text>
</svg>
</div>
<p><em>Figure 5. The lifetime traversal starts at the release and keeps the entry point, the governing branch, the reallocation, and the later uses. Those nodes and their edges become the evidence slice; the rest of the graph never reaches the model.</em></p>
<h3 id="5-materialize-the-evidence-slice">5. Materialize the evidence slice</h3>
<p>For each candidate, SecMate collects the source nodes, call chain, control predicates, data or alias edges, and unresolved assumptions needed for review. The local model sees that package, not the repository. It tests a specific vulnerability hypothesis against the extracted path. A researcher then checks the source path, attack preconditions, and exploitability claim before disclosure.</p>
<p>The graph recovers program relations. The analysis selects the relevant path. The model reviews that path. Candidate discovery and path extraction happen before model review. A SecMate researcher validates every claim before it is reported. The model&rsquo;s output is one input to that review.</p>
<p>This is what one such package looks like for the use-after-free presented later in this article:</p>
<div class="evidence-package">
  <div class="evidence-package__head">Evidence package — HID descriptor use-after-free (sanitized)</div>
  <dl class="evidence-package__grid">
    <dt>Hypothesis</dt>
    <dd>use after free of usb_transfer_t through a stale local alias</dd>
    <dt>Source</dt>
    <dd>usb_host_hid / hid_host.c · usb_class_request_get_descriptor()</dd>
    <dt>Call path</dt>
    <dd>enumerate_device()
  → get_report_descriptor()
  → usb_class_request_get_descriptor()</dd>
    <dt>Object</dt>
    <dd>urb_t reached through hid_device->ctrl_xfer, owning its data_buffer</dd>
    <dt>Lifetime</dt>
    <dd><span class="ep-alias">ctrl_xfer (local) aliases the urb_t</span> — captured before the branch
usb_host_transfer_free() — <span class="ep-bad">releases the urb_t and its data_buffer</span>
usb_host_transfer_alloc(&amp;hid_device->ctrl_xfer) — on success the field refers to a new urb_t
<span class="ep-bad">ctrl_xfer->data_buffer — dereference after that lifetime ended</span></dd>
    <dt>Path condition</dt>
    <dd><span class="ep-data">ctrl_size &lt; USB_SETUP_PACKET_SIZE + req->wLength</span> — right side device-controlled</dd>
    <dt>Unresolved</dt>
    <dd>indirect callback target — resolved with medium confidence</dd>
  </dl>
</div>
<p><em>Figure 6. A sanitized evidence package for the HID use-after-free: hypothesis, bounded path, object lifetime, governing condition, and the facts the analysis could not resolve. This package is what the local model reviews, and what the researcher audits afterward.</em></p>
<p>LLMxCPG and <code>codebadger</code> also use CPGs to guide repository investigation <a href="#ref6">[6]</a> <a href="#ref7">[7]</a>.</p>
<h2 id="applying-the-method-to-espressif-usb-host">Applying the Method to Espressif USB Host</h2>
<p>ESP-IDF is Espressif&rsquo;s development framework for its systems-on-chip <a href="#ref10">[10]</a>. The <code>esp-usb</code> repository contains USB host and device class drivers distributed through the ESP Component Registry <a href="#ref11">[11]</a>.</p>
<p>We focused on USB host mode in the HID and UVC class drivers. Espressif documents the USB Host Library as the lowest public-facing API layer of the host stack. Class drivers sit above it and handle class-specific descriptors, transfers, callbacks, and device lifecycle events <a href="#ref12">[12]</a>.</p>
<p>A connected USB device controls the descriptors and lengths consumed during enumeration. It also controls when it disconnects and how it behaves during transfers. That makes the class-driver boundary attacker-controlled even though the attack requires physical access. The findings affect host-side drivers, not Espressif&rsquo;s USB device mode.</p>
<p>The following sections cite the public advisories and fixing commits for the affected versions, vulnerability details, and patches.</p>
<h2 id="the-espressif-findings">The Espressif Findings</h2>
<div class="finding-summary" aria-label="Espressif USB vulnerability summary">
  <dl class="finding-summary__item">
    <div class="finding-summary__field"><dt>CVE</dt><dd><a href="https://github.com/espressif/esp-usb/security/advisories/GHSA-2pm2-62mr-c9x7">CVE-2025-68656</a></dd></div>
    <div class="finding-summary__field"><dt>Component</dt><dd><code>usb_host_hid</code></dd></div>
    <div class="finding-summary__field finding-summary__field--wide"><dt>Analysis problem</dt><dd>Stale alias after transfer reallocation</dd></div>
    <div class="finding-summary__field"><dt>Affected</dt><dd><code>1.0.4</code> and earlier</dd></div>
    <div class="finding-summary__field"><dt>Fixed</dt><dd><code>1.1.0</code></dd></div>
  </dl>
  <dl class="finding-summary__item">
    <div class="finding-summary__field"><dt>CVE</dt><dd><a href="https://github.com/espressif/esp-usb/security/advisories/GHSA-gp8r-qjfr-gqfv">CVE-2025-68657</a></dd></div>
    <div class="finding-summary__field"><dt>Component</dt><dd><code>usb_host_hid</code></dd></div>
    <div class="finding-summary__field finding-summary__field--wide"><dt>Analysis problem</dt><dd>Concurrent teardown of the same transfer</dd></div>
    <div class="finding-summary__field"><dt>Affected</dt><dd><code>1.0.4</code> and earlier</dd></div>
    <div class="finding-summary__field"><dt>Fixed</dt><dd><code>1.1.0</code></dd></div>
  </dl>
  <dl class="finding-summary__item">
    <div class="finding-summary__field"><dt>CVE</dt><dd><a href="https://github.com/espressif/esp-usb/security/advisories/GHSA-g65h-9ggq-9827">CVE-2025-68622</a></dd></div>
    <div class="finding-summary__field"><dt>Component</dt><dd><code>usb_host_uvc</code></dd></div>
    <div class="finding-summary__field finding-summary__field--wide"><dt>Analysis problem</dt><dd>Descriptor length copied into a fixed stack buffer</dd></div>
    <div class="finding-summary__field"><dt>Affected</dt><dd><code>2.3.1</code> and earlier</dd></div>
    <div class="finding-summary__field"><dt>Fixed</dt><dd><code>2.4.0</code></dd></div>
  </dl>
</div>
<p>GitHub classifies all three advisories as Moderate. Their CVSS 3.1 base scores are <code>6.8</code>, <code>6.4</code>, and <code>6.8</code>. The affected and fixed versions above come from the published advisories <a href="#ref8">[8]</a> <a href="#ref13">[13]</a> <a href="#ref15">[15]</a>.</p>
<h3 id="cve-2025-68656-hid-descriptor-use-after-free">CVE-2025-68656: HID Descriptor Use-After-Free</h3>
<p>The first finding shows the method on a concrete lifetime path. During enumeration, a HID device advertises <code>wReport<wbr>Descriptor<wbr>Length</code>. The host uses that value for <code>req-&gt;wLength</code>. If the current control transfer is too small, <code>usb_class_request_<wbr>get_descriptor()</code> frees <code>hid_device-&gt;<wbr>ctrl_xfer</code> and allocates a larger transfer. The local <code>ctrl_xfer</code> pointer was captured before the free and remains unchanged:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="kt">usb_transfer_t</span> <span class="o">*</span><span class="n">ctrl_xfer</span> <span class="o">=</span> <span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 2</span><span class="cl"><span class="k">const</span> <span class="kt">size_t</span> <span class="n">ctrl_size</span> <span class="o">=</span> <span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="o">-&gt;</span><span class="n">data_buffer_size</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl">
</span></span><span class="line"><span class="ln"> 4</span><span class="cl"><span class="k">if</span> <span class="p">(</span><span class="n">ctrl_size</span> <span class="o">&lt;</span> <span class="p">(</span><span class="n">USB_SETUP_PACKET_SIZE</span> <span class="o">+</span> <span class="n">req</span><span class="o">-&gt;</span><span class="n">wLength</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">    <span class="nf">usb_host_transfer_free</span><span class="p">(</span><span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">    <span class="nf">HID_RETURN_ON_ERROR</span><span class="p">(</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">        <span class="nf">usb_host_transfer_alloc</span><span class="p">(</span><span class="n">USB_SETUP_PACKET_SIZE</span> <span class="o">+</span> <span class="n">req</span><span class="o">-&gt;</span><span class="n">wLength</span><span class="p">,</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">                                <span class="mi">0</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="p">),</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">        <span class="s">&#34;Unable to allocate transfer buffer for EP0&#34;</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">
</span></span><span class="line"><span class="ln">12</span><span class="cl"><span class="kt">usb_setup_packet_t</span> <span class="o">*</span><span class="n">setup</span> <span class="o">=</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">    <span class="p">(</span><span class="kt">usb_setup_packet_t</span> <span class="o">*</span><span class="p">)</span><span class="n">ctrl_xfer</span><span class="o">-&gt;</span><span class="n">data_buffer</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl"><span class="n">setup</span><span class="o">-&gt;</span><span class="n">bmRequestType</span> <span class="o">=</span> <span class="n">USB_BM_REQUEST_TYPE_DIR_IN</span> <span class="o">|</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">                       <span class="n">USB_BM_REQUEST_TYPE_TYPE_STANDARD</span> <span class="o">|</span>
</span></span><span class="line"><span class="ln">16</span><span class="cl">                       <span class="n">USB_BM_REQUEST_TYPE_RECIP_INTERFACE</span><span class="p">;</span>
</span></span></code></pre></div><p>The AST contains every statement above. The security evidence is in the relationships between them:</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 470" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="uaf-t uaf-d">
<title id="uaf-t">What the release actually frees, and what the local pointer still refers to</title>
<desc id="uaf-d">The hid_device_t field ctrl_xfer refers to an urb_t, whose transfer.data_buffer refers to a separate heap buffer. usb_host_transfer_free releases both objects. The local ctrl_xfer pointer was captured before the branch and still refers to the released urb_t when the setup packet is written through it.</desc>
<defs>
<marker id="uaf-own" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#8b5cf6"/></marker>
<marker id="uaf-buf" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="var(--color-secondary)"/></marker>
<marker id="uaf-bad" markerWidth="9" markerHeight="7" refX="8" refY="3.5" orient="auto"><path d="M0,0 L9,3.5 L0,7 Z" fill="#e11d48"/></marker>
<style>
.uf-bg{fill:var(--color-bg-card);stroke:var(--color-border);stroke-width:1.4}
.uf-box{fill:var(--color-muted-bg);stroke:color-mix(in srgb,var(--color-text-secondary) 45%,transparent);stroke-width:1.5}
.uf-dead{fill:color-mix(in srgb,#e11d48 6%,var(--color-muted-bg));stroke:#e11d48;stroke-width:1.8;stroke-dasharray:6 4}
.uf-inner{fill:none;stroke:color-mix(in srgb,var(--color-text-secondary) 40%,transparent);stroke-width:1.2}
.uf-hl-own{fill:color-mix(in srgb,#8b5cf6 18%,transparent);stroke:#8b5cf6;stroke-width:1.4;stroke-dasharray:4 3}
.uf-hl-buf{fill:color-mix(in srgb,var(--color-secondary) 16%,transparent);stroke:var(--color-secondary);stroke-width:1.4;stroke-dasharray:4 3}
.uf-stale{fill:color-mix(in srgb,#e11d48 8%,var(--color-muted-bg));stroke:#e11d48;stroke-width:1.8}
.uf-name{fill:var(--color-text);font-family:var(--font-sans,system-ui,sans-serif);font-weight:700}
.uf-f{fill:var(--color-text);font-family:var(--font-mono,ui-monospace,Menlo,monospace);opacity:.92}
.uf-title{fill:var(--color-text);font-family:var(--font-sans,system-ui,sans-serif)}
.uf-muted{fill:var(--color-text-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
.uf-red{fill:var(--ink-red);font-family:var(--font-sans,system-ui,sans-serif)}
.uf-purple{fill:var(--ink-purple);font-family:var(--font-sans,system-ui,sans-serif)}
.uf-cy{fill:var(--color-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
.uf-own{stroke:#8b5cf6;stroke-width:2.2;fill:none;marker-end:url(#uaf-own)}
.uf-buf{stroke:var(--color-secondary);stroke-width:2.2;fill:none;marker-end:url(#uaf-buf)}
.uf-bad{stroke:#e11d48;stroke-width:2.4;fill:none;stroke-dasharray:6 4;marker-end:url(#uaf-bad)}
</style>
</defs>
<rect class="uf-bg" x="1" y="1" width="898" height="468" rx="12"/>
<text class="uf-title" x="32" y="38" font-size="18" font-weight="700">CVE-2025-68656: the release frees two objects, the local pointer refers to one of them</text>
<text class="uf-muted" x="32" y="60" font-size="12.5">Ownership runs left to right. Everything inside the dashed red outline is released by a single call.</text>
<rect class="uf-box" x="32" y="88" width="246" height="182" rx="8"/>
<text class="uf-name" x="155" y="114" font-size="13" text-anchor="middle">hid_device_t</text>
<text class="uf-f" x="44" y="142" font-size="10">SemaphoreHandle_t device_busy</text>
<text class="uf-f" x="44" y="164" font-size="10">SemaphoreHandle_t ctrl_xfer_done</text>
<rect class="uf-hl-own" x="40" y="172" width="230" height="22" rx="4"/>
<text class="uf-f" x="44" y="187" font-size="10">usb_transfer_t *ctrl_xfer</text>
<text class="uf-f" x="44" y="216" font-size="10">usb_device_handle_t dev_hdl</text>
<text class="uf-f" x="44" y="238" font-size="10">uint8_t dev_addr</text>
<rect class="uf-dead" x="326" y="76" width="266" height="248" rx="8"/>
<text class="uf-name" x="459" y="102" font-size="13" text-anchor="middle">urb_t</text>
<text class="uf-f" x="338" y="128" font-size="10">TAILQ_ENTRY tailq_entry</text>
<text class="uf-f" x="338" y="148" font-size="10">void *hcd_ptr</text>
<text class="uf-f" x="338" y="168" font-size="10">uint32_t hcd_var</text>
<text class="uf-f" x="338" y="188" font-size="10">void *usb_host_client</text>
<rect class="uf-inner" x="334" y="200" width="250" height="112" rx="6"/>
<text class="uf-muted" x="344" y="216" font-size="9.5">usb_transfer_t transfer</text>
<rect class="uf-hl-buf" x="340" y="224" width="238" height="22" rx="4"/>
<text class="uf-f" x="344" y="239" font-size="10">uint8_t *data_buffer</text>
<text class="uf-f" x="344" y="262" font-size="10">size_t data_buffer_size</text>
<text class="uf-f" x="344" y="282" font-size="10">int num_bytes</text>
<text class="uf-f" x="344" y="302" font-size="10">usb_transfer_cb_t callback</text>
<rect class="uf-dead" x="646" y="140" width="218" height="120" rx="8"/>
<text class="uf-name" x="755" y="168" font-size="13" text-anchor="middle">data_buffer</text>
<text class="uf-f" x="660" y="196" font-size="10">uint8_t[]</text>
<text class="uf-f" x="660" y="220" font-size="10">initial: 512 B</text>
<text class="uf-f" x="660" y="242" font-size="10">realloc: align(8 + N)</text>
<path class="uf-own" d="M270 183 C296 183 300 172 320 168"/>
<text class="uf-purple" x="292" y="215" font-size="10.5" text-anchor="middle">field</text>
<path class="uf-buf" d="M578 235 C608 235 614 214 640 206"/>
<text class="uf-cy" x="606" y="256" font-size="10.5" text-anchor="middle">buffer</text>
<rect class="uf-stale" x="32" y="330" width="246" height="66" rx="8"/>
<text class="uf-f" x="46" y="356" font-size="11">ctrl_xfer (local)</text>
<text class="uf-red" x="46" y="378" font-size="10.5">captured before the branch</text>
<path class="uf-bad" d="M278 356 C330 356 356 348 388 330"/>
<text class="uf-red" x="300" y="410" font-size="10.5">still refers to the released urb_t</text>
<text class="uf-red" x="868" y="300" font-size="11.5" font-weight="700" text-anchor="end">usb_host_transfer_free() releases both</text>
<text class="uf-f" x="868" y="322" font-size="9.5" text-anchor="end">heap_caps_free(urb-&gt;transfer.data_buffer);</text>
<text class="uf-f" x="868" y="340" font-size="9.5" text-anchor="end">heap_caps_free(urb);</text>
<text class="uf-muted" x="32" y="432" font-size="11">On success, reallocation replaces <tspan class="uf-f" font-size="10.5">hid_device-&gt;ctrl_xfer</tspan> but not the local copy. On error, the function returns before</text>
<text class="uf-muted" x="32" y="450" font-size="11">this dereference; on success, <tspan class="uf-f" font-size="10.5">ctrl_xfer-&gt;data_buffer</tspan> reaches memory whose lifetime has ended.</text>
</svg>
</div>
<p><em>Figure 7. A single <code>usb_host_transfer_free()</code> releases both the <code>urb_t</code> and the <code>data_buffer</code> it owns. The local <code>ctrl_xfer</code> pointer was read from the field before the branch. If reallocation succeeds, the field receives a new transfer but the local pointer still refers to the released <code>urb_t</code> when the setup packet is written through it; if allocation fails, the error path returns before that write.</em></p>
<p>The function then writes the USB setup packet through <code>ctrl_xfer-&gt;data_buffer</code>. Espressif&rsquo;s advisory describes attacker-controlled writes to freed heap memory, arbitrary memory corruption, and potential code execution <a href="#ref8">[8]</a>.</p>
<p>Espressif&rsquo;s fix validates the requested length, performs any required reallocation, and only then reads the field into the local pointer <a href="#ref9">[9]</a>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln"> 1</span><span class="cl"><span class="k">if</span> <span class="p">(</span><span class="n">req</span><span class="o">-&gt;</span><span class="n">wLength</span> <span class="o">&gt;</span> <span class="n">HID_MAX_REPORT_DESC_LEN</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln"> 2</span><span class="cl">    <span class="k">return</span> <span class="n">ESP_ERR_INVALID_SIZE</span><span class="p">;</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">
</span></span><span class="line"><span class="ln"> 5</span><span class="cl"><span class="c1">// Argument checks and lock acquisition omitted.
</span></span></span><span class="line"><span class="ln"> 6</span><span class="cl"><span class="c1"></span><span class="k">if</span> <span class="p">(</span><span class="n">ctrl_size</span> <span class="o">&lt;</span> <span class="n">required_size</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">    <span class="nf">usb_host_transfer_free</span><span class="p">(</span><span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="p">);</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nf">usb_host_transfer_alloc</span><span class="p">(</span><span class="n">required_size</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">                                <span class="o">&amp;</span><span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="p">)</span> <span class="o">!=</span> <span class="n">ESP_OK</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">        <span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">        <span class="nf">hid_device_unlock</span><span class="p">(</span><span class="n">hid_device</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">        <span class="k">return</span> <span class="n">ESP_ERR_NO_MEM</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">13</span><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="ln">15</span><span class="cl">
</span></span><span class="line"><span class="ln">16</span><span class="cl"><span class="kt">usb_transfer_t</span> <span class="o">*</span><span class="n">ctrl_xfer</span> <span class="o">=</span> <span class="n">hid_device</span><span class="o">-&gt;</span><span class="n">ctrl_xfer</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">17</span><span class="cl"><span class="kt">usb_setup_packet_t</span> <span class="o">*</span><span class="n">setup</span> <span class="o">=</span>
</span></span><span class="line"><span class="ln">18</span><span class="cl">    <span class="p">(</span><span class="kt">usb_setup_packet_t</span> <span class="o">*</span><span class="p">)</span><span class="n">ctrl_xfer</span><span class="o">-&gt;</span><span class="n">data_buffer</span><span class="p">;</span>
</span></span></code></pre></div><p>The reported stale alias disappears when the alias is created after the field replacement. The same patch caps report descriptors at 2048 bytes, handles allocation failure, and enables tests for large report descriptors. This is the finding we took into the exploitation work.</p>
<h3 id="cve-2025-68657-hid-close-path-race">CVE-2025-68657: HID Close-Path Race</h3>
<p>The second HID issue is in teardown rather than descriptor parsing. USB event handling and application code can both reach <code>hid_host_device_close()</code> while sharing the same <code>hid_iface_t</code> state. Existing FreeRTOS critical sections and <code>device_busy</code> serialize parts of this path, but they do not make the READY-state check and transfer release one atomic operation across both callers. Two callers can therefore proceed to free the same <code>usb_transfer_t</code> <a href="#ref13">[13]</a>.</p>
<p>This requires evidence from two execution paths. A single-function pattern can find the release operation, but it cannot establish competing ownership or determine whether the existing synchronization covers the state-check-to-release transition.</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 620" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="race-title race-desc">
  <title id="race-title">Two potentially concurrent teardown paths over the same transfer</title>
  <desc id="race-desc">The USB event task and the application task can both enter the close path, both observe the READY state, and both release the same transfer object. Existing synchronization does not make the region between the check and the release atomic across both callers in the vulnerable version. The fix holds an open_close_mutex across the check, interface removal, and release.</desc>
  <defs>
    <marker id="rc-amber" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto"><path d="M0,0 L10,4 L0,8 Z" fill="#d97706"/></marker>
    <marker id="rc-red" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto"><path d="M0,0 L10,4 L0,8 Z" fill="#e11d48"/></marker>
    <style>
      .rc-bg{fill:var(--color-bg-card);stroke:var(--color-border);stroke-width:1.4}
      .rc-lane{fill:none;stroke:var(--color-border);stroke-width:1.4;stroke-dasharray:4 4}
      .rc-node{fill:var(--color-muted-bg);stroke:color-mix(in srgb,var(--color-text-secondary) 45%,transparent);stroke-width:1.5}
      .rc-conc{fill:var(--color-muted-bg);stroke:color-mix(in srgb,var(--color-text-secondary) 55%,transparent);stroke-width:1.6}
      .rc-bad{fill:color-mix(in srgb,#e11d48 12%,var(--color-muted-bg));stroke:#e11d48;stroke-width:1.8}
      .rc-fix{fill:color-mix(in srgb,var(--color-accent) 12%,var(--color-muted-bg));stroke:var(--color-accent);stroke-width:1.6}
      .rc-shared{fill:color-mix(in srgb,#8b5cf6 12%,var(--color-muted-bg));stroke:#8b5cf6;stroke-width:1.6}
      .rc-text{fill:var(--color-text);font-family:var(--font-mono,ui-monospace,Menlo,monospace)}
      .rc-title{fill:var(--color-text);font-family:var(--font-sans,system-ui,sans-serif)}
      .rc-muted{fill:var(--color-text-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
      .rc-red{fill:var(--ink-red);font-family:var(--font-sans,system-ui,sans-serif)}
            .rc-purple{fill:var(--ink-purple);font-family:var(--font-sans,system-ui,sans-serif)}
      .rc-cf{stroke:#d97706;stroke-width:2;fill:none;marker-end:url(#rc-amber)}
      .rc-danger{stroke:#e11d48;stroke-width:2.5;fill:none;marker-end:url(#rc-red)}
      .rc-nohb{stroke:#e11d48;stroke-width:2;stroke-dasharray:8 5;fill:none}
    </style>
  </defs>
  <rect class="rc-bg" x="1" y="1" width="898" height="618" rx="12"/>
  <text class="rc-title" x="36" y="42" font-size="20" font-weight="700">CVE-2025-68657: two teardown paths, one transfer</text>
  <text class="rc-muted" x="36" y="66" font-size="13">Both lanes may execute in parallel; existing synchronization does not cover the whole transition.</text>
  <rect class="rc-lane" x="52" y="90" width="330" height="300" rx="8"/>
  <rect class="rc-lane" x="518" y="90" width="330" height="300" rx="8"/>
  <text class="rc-title" x="217" y="116" font-size="13" font-weight="700" text-anchor="middle">USB event task</text>
  <text class="rc-title" x="683" y="116" font-size="13" font-weight="700" text-anchor="middle">Application task</text>
  <rect class="rc-conc" x="82" y="134" width="270" height="46" rx="7"/>
  <text class="rc-text" x="217" y="162" font-size="12" text-anchor="middle">hid_host_device_close()</text>
  <rect class="rc-conc" x="548" y="134" width="270" height="46" rx="7"/>
  <text class="rc-text" x="683" y="162" font-size="12" text-anchor="middle">hid_host_device_close()</text>
  <path class="rc-cf" d="M217 180 V212"/>
  <path class="rc-cf" d="M683 180 V212"/>
  <rect class="rc-node" x="82" y="216" width="270" height="46" rx="7"/>
  <text class="rc-text" x="217" y="244" font-size="12" text-anchor="middle">state == READY</text>
  <rect class="rc-node" x="548" y="216" width="270" height="46" rx="7"/>
  <text class="rc-text" x="683" y="244" font-size="12" text-anchor="middle">state == READY</text>
  <path class="rc-cf" d="M217 262 V300"/>
  <path class="rc-cf" d="M683 262 V300"/>
  <rect class="rc-bad" x="82" y="304" width="270" height="52" rx="7"/>
  <text class="rc-text" x="217" y="326" font-size="12" text-anchor="middle">free(transfer T)</text>
  <text class="rc-red" x="217" y="346" font-size="11" text-anchor="middle">releases the shared object</text>
  <rect class="rc-bad" x="548" y="304" width="270" height="52" rx="7"/>
  <text class="rc-text" x="683" y="326" font-size="12" text-anchor="middle">free(transfer T)</text>
  <text class="rc-red" x="683" y="346" font-size="11" text-anchor="middle">releases the shared object</text>
  <path class="rc-nohb" d="M382 240 H518"/>
  <text class="rc-red" x="450" y="232" font-size="11" text-anchor="middle">existing synchronization</text>
  <text class="rc-red" x="450" y="262" font-size="11" text-anchor="middle">does not cover the full transition</text>
  <rect class="rc-shared" x="330" y="404" width="240" height="52" rx="7"/>
  <text class="rc-text" x="450" y="426" font-size="12" text-anchor="middle">shared usb_transfer_t T</text>
  <text class="rc-purple" x="450" y="446" font-size="11" text-anchor="middle">same abstract object in both lanes</text>
  <path class="rc-danger" d="M217 356 C217 392 300 412 324 424"/>
  <path class="rc-danger" d="M683 356 C683 392 600 412 576 424"/>
  <text class="rc-red" x="450" y="482" font-size="12" text-anchor="middle" font-weight="700">second release is a double free</text>
  <rect class="rc-fix" x="82" y="508" width="736" height="86" rx="7"/>
  <text class="rc-title" x="102" y="532" font-size="12" font-weight="700">Fix: one lock covers check, removal, and release</text>
  <text class="rc-text" x="102" y="554" font-size="12">lock(open_close_mutex)  →  check READY  →  remove interface  →  release transfer  →  unlock</text>
  <text class="rc-muted" x="102" y="576" font-size="11">The mutex establishes the happens-before relation the vulnerable version was missing.</text>
</svg>
</div>
<p><em>Figure 8. The analysis needs evidence of three things: two paths that may execute in parallel, the same abstract transfer object reached from both, and a gap in the synchronization of the state-check-to-release transition. The fix adds a mutex that covers that transition.</em></p>
<p>Espressif&rsquo;s fix adds an <code>open_close_mutex</code> and holds it across the open and close paths, including the state check and interface removal <a href="#ref14">[14]</a>. The advisory also records an important practical limit: the READY-to-free window is estimated at 0.1 to 1 microsecond, while detach handling and application reaction occur on a millisecond scale. The proof of concept widened that window to demonstrate the issue deterministically <a href="#ref13">[13]</a>.</p>
<h3 id="cve-2025-68622-uvc-descriptor-stack-overflow">CVE-2025-68622: UVC Descriptor Stack Overflow</h3>
<p>The UVC finding is a direct bounds path in <code>print_vs_frame_mjpeg_desc()</code>. When configuration-descriptor printing is enabled, the function reads the device-controlled <code>bLength</code> and copies that many bytes into <code>raw_desc[25]</code>, a 100-byte stack buffer:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="ln">1</span><span class="cl"><span class="kt">uint32_t</span> <span class="n">raw_desc</span><span class="p">[</span><span class="mi">25</span><span class="p">];</span>
</span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="kt">uint32_t</span> <span class="n">desc_size</span> <span class="o">=</span> <span class="p">((</span><span class="k">const</span> <span class="kt">uvc_frame_desc_t</span> <span class="o">*</span><span class="p">)</span><span class="n">_desc</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">bLength</span><span class="p">;</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="nf">memcpy</span><span class="p">(</span><span class="n">raw_desc</span><span class="p">,</span> <span class="n">_desc</span><span class="p">,</span> <span class="n">desc_size</span><span class="p">);</span>
</span></span></code></pre></div><p>A UVC frame descriptor can contain a variable-length frame-interval array. The vulnerable code did not compare <code>desc_size</code> with <code>sizeof(raw_desc)</code> before the copy. A malicious camera could therefore corrupt the stack during enumeration when <code>CONFIG_UVC_<wbr>PRINTF_<wbr>CONFIGURATION_<wbr>DESCRIPTOR</code> was enabled <a href="#ref15">[15]</a>.</p>
<div class="figure-scroll" role="region" tabindex="0" aria-label="Figure, scrollable">
<svg viewBox="0 0 900 560" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="ovf-title ovf-desc">
  <title id="ovf-title">The bounds constraint for the UVC descriptor stack overflow</title>
  <desc id="ovf-desc">A device-controlled bLength becomes desc_size and reaches memcpy as the copy length. The destination raw_desc is a fixed 25-element array of 32-bit words, 100 bytes. The required guard comparing desc_size with the destination size is absent, and the whole path exists only when descriptor printing is enabled in the build configuration.</desc>
  <defs>
    <marker id="ov-gray" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto"><path d="M0,0 L10,4 L0,8 Z" fill="var(--color-text-secondary)"/></marker>
    <marker id="ov-lime" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto"><path d="M0,0 L10,4 L0,8 Z" fill="var(--color-accent)"/></marker>
    <style>
      .ov-bg{fill:var(--color-bg-card);stroke:var(--color-border);stroke-width:1.4}
      .ov-node{fill:var(--color-muted-bg);stroke:color-mix(in srgb,var(--color-text-secondary) 45%,transparent);stroke-width:1.5}
      .ov-input{fill:var(--color-muted-bg);stroke:var(--color-accent);stroke-width:2.2}
      .ov-bad{fill:color-mix(in srgb,#e11d48 12%,var(--color-muted-bg));stroke:#e11d48;stroke-width:1.8}
      .ov-guard{fill:var(--color-muted-bg);stroke:#e11d48;stroke-width:1.6;stroke-dasharray:6 4}
      .ov-build{fill:color-mix(in srgb,#d97706 10%,var(--color-muted-bg));stroke:#d97706;stroke-width:1.5}
      .ov-text{fill:var(--color-text);font-family:var(--font-mono,ui-monospace,Menlo,monospace)}
      .ov-title{fill:var(--color-text);font-family:var(--font-sans,system-ui,sans-serif)}
      .ov-muted{fill:var(--color-text-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
      .ov-red{fill:var(--ink-red);font-family:var(--font-sans,system-ui,sans-serif)}
      .ov-amber{fill:var(--ink-amber);font-family:var(--font-sans,system-ui,sans-serif)}
      .ov-cyantxt{fill:var(--color-secondary);font-family:var(--font-sans,system-ui,sans-serif)}
      .ov-cf{stroke:var(--color-text-secondary);stroke-width:2;fill:none;marker-end:url(#ov-gray)}
      .ov-data{stroke:var(--color-accent);stroke-width:2;stroke-dasharray:5 4;fill:none;marker-end:url(#ov-lime)}
    </style>
  </defs>
  <rect class="ov-bg" x="1" y="1" width="898" height="558" rx="12"/>
  <text class="ov-title" x="36" y="42" font-size="20" font-weight="700">CVE-2025-68622: copy length against destination extent</text>
  <text class="ov-muted" x="36" y="66" font-size="13">The bug is the missing relation between the two sides of the copy.</text>
  <rect class="ov-build" x="36" y="92" width="828" height="42" rx="7"/>
  <text class="ov-text" x="56" y="119" font-size="12">CONFIG_UVC_PRINTF_CONFIGURATION_DESCRIPTOR = y</text>
  <text class="ov-amber" x="600" y="119" font-size="11">build condition — path exists only here</text>
  <text class="ov-muted" x="36" y="176" font-size="11" font-weight="700">SOURCE → SINK</text>
  <rect class="ov-input" x="36" y="190" width="230" height="56" rx="7"/>
  <text class="ov-text" x="56" y="214" font-size="12">descriptor.bLength</text>
  <text class="ov-muted" x="56" y="234" font-size="11">device-controlled</text>
  <path class="ov-data" d="M266 218 H316"/>
  <rect class="ov-node" x="320" y="190" width="180" height="56" rx="7"/>
  <text class="ov-text" x="410" y="214" font-size="12" text-anchor="middle">desc_size</text>
  <text class="ov-muted" x="410" y="234" font-size="11" text-anchor="middle">copy length</text>
  <path class="ov-data" d="M500 218 H550"/>
  <rect class="ov-bad" x="554" y="184" width="310" height="68" rx="7"/>
  <text class="ov-text" x="574" y="208" font-size="12">memcpy(raw_desc, _desc, desc_size)</text>
  <text class="ov-red" x="574" y="230" font-size="11">copy length is not bounded by the stack buffer</text>
  <text class="ov-muted" x="36" y="300" font-size="11" font-weight="700">DESTINATION EXTENT</text>
  <rect class="ov-node" x="36" y="314" width="230" height="76" rx="7"/>
  <text class="ov-text" x="56" y="338" font-size="12">uint32_t raw_desc[25]</text>
  <text class="ov-muted" x="56" y="358" font-size="11">25 × sizeof(uint32_t)</text>
  <text class="ov-muted" x="56" y="376" font-size="11">= 100 bytes of stack storage</text>
  <path class="ov-cf" d="M266 352 C400 352 480 300 606 258"/>
  <text class="ov-muted" x="410" y="330" font-size="11">bounds the destination</text>
  <rect class="ov-guard" x="330" y="410" width="534" height="100" rx="7"/>
  <text class="ov-title" x="350" y="436" font-size="12" font-weight="700">The predicate that decides the outcome</text>
  <text class="ov-text" x="350" y="462" font-size="12">required:</text><text class="ov-text" x="470" y="462" font-size="12">desc_size &lt;= sizeof(raw_desc)</text>
  <text class="ov-text" x="350" y="488" font-size="12">observed on this path:</text><text class="ov-red" x="520" y="488" font-size="12" font-weight="700">no applicable bound</text>
  <rect class="ov-node" x="36" y="410" width="270" height="100" rx="7"/>
  <text class="ov-title" x="56" y="436" font-size="12" font-weight="700">What the analysis must recover</text>
  <text class="ov-muted" x="56" y="458" font-size="11">the untrusted value and its flow</text>
  <text class="ov-muted" x="56" y="476" font-size="11">the destination extent</text>
  <text class="ov-muted" x="56" y="494" font-size="11">every guard on the path between them</text>
</svg>
</div>
<p><em>Figure 9. A bounds finding appears when a device-controlled copy length is not checked against the destination extent on the analyzed path. Here the destination holds 100 bytes and no predicate on that path relates the two. The build condition is part of the evidence because the vulnerable path is compiled only when descriptor printing is enabled.</em></p>
<p>Espressif fixed the issue in commit <code>77a38b1</code> by removing the temporary stack copy and reading the descriptor directly. The commit applies the same change to both MJPEG and frame-based descriptor printers <a href="#ref16">[16]</a>.</p>
<h2 id="fixes">Fixes</h2>
<p>Users of the affected components should update <code>usb_host_hid</code> to <code>1.1.0</code> or later and <code>usb_host_uvc</code> to <code>2.4.0</code> or later. Products that vendor or fork these components should verify that the three fixing commits are present rather than relying only on package metadata.</p>
<p>The three findings also show why one generic code excerpt is not enough for automated vulnerability research. The UVC overflow needs a source, destination extent, and missing bound. The HID use-after-free needs object identity across an alias, free, field replacement, and later use. The close-path race needs two potentially concurrent teardown paths over the same shared object and the synchronization governing their state-check-to-release transition.</p>
<p>Static analysis identifies the stale write in <code>CVE-2025-68656</code> and reconstructs the device-controlled path to it. Turning that into a working exploit asked a different set of questions: allocator behavior, heap reuse, and how much a malicious USB device actually controls on the ESP32 target. That is where the analysis stops and the target-specific work begins.</p>
<h2 id="references">References</h2>
<ul>
<li>
<p><a id="ref1"></a>[1] OpenAI. &ldquo;Introducing gpt-oss.&rdquo; August 5, 2025. <a href="https://openai.com/index/introducing-gpt-oss/" rel="noopener noreferrer" target="_blank">Product and model specifications</a></p>
</li>
<li>
<p><a id="ref2"></a>[2] Mark Weiser. &ldquo;Program Slicing.&rdquo; <em>IEEE Transactions on Software Engineering</em>, 1984. <a href="https://doi.org/10.1109/TSE.1984.5010248" rel="noopener noreferrer" target="_blank">DOI</a></p>
</li>
<li>
<p><a id="ref3"></a>[3] Jeanne Ferrante, Karl J. Ottenstein, and Joe D. Warren. &ldquo;The Program Dependence Graph and Its Use in Optimization.&rdquo; <em>ACM Transactions on Programming Languages and Systems</em>, 1987. <a href="https://doi.org/10.1145/24039.24041" rel="noopener noreferrer" target="_blank">DOI</a></p>
</li>
<li>
<p><a id="ref4"></a>[4] Thomas Reps, Susan Horwitz, and Mooly Sagiv. &ldquo;Precise Interprocedural Dataflow Analysis via Graph Reachability.&rdquo; <em>POPL</em>, 1995. <a href="https://doi.org/10.1145/199448.199462" rel="noopener noreferrer" target="_blank">DOI</a></p>
</li>
<li>
<p><a id="ref5"></a>[5] Fabian Yamaguchi, Nico Golde, Daniel Arp, and Konrad Rieck. &ldquo;Modeling and Discovering Vulnerabilities with Code Property Graphs.&rdquo; <em>IEEE Symposium on Security and Privacy</em>, 2014. <a href="https://www.ieee-security.org/TC/SP2014/papers/ModelingandDiscoveringVulnerabilitieswithCodePropertyGraphs.pdf" rel="noopener noreferrer" target="_blank">Paper</a></p>
</li>
<li>
<p><a id="ref6"></a>[6] Ahmed Lekssays, Hamza Mouhcine, Khang Tran, Ting Yu, and Issa Khalil. &ldquo;LLMxCPG: Context-Aware Vulnerability Detection Through Code Property Graph-Guided Large Language Models.&rdquo; <em>34th USENIX Security Symposium</em>, 2025. <a href="https://www.usenix.org/conference/usenixsecurity25/presentation/lekssays" rel="noopener noreferrer" target="_blank">Paper and presentation</a></p>
</li>
<li>
<p><a id="ref7"></a>[7] Ahmed Lekssays. &ldquo;Bridging Code Property Graphs and Language Models for Program Analysis.&rdquo; <em>Software Vulnerability Management Workshop @ ICSE 2026</em>. <a href="https://arxiv.org/abs/2603.24837" rel="noopener noreferrer" target="_blank">Paper</a></p>
</li>
<li>
<p><a id="ref8"></a>[8] Espressif. &ldquo;USB Host HID Descriptor Use-After-Free Vulnerability.&rdquo; <a href="https://github.com/espressif/esp-usb/security/advisories/GHSA-2pm2-62mr-c9x7" rel="noopener noreferrer" target="_blank">GHSA-2pm2-62mr-c9x7</a></p>
</li>
<li>
<p><a id="ref9"></a>[9] Espressif. &ldquo;Changed the handling of reallocating ctrl_xfer buffer on large report descriptors&rdquo; (<code>81b37c9</code>, November 25, 2025). <a href="https://github.com/espressif/esp-usb/commit/81b37c96593c0bec92ef14c6ee6bf8cab8d8f660" rel="noopener noreferrer" target="_blank">Fix commit</a></p>
</li>
<li>
<p><a id="ref10"></a>[10] Espressif. &ldquo;Espressif IoT Development Framework.&rdquo; <a href="https://github.com/espressif/esp-idf" rel="noopener noreferrer" target="_blank">Repository</a></p>
</li>
<li>
<p><a id="ref11"></a>[11] Espressif. &ldquo;Espressif ESP-USB.&rdquo; <a href="https://github.com/espressif/esp-usb" rel="noopener noreferrer" target="_blank">Repository</a></p>
</li>
<li>
<p><a id="ref12"></a>[12] Espressif. &ldquo;USB Host.&rdquo; <em>ESP-IDF Programming Guide</em>. <a href="https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-reference/peripherals/usb_host.html" rel="noopener noreferrer" target="_blank">Documentation</a></p>
</li>
<li>
<p><a id="ref13"></a>[13] Espressif. &ldquo;Double-Free Race Condition in USB Host HID Device Close Path.&rdquo; <a href="https://github.com/espressif/esp-usb/security/advisories/GHSA-gp8r-qjfr-gqfv" rel="noopener noreferrer" target="_blank">GHSA-gp8r-qjfr-gqfv</a></p>
</li>
<li>
<p><a id="ref14"></a>[14] Espressif. &ldquo;Fixed race condition in hid_host_device_close()&rdquo; (<code>cd28106</code>, January 9, 2026). <a href="https://github.com/espressif/esp-usb/commit/cd28106e9f72ac2719682c06f94601f9f034390b" rel="noopener noreferrer" target="_blank">Fix commit</a></p>
</li>
<li>
<p><a id="ref15"></a>[15] Espressif. &ldquo;Stack buffer overflow in UVC descriptor printing.&rdquo; <a href="https://github.com/espressif/esp-usb/security/advisories/GHSA-g65h-9ggq-9827" rel="noopener noreferrer" target="_blank">GHSA-g65h-9ggq-9827</a></p>
</li>
<li>
<p><a id="ref16"></a>[16] Espressif. &ldquo;Fixed potential buffer overflow in descriptor printing&rdquo; (<code>77a38b1</code>, November 21, 2025). <a href="https://github.com/espressif/esp-usb/commit/77a38b15a17f6e3c7aeb620eb4aeaf61d5194cc0" rel="noopener noreferrer" target="_blank">Fix commit</a></p>
</li>
<li>
<p><a id="ref17"></a>[17] The Code Property Graph specification. &ldquo;Overlays.&rdquo; <a href="https://cpg.joern.io/" rel="noopener noreferrer" target="_blank">Specification</a></p>
</li>
<li>
<p><a id="ref18"></a>[18] Clang. &ldquo;JSON Compilation Database Format Specification.&rdquo; <a href="https://clang.llvm.org/docs/JSONCompilationDatabase.html" rel="noopener noreferrer" target="_blank">Documentation</a></p>
</li>
<li>
<p><a id="ref19"></a>[19] Anthropic. &ldquo;Assessing Claude Mythos Preview’s cybersecurity capabilities.&rdquo; April 2026. <a href="https://www.anthropic.com/research/mythos-preview" rel="noopener noreferrer" target="_blank">Research</a></p>
</li>
<li>
<p><a id="ref20"></a>[20] Anthropic. &ldquo;How Claude marks AI-generated content.&rdquo; <a href="https://support.claude.com/en/articles/16266773-how-claude-marks-ai-generated-content" rel="noopener noreferrer" target="_blank">Support documentation</a></p>
</li>
</ul>
<hr>
<p><em>The SecMate Team</em></p>
]]></content:encoded><media:content url="https://blog.secmate.dev/images/og_image.jpg" medium="image"/></item></channel></rss>