Add 300 CheckerBench tasks, dataset card, and restoration tools (part 6)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/csa159/pair_163861/task_prompt.md +377 -0
- tasks/csa159/pair_163978/checker_template.cpp +98 -0
- tasks/csa159/pair_163978/config.json +19 -0
- tasks/csa159/pair_163978/patch.diff +49 -0
- tasks/csa159/pair_163978/post_functions.txt +61 -0
- tasks/csa159/pair_163978/pre_functions.txt +53 -0
- tasks/csa159/pair_163978/task_prompt.md +381 -0
- tasks/csa159/pair_164140/checker_template.cpp +98 -0
- tasks/csa159/pair_164140/config.json +19 -0
- tasks/csa159/pair_164140/patch.diff +15 -0
- tasks/csa159/pair_164140/post_functions.txt +328 -0
- tasks/csa159/pair_164140/pre_functions.txt +328 -0
- tasks/csa159/pair_164140/task_prompt.md +380 -0
- tasks/csa159/pair_164279/checker_template.cpp +98 -0
- tasks/csa159/pair_164279/config.json +19 -0
- tasks/csa159/pair_164279/patch.diff +21 -0
- tasks/csa159/pair_164279/post_functions.txt +62 -0
- tasks/csa159/pair_164279/pre_functions.txt +52 -0
- tasks/csa159/pair_164279/task_prompt.md +318 -0
- tasks/csa159/pair_164624/checker_template.cpp +98 -0
- tasks/csa159/pair_164624/config.json +19 -0
- tasks/csa159/pair_164624/patch.diff +19 -0
- tasks/csa159/pair_164624/post_functions.txt +44 -0
- tasks/csa159/pair_164624/pre_functions.txt +39 -0
- tasks/csa159/pair_164624/task_prompt.md +376 -0
- tasks/csa159/pair_164760/checker_template.cpp +98 -0
- tasks/csa159/pair_164760/config.json +19 -0
- tasks/csa159/pair_164760/patch.diff +14 -0
- tasks/csa159/pair_164760/post_functions.txt +54 -0
- tasks/csa159/pair_164760/pre_functions.txt +57 -0
- tasks/csa159/pair_164760/task_prompt.md +318 -0
- tasks/csa159/pair_164920/checker_template.cpp +98 -0
- tasks/csa159/pair_164920/config.json +19 -0
- tasks/csa159/pair_164920/patch.diff +12 -0
- tasks/csa159/pair_164920/post_functions.txt +40 -0
- tasks/csa159/pair_164920/pre_functions.txt +39 -0
- tasks/csa159/pair_164920/task_prompt.md +381 -0
- tasks/csa159/pair_164974/checker_template.cpp +98 -0
- tasks/csa159/pair_164974/config.json +19 -0
- tasks/csa159/pair_164974/patch.diff +35 -0
- tasks/csa159/pair_164974/post_functions.txt +43 -0
- tasks/csa159/pair_164974/pre_functions.txt +52 -0
- tasks/csa159/pair_164974/task_prompt.md +370 -0
- tasks/csa159/pair_165542/checker_template.cpp +98 -0
- tasks/csa159/pair_165542/config.json +19 -0
- tasks/csa159/pair_165542/patch.diff +66 -0
- tasks/csa159/pair_165542/post_functions.txt +38 -0
- tasks/csa159/pair_165542/pre_functions.txt +58 -0
- tasks/csa159/pair_165542/task_prompt.md +382 -0
- tasks/csa159/pair_165550/checker_template.cpp +98 -0
tasks/csa159/pair_163861/task_prompt.md
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `interprocedural_dataflow`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- The failed rollout used a syntax-only AST pattern and therefore did not establish the cross-function failure condition: an allocation failure in the xa_store path can leave xarray metadata indicating non-empty while no entry is enumerable.
|
| 330 |
+
- Matching every direct callee whose name ends in _empty treated unrelated list, queue, and project-specific predicates as if they shared xa_empty's failure semantics.
|
| 331 |
+
- Odd negation parity inside a WARN/BUG expansion proves only expression shape; it does not prove that the affected xarray state can feasibly reach the teardown assertion.
|
| 332 |
+
- Refinement remained feedback_required, the semantic mechanism was rated inadequate, and the semantic score stayed below threshold despite successful differential detection.
|
| 333 |
+
|
| 334 |
+
### Preserve from prior rollouts
|
| 335 |
+
|
| 336 |
+
- Preserve successful compile, before/after validation, and code verification.
|
| 337 |
+
- Preserve objective eligibility gate G6.
|
| 338 |
+
- Preserve process quality at or above the configured threshold.
|
| 339 |
+
- Do not introduce patch-anchor dependence.
|
| 340 |
+
- Do not introduce patch-local hardcoding.
|
| 341 |
+
|
| 342 |
+
### Required semantic proof
|
| 343 |
+
|
| 344 |
+
- Establish that a feasible allocation-error or partial-completion path associated with xa_store can produce an xarray whose head metadata is non-NULL while no actual entry is enumerable.
|
| 345 |
+
- Establish that this exceptional xarray fact propagates across the relevant function boundaries to the same abstract xarray object inspected during teardown.
|
| 346 |
+
- Establish that xa_empty on that object can evaluate false because it observes head metadata, and that its negated result controls a reachable WARN_ON_ONCE trap path.
|
| 347 |
+
- Distinguish the vulnerable metadata-based assertion from the patched behavior, where xa_for_each reaches the warning only after observing an actual entry.
|
| 348 |
+
|
| 349 |
+
### Implementation constraints
|
| 350 |
+
|
| 351 |
+
- Use CSA interprocedural analysis with ProgramState facts or equivalent call summaries for the exceptional xa_store outcome and preserve object identity for the affected xarray region across calls.
|
| 352 |
+
- Use call-event callbacks suitable for modeling xa_store and xa_empty, and combine them with CFG or branch-condition evidence that the xa_empty result controls the macro-expanded trap path.
|
| 353 |
+
- Inspect the post-preprocessing assertion structure because WARN_ON_ONCE is not a callable sink; recognize its reachable __bug_table trap through AST/CFG relationships rather than a WARN_ON_ONCE call event.
|
| 354 |
+
- Emit a report only when the exceptional xa_store-derived fact, the same xarray region, the false xa_empty result, and the reachable trap branch are all related.
|
| 355 |
+
- Attach the diagnostic to the vulnerable xa_empty use in the assertion and keep the report within the function containing that use.
|
| 356 |
+
- Scope modeling to evidenced xarray semantics; do not infer equivalent behavior from generic *_empty naming conventions.
|
| 357 |
+
- Use stable API or semantic identities for xarray operations and regions, without file paths, line numbers, local variable names, commit identifiers, or changed-line anchors.
|
| 358 |
+
|
| 359 |
+
### Validation checklist
|
| 360 |
+
|
| 361 |
+
- Compile the new checker successfully against the target Clang Static Analyzer API and verify checker registration and loading.
|
| 362 |
+
- Scan both supplied pre-patch inputs and confirm the expected diagnostics occur at the xa_empty call in __io_uring_free.
|
| 363 |
+
- Scan both supplied post-patch inputs and confirm zero diagnostics after replacement with xa_for_each.
|
| 364 |
+
- Verify each pre-patch report is on the changed assertion line with no duplicate report for the same semantic path.
|
| 365 |
+
- Add or run a relevant case where a normal xa_store outcome reaches !xa_empty and confirm that the exceptional-state report is suppressed.
|
| 366 |
+
- Add or run relevant negative cases for list_empty, skb_queue_empty, arbitrary *_empty functions, and negated emptiness tests outside trap assertions.
|
| 367 |
+
- Confirm interprocedural propagation uses the same xarray region and does not report when the exceptional fact belongs to a different container.
|
| 368 |
+
- Complete refinement with an accepted clean outcome while retaining G6, hard validation, code verification, and the configured process-score threshold.
|
| 369 |
+
|
| 370 |
+
### Avoid and forbidden regressions
|
| 371 |
+
|
| 372 |
+
- Do not reuse a syntax-only odd-negation plus trap-assembly pattern as sufficient evidence of the vulnerability.
|
| 373 |
+
- Do not classify all functions ending in _empty, including list_empty_careful, as metadata-only predicates with xa_empty's partial-insertion behavior.
|
| 374 |
+
- Do not report solely because !xa_empty appears inside a WARN_ON, WARN_ON_ONCE, WARN_ONCE, BUG, or BUG_ON expansion.
|
| 375 |
+
- Do not rely on PreCall or PostCall to observe WARN_ON_ONCE itself, because preprocessing expands it into a statement expression and inline trap assembly.
|
| 376 |
+
- Do not substitute generic warning proximity or before/after disappearance for proof of the failed-store state reaching the assertion.
|
| 377 |
+
- Do not introduce source-text matching or patch-local file, function, variable, line, or commit anchors.
|
tasks/csa159/pair_163978/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_163978/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "504fa212d7030fb1c042290dc2eb92b21515573a",
|
| 4 |
+
"after_commit": "3bb2a01caa813d3a1845d378bbe4169ef280d394",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/b7bfaa761d760e72a969d116517eaa12e404c262/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/b7bfaa761d760e72a969d116517eaa12e404c262/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"lib/kobject.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "kobject: Fix slab-out-of-bounds in fill_kobj_path()\n\nIn kobject_get_path(), if kobj->name is changed between calls\nget_kobj_path_length() and fill_kobj_path() and the length becomes\nlonger, then fill_kobj_path() will have an out-of-bounds bug.\n\nThe actual current problem occurs when the ixgbe probe.\n\nIn ixgbe_mii_bus_init(), if the length of netdev->dev.kobj.name\nlength becomes longer, out-of-bounds will occur.\n\ncpu0 cpu1\nixgbe_probe\n register_netdev(netdev)\n netdev_register_kobject\n device_add\n kobject_uevent // Sending ADD events\n systemd-udevd // rename netdev\n dev_change_name\n device_rename\n kobject_rename\n ixgbe_mii_bus_init |\n mdiobus_register |\n __mdiobus_register |\n device_register |\n device_add |\n kobject_uevent |\n kobject_get_path |\n len = get_kobj_path_length // old name |\n path = kzalloc(len, gfp_mask); |\n kobj->name = name;\n /* name length becomes\n * longer\n */\n fill_kobj_path /* kobj path length is\n * longer than path,\n * resulting in out of\n * bounds when filling path\n */\n\nThis is the kasan report:\n\n==================================================================\nBUG: KASAN: slab-out-of-bounds in fill_kobj_path+0x50/0xc0\nWrite of size 7 at addr ff1100090573d1fd by task kworker/28:1/673\n\n Workqueue: events work_for_cpu_fn\n Call Trace:\n <TASK>\n dump_stack_lvl+0x34/0x48\n print_address_description.constprop.0+0x86/0x1e7\n print_report+0x36/0x4f\n kasan_report+0xad/0x130\n kasan_check_range+0x35/0x1c0\n memcpy+0x39/0x60\n fill_kobj_path+0x50/0xc0\n kobject_get_path+0x5a/0xc0\n kobject_uevent_env+0x140/0x460\n device_add+0x5c7/0x910\n __mdiobus_register+0x14e/0x490\n ixgbe_probe.cold+0x441/0x574 [ixgbe]\n local_pci_probe+0x78/0xc0\n work_for_cpu_fn+0x26/0x40\n process_one_work+0x3b6/0x6a0\n worker_thread+0x368/0x520\n kthread+0x165/0x1a0\n ret_from_fork+0x1f/0x30\n\nThis reproducer triggers that bug:\n\nwhile:\ndo\n rmmod ixgbe\n sleep 0.5\n modprobe ixgbe\n sleep 0.5\n\nWhen calling fill_kobj_path() to fill path, if the name length of\nkobj becomes longer, return failure and retry. This fixes the problem.\n\nFixes: 1da177e4c3f4 (\"Linux-2.6.12-rc2\")\nSigned-off-by: Wang Hai <wanghai38@huawei.com>\nLink: https://lore.kernel.org/r/20221220012143.52141-1-wanghai38@huawei.com\nSigned-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_163978/patch.diff
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/lib/kobject.c b/lib/kobject.c
|
| 2 |
+
index 985ee1c4f2c6..d20ce15eec2d 100644
|
| 3 |
+
--- a/lib/kobject.c
|
| 4 |
+
+++ b/lib/kobject.c
|
| 5 |
+
@@ -112,7 +112,7 @@ static int get_kobj_path_length(const struct kobject *kobj)
|
| 6 |
+
return length;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
-static void fill_kobj_path(const struct kobject *kobj, char *path, int length)
|
| 10 |
+
+static int fill_kobj_path(const struct kobject *kobj, char *path, int length)
|
| 11 |
+
{
|
| 12 |
+
const struct kobject *parent;
|
| 13 |
+
|
| 14 |
+
@@ -121,12 +121,16 @@ static void fill_kobj_path(const struct kobject *kobj, char *path, int length)
|
| 15 |
+
int cur = strlen(kobject_name(parent));
|
| 16 |
+
/* back up enough to print this name with '/' */
|
| 17 |
+
length -= cur;
|
| 18 |
+
+ if (length <= 0)
|
| 19 |
+
+ return -EINVAL;
|
| 20 |
+
memcpy(path + length, kobject_name(parent), cur);
|
| 21 |
+
*(path + --length) = '/';
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
|
| 25 |
+
kobj, __func__, path);
|
| 26 |
+
+
|
| 27 |
+
+ return 0;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
@@ -141,13 +145,17 @@ char *kobject_get_path(const struct kobject *kobj, gfp_t gfp_mask)
|
| 32 |
+
char *path;
|
| 33 |
+
int len;
|
| 34 |
+
|
| 35 |
+
+retry:
|
| 36 |
+
len = get_kobj_path_length(kobj);
|
| 37 |
+
if (len == 0)
|
| 38 |
+
return NULL;
|
| 39 |
+
path = kzalloc(len, gfp_mask);
|
| 40 |
+
if (!path)
|
| 41 |
+
return NULL;
|
| 42 |
+
- fill_kobj_path(kobj, path, len);
|
| 43 |
+
+ if (fill_kobj_path(kobj, path, len)) {
|
| 44 |
+
+ kfree(path);
|
| 45 |
+
+ goto retry;
|
| 46 |
+
+ }
|
| 47 |
+
|
| 48 |
+
return path;
|
| 49 |
+
}
|
tasks/csa159/pair_163978/post_functions.txt
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: lib/kobject.c
|
| 2 |
+
```c
|
| 3 |
+
static int get_kobj_path_length(const struct kobject *kobj)
|
| 4 |
+
{
|
| 5 |
+
int length = 1;
|
| 6 |
+
const struct kobject *parent = kobj;
|
| 7 |
+
|
| 8 |
+
/* walk up the ancestors until we hit the one pointing to the
|
| 9 |
+
* root.
|
| 10 |
+
* Add 1 to strlen for leading '/' of each level.
|
| 11 |
+
*/
|
| 12 |
+
do {
|
| 13 |
+
if (kobject_name(parent) == NULL)
|
| 14 |
+
return 0;
|
| 15 |
+
length += strlen(kobject_name(parent)) + 1;
|
| 16 |
+
parent = parent->parent;
|
| 17 |
+
} while (parent);
|
| 18 |
+
return length;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
static int fill_kobj_path(const struct kobject *kobj, char *path, int length)
|
| 22 |
+
{
|
| 23 |
+
const struct kobject *parent;
|
| 24 |
+
|
| 25 |
+
--length;
|
| 26 |
+
for (parent = kobj; parent; parent = parent->parent) {
|
| 27 |
+
int cur = strlen(kobject_name(parent));
|
| 28 |
+
/* back up enough to print this name with '/' */
|
| 29 |
+
length -= cur;
|
| 30 |
+
if (length <= 0)
|
| 31 |
+
return -EINVAL;
|
| 32 |
+
memcpy(path + length, kobject_name(parent), cur);
|
| 33 |
+
*(path + --length) = '/';
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
|
| 37 |
+
kobj, __func__, path);
|
| 38 |
+
|
| 39 |
+
return 0;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
char *kobject_get_path(const struct kobject *kobj, gfp_t gfp_mask)
|
| 43 |
+
{
|
| 44 |
+
char *path;
|
| 45 |
+
int len;
|
| 46 |
+
|
| 47 |
+
retry:
|
| 48 |
+
len = get_kobj_path_length(kobj);
|
| 49 |
+
if (len == 0)
|
| 50 |
+
return NULL;
|
| 51 |
+
path = kzalloc(len, gfp_mask);
|
| 52 |
+
if (!path)
|
| 53 |
+
return NULL;
|
| 54 |
+
if (fill_kobj_path(kobj, path, len)) {
|
| 55 |
+
kfree(path);
|
| 56 |
+
goto retry;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
return path;
|
| 60 |
+
}
|
| 61 |
+
```
|
tasks/csa159/pair_163978/pre_functions.txt
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: lib/kobject.c
|
| 2 |
+
```c
|
| 3 |
+
static int get_kobj_path_length(const struct kobject *kobj)
|
| 4 |
+
{
|
| 5 |
+
int length = 1;
|
| 6 |
+
const struct kobject *parent = kobj;
|
| 7 |
+
|
| 8 |
+
/* walk up the ancestors until we hit the one pointing to the
|
| 9 |
+
* root.
|
| 10 |
+
* Add 1 to strlen for leading '/' of each level.
|
| 11 |
+
*/
|
| 12 |
+
do {
|
| 13 |
+
if (kobject_name(parent) == NULL)
|
| 14 |
+
return 0;
|
| 15 |
+
length += strlen(kobject_name(parent)) + 1;
|
| 16 |
+
parent = parent->parent;
|
| 17 |
+
} while (parent);
|
| 18 |
+
return length;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
static void fill_kobj_path(const struct kobject *kobj, char *path, int length)
|
| 22 |
+
{
|
| 23 |
+
const struct kobject *parent;
|
| 24 |
+
|
| 25 |
+
--length;
|
| 26 |
+
for (parent = kobj; parent; parent = parent->parent) {
|
| 27 |
+
int cur = strlen(kobject_name(parent));
|
| 28 |
+
/* back up enough to print this name with '/' */
|
| 29 |
+
length -= cur;
|
| 30 |
+
memcpy(path + length, kobject_name(parent), cur);
|
| 31 |
+
*(path + --length) = '/';
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
|
| 35 |
+
kobj, __func__, path);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
char *kobject_get_path(const struct kobject *kobj, gfp_t gfp_mask)
|
| 39 |
+
{
|
| 40 |
+
char *path;
|
| 41 |
+
int len;
|
| 42 |
+
|
| 43 |
+
len = get_kobj_path_length(kobj);
|
| 44 |
+
if (len == 0)
|
| 45 |
+
return NULL;
|
| 46 |
+
path = kzalloc(len, gfp_mask);
|
| 47 |
+
if (!path)
|
| 48 |
+
return NULL;
|
| 49 |
+
fill_kobj_path(kobj, path, len);
|
| 50 |
+
|
| 51 |
+
return path;
|
| 52 |
+
}
|
| 53 |
+
```
|
tasks/csa159/pair_163978/task_prompt.md
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `interprocedural_dataflow`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- The prior rollout detected a generic negative destination offset but did not prove the specific defect fixed by the patch: a length measured by get_kobj_path_length() becoming stale before fill_kobj_path() writes into the allocation.
|
| 330 |
+
- It did not establish that path is the beginning of the allocation returned by kzalloc(), nor relate the allocation extent to the later memcpy and decremented store.
|
| 331 |
+
- It had no model for the relationship between the sizing and filling operations or for concurrent kobject name or ancestry growth, so its reports covered a superset of the patched defect.
|
| 332 |
+
- The final refinement, semantic mechanism, and semantic score checks failed even though compilation, differential validation, scope sharpness, and hardcoding checks passed.
|
| 333 |
+
|
| 334 |
+
### Preserve from prior rollouts
|
| 335 |
+
|
| 336 |
+
- Preserve successful compilation, before/after validation, and code verification.
|
| 337 |
+
- Preserve objective eligibility gate G6.
|
| 338 |
+
- Preserve at least the previously adequate path-sensitive CSA reasoning level.
|
| 339 |
+
- Preserve semantic score at or above the configured threshold and process quality at or above its configured threshold.
|
| 340 |
+
- Do not introduce dependence on patch anchors, patch-local identifiers, literals, line numbers, or source-text matching.
|
| 341 |
+
- Keep the checker project-general and free of patch-local hardcoding.
|
| 342 |
+
|
| 343 |
+
### Required semantic proof
|
| 344 |
+
|
| 345 |
+
- Establish that a destination write can occur through a pointer derived from the allocation base, with an effective offset that is negative relative to the beginning of that allocation.
|
| 346 |
+
- Track the allocation size or available extent from the allocation-producing operation and relate it to the length computed before the fill operation.
|
| 347 |
+
- Connect the value returned or established by get_kobj_path_length() with the length consumed by fill_kobj_path(), including the intervening allocation and function boundary.
|
| 348 |
+
- Establish that the write is reachable without a terminating condition proving the effective offset is non-negative, and that the patched length <= 0 return excludes the corresponding unsafe path.
|
| 349 |
+
- Represent the stale-size condition caused by a possible change in the kobject name or ancestry between measurement and filling sufficiently to distinguish the fixed race from unrelated negative arithmetic.
|
| 350 |
+
- Keep the claimed defect precise: the write begins before the allocated path buffer; do not infer that every negative arithmetic expression is an out-of-bounds access.
|
| 351 |
+
|
| 352 |
+
### Implementation constraints
|
| 353 |
+
|
| 354 |
+
- Use CSA path-sensitive ProgramState and ConstraintManager facts at the write sink, combined with interprocedural propagation across the sizing, allocation, and filling functions.
|
| 355 |
+
- Model destination-writing calls such as memcpy and direct pointer stores only when their destination can be tied to the tracked allocation base and effective offset.
|
| 356 |
+
- Preserve correct handling of pointer arithmetic, nested element or field regions, signed values, and pre/post-decrement side effects without manually re-evaluating expressions.
|
| 357 |
+
- Carry allocation extent and relevant length provenance through returns, arguments, and aliases rather than recognizing only local AST shapes.
|
| 358 |
+
- Use CFG reachability and terminating guards to suppress the patched paths, while reporting at the concrete write location with a path-sensitive diagnostic.
|
| 359 |
+
- Keep matching structural and semantic; do not special-case fill_kobj_path, get_kobj_path_length, kobject_get_path, kobject, path, length, or patch-specific APIs.
|
| 360 |
+
- Limit reports to the project-general stale-size allocation/write relation and avoid broad classification of arbitrary writable byte-pointer calls without established provenance.
|
| 361 |
+
|
| 362 |
+
### Validation checklist
|
| 363 |
+
|
| 364 |
+
- Compile the new checker and retain code verification success.
|
| 365 |
+
- Scan the supplied pre-patch source and confirm the expected vulnerable writes are reported at or near the memcpy and direct-store sinks.
|
| 366 |
+
- Scan the supplied post-patch source and confirm those reports disappear because the terminating guard and retry path exclude the unsafe relation.
|
| 367 |
+
- Verify report locations belong to the changed functions and remain within the established diagnostic-distance threshold.
|
| 368 |
+
- Check that the before/after result preserves objective gate G6, including differential detection, sharpness, and non-patched-function false-positive control.
|
| 369 |
+
- Exercise a refinement set with nonnegative guarded offsets, interior pointers, concrete offsets, unrelated negative arithmetic, and writes lacking allocation provenance.
|
| 370 |
+
- Confirm the checker remains patch-anchor-free and patch-hardcoding-free under implementation and scan checks.
|
| 371 |
+
- Require refinement acceptance, semantic mechanism adequacy, semantic correctness, and semantic score threshold success before rollout.
|
| 372 |
+
|
| 373 |
+
### Avoid and forbidden regressions
|
| 374 |
+
|
| 375 |
+
- Do not treat any feasible negative symbolic offset as sufficient evidence of this vulnerability.
|
| 376 |
+
- Do not rely solely on local PreCall or PreStmt destination shape without allocation extent and cross-function provenance.
|
| 377 |
+
- Do not force all pointer offsets into a signed interpretation when the source semantics do not establish that interpretation.
|
| 378 |
+
- Do not broadly classify every mutable byte-buffer first parameter as a destination sink without proving the relevant write and allocation relationship.
|
| 379 |
+
- Do not claim that a nonnegative offset proves the entire write range fits within the allocation.
|
| 380 |
+
- Do not model the patch by matching its function names, variable names, guard text, changed lines, or literal constants.
|
| 381 |
+
- Do not regress the successful compile, validation, objective-gate, scope-control, semantic-level, semantic-score, process-quality, anchor-free, or hardcoding-free checks.
|
tasks/csa159/pair_164140/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_164140/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "60316d7f10b17a7ebb1ead0642fee8710e1560e0",
|
| 4 |
+
"after_commit": "23d05d563b7e7b0314e65c8e882bc27eac2da8e7",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/33cc938e65a98f1d29d0a18403dbbee050dcad9a/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/33cc938e65a98f1d29d0a18403dbbee050dcad9a/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"net/core/skbuff.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "net: prevent mss overflow in skb_segment()\n\nOnce again syzbot is able to crash the kernel in skb_segment() [1]\n\nGSO_BY_FRAGS is a forbidden value, but unfortunately the following\ncomputation in skb_segment() can reach it quite easily :\n\n\tmss = mss * partial_segs;\n\n65535 = 3 * 5 * 17 * 257, so many initial values of mss can lead to\na bad final result.\n\nMake sure to limit segmentation so that the new mss value is smaller\nthan GSO_BY_FRAGS.\n\n[1]\n\ngeneral protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN\nKASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]\nCPU: 1 PID: 5079 Comm: syz-executor993 Not tainted 6.7.0-rc4-syzkaller-00141-g1ae4cd3cbdd0 #0\nHardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/10/2023\nRIP: 0010:skb_segment+0x181d/0x3f30 net/core/skbuff.c:4551\nCode: 83 e3 02 e9 fb ed ff ff e8 90 68 1c f9 48 8b 84 24 f8 00 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e 8a 21 00 00 48 8b 84 24 f8 00\nRSP: 0018:ffffc900043473d0 EFLAGS: 00010202\nRAX: dffffc0000000000 RBX: 0000000000010046 RCX: ffffffff886b1597\nRDX: 000000000000000e RSI: ffffffff886b2520 RDI: 0000000000000070\nRBP: ffffc90004347578 R08: 0000000000000005 R09: 000000000000ffff\nR10: 000000000000ffff R11: 0000000000000002 R12: ffff888063202ac0\nR13: 0000000000010000 R14: 000000000000ffff R15: 0000000000000046\nFS: 0000555556e7e380(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000\nCS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033\nCR2: 0000000020010000 CR3: 0000000027ee2000 CR4: 00000000003506f0\nDR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000\nDR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400\nCall Trace:\n<TASK>\nudp6_ufo_fragment+0xa0e/0xd00 net/ipv6/udp_offload.c:109\nipv6_gso_segment+0x534/0x17e0 net/ipv6/ip6_offload.c:120\nskb_mac_gso_segment+0x290/0x610 net/core/gso.c:53\n__skb_gso_segment+0x339/0x710 net/core/gso.c:124\nskb_gso_segment include/net/gso.h:83 [inline]\nvalidate_xmit_skb+0x36c/0xeb0 net/core/dev.c:3626\n__dev_queue_xmit+0x6f3/0x3d60 net/core/dev.c:4338\ndev_queue_xmit include/linux/netdevice.h:3134 [inline]\npacket_xmit+0x257/0x380 net/packet/af_packet.c:276\npacket_snd net/packet/af_packet.c:3087 [inline]\npacket_sendmsg+0x24c6/0x5220 net/packet/af_packet.c:3119\nsock_sendmsg_nosec net/socket.c:730 [inline]\n__sock_sendmsg+0xd5/0x180 net/socket.c:745\n__sys_sendto+0x255/0x340 net/socket.c:2190\n__do_sys_sendto net/socket.c:2202 [inline]\n__se_sys_sendto net/socket.c:2198 [inline]\n__x64_sys_sendto+0xe0/0x1b0 net/socket.c:2198\ndo_syscall_x64 arch/x86/entry/common.c:52 [inline]\ndo_syscall_64+0x40/0x110 arch/x86/entry/common.c:83\nentry_SYSCALL_64_after_hwframe+0x63/0x6b\nRIP: 0033:0x7f8692032aa9\nCode: 28 00 00 00 75 05 48 83 c4 28 c3 e8 d1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48\nRSP: 002b:00007fff8d685418 EFLAGS: 00000246 ORIG_RAX: 000000000000002c\nRAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f8692032aa9\nRDX: 0000000000010048 RSI: 00000000200000c0 RDI: 0000000000000003\nRBP: 00000000000f4240 R08: 0000000020000540 R09: 0000000000000014\nR10: 0000000000000000 R11: 0000000000000246 R12: 00007fff8d685480\nR13: 0000000000000001 R14: 00007fff8d685480 R15: 0000000000000003\n</TASK>\nModules linked in:\n---[ end trace 0000000000000000 ]---\nRIP: 0010:skb_segment+0x181d/0x3f30 net/core/skbuff.c:4551\nCode: 83 e3 02 e9 fb ed ff ff e8 90 68 1c f9 48 8b 84 24 f8 00 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e 8a 21 00 00 48 8b 84 24 f8 00\nRSP: 0018:ffffc900043473d0 EFLAGS: 00010202\nRAX: dffffc0000000000 RBX: 0000000000010046 RCX: ffffffff886b1597\nRDX: 000000000000000e RSI: ffffffff886b2520 RDI: 0000000000000070\nRBP: ffffc90004347578 R08: 0000000000000005 R09: 000000000000ffff\nR10: 000000000000ffff R11: 0000000000000002 R12: ffff888063202ac0\nR13: 0000000000010000 R14: 000000000000ffff R15: 0000000000000046\nFS: 0000555556e7e380(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000\nCS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033\nCR2: 0000000020010000 CR3: 0000000027ee2000 CR4: 00000000003506f0\nDR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000\nDR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400\n\nFixes: 3953c46c3ac7 (\"sk_buff: allow segmenting based on frag sizes\")\nSigned-off-by: Eric Dumazet <edumazet@google.com>\nCc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>\nReviewed-by: Willem de Bruijn <willemb@google.com>\nLink: https://lore.kernel.org/r/20231212164621.4131800-1-edumazet@google.com\nSigned-off-by: Jakub Kicinski <kuba@kernel.org>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_164140/patch.diff
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
|
| 2 |
+
index b157efea5dea..83af8aaeb893 100644
|
| 3 |
+
--- a/net/core/skbuff.c
|
| 4 |
+
+++ b/net/core/skbuff.c
|
| 5 |
+
@@ -4522,8 +4522,9 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
|
| 6 |
+
/* GSO partial only requires that we trim off any excess that
|
| 7 |
+
* doesn't fit into an MSS sized block, so take care of that
|
| 8 |
+
* now.
|
| 9 |
+
+ * Cap len to not accidentally hit GSO_BY_FRAGS.
|
| 10 |
+
*/
|
| 11 |
+
- partial_segs = len / mss;
|
| 12 |
+
+ partial_segs = min(len, GSO_BY_FRAGS - 1) / mss;
|
| 13 |
+
if (partial_segs > 1)
|
| 14 |
+
mss *= partial_segs;
|
| 15 |
+
else
|
tasks/csa159/pair_164140/post_functions.txt
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/core/skbuff.c
|
| 2 |
+
```c
|
| 3 |
+
struct sk_buff *skb_segment(struct sk_buff *head_skb,
|
| 4 |
+
netdev_features_t features)
|
| 5 |
+
{
|
| 6 |
+
struct sk_buff *segs = NULL;
|
| 7 |
+
struct sk_buff *tail = NULL;
|
| 8 |
+
struct sk_buff *list_skb = skb_shinfo(head_skb)->frag_list;
|
| 9 |
+
unsigned int mss = skb_shinfo(head_skb)->gso_size;
|
| 10 |
+
unsigned int doffset = head_skb->data - skb_mac_header(head_skb);
|
| 11 |
+
unsigned int offset = doffset;
|
| 12 |
+
unsigned int tnl_hlen = skb_tnl_header_len(head_skb);
|
| 13 |
+
unsigned int partial_segs = 0;
|
| 14 |
+
unsigned int headroom;
|
| 15 |
+
unsigned int len = head_skb->len;
|
| 16 |
+
struct sk_buff *frag_skb;
|
| 17 |
+
skb_frag_t *frag;
|
| 18 |
+
__be16 proto;
|
| 19 |
+
bool csum, sg;
|
| 20 |
+
int err = -ENOMEM;
|
| 21 |
+
int i = 0;
|
| 22 |
+
int nfrags, pos;
|
| 23 |
+
|
| 24 |
+
if ((skb_shinfo(head_skb)->gso_type & SKB_GSO_DODGY) &&
|
| 25 |
+
mss != GSO_BY_FRAGS && mss != skb_headlen(head_skb)) {
|
| 26 |
+
struct sk_buff *check_skb;
|
| 27 |
+
|
| 28 |
+
for (check_skb = list_skb; check_skb; check_skb = check_skb->next) {
|
| 29 |
+
if (skb_headlen(check_skb) && !check_skb->head_frag) {
|
| 30 |
+
/* gso_size is untrusted, and we have a frag_list with
|
| 31 |
+
* a linear non head_frag item.
|
| 32 |
+
*
|
| 33 |
+
* If head_skb's headlen does not fit requested gso_size,
|
| 34 |
+
* it means that the frag_list members do NOT terminate
|
| 35 |
+
* on exact gso_size boundaries. Hence we cannot perform
|
| 36 |
+
* skb_frag_t page sharing. Therefore we must fallback to
|
| 37 |
+
* copying the frag_list skbs; we do so by disabling SG.
|
| 38 |
+
*/
|
| 39 |
+
features &= ~NETIF_F_SG;
|
| 40 |
+
break;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
__skb_push(head_skb, doffset);
|
| 46 |
+
proto = skb_network_protocol(head_skb, NULL);
|
| 47 |
+
if (unlikely(!proto))
|
| 48 |
+
return ERR_PTR(-EINVAL);
|
| 49 |
+
|
| 50 |
+
sg = !!(features & NETIF_F_SG);
|
| 51 |
+
csum = !!can_checksum_protocol(features, proto);
|
| 52 |
+
|
| 53 |
+
if (sg && csum && (mss != GSO_BY_FRAGS)) {
|
| 54 |
+
if (!(features & NETIF_F_GSO_PARTIAL)) {
|
| 55 |
+
struct sk_buff *iter;
|
| 56 |
+
unsigned int frag_len;
|
| 57 |
+
|
| 58 |
+
if (!list_skb ||
|
| 59 |
+
!net_gso_ok(features, skb_shinfo(head_skb)->gso_type))
|
| 60 |
+
goto normal;
|
| 61 |
+
|
| 62 |
+
/* If we get here then all the required
|
| 63 |
+
* GSO features except frag_list are supported.
|
| 64 |
+
* Try to split the SKB to multiple GSO SKBs
|
| 65 |
+
* with no frag_list.
|
| 66 |
+
* Currently we can do that only when the buffers don't
|
| 67 |
+
* have a linear part and all the buffers except
|
| 68 |
+
* the last are of the same length.
|
| 69 |
+
*/
|
| 70 |
+
frag_len = list_skb->len;
|
| 71 |
+
skb_walk_frags(head_skb, iter) {
|
| 72 |
+
if (frag_len != iter->len && iter->next)
|
| 73 |
+
goto normal;
|
| 74 |
+
if (skb_headlen(iter) && !iter->head_frag)
|
| 75 |
+
goto normal;
|
| 76 |
+
|
| 77 |
+
len -= iter->len;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
if (len != frag_len)
|
| 81 |
+
goto normal;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* GSO partial only requires that we trim off any excess that
|
| 85 |
+
* doesn't fit into an MSS sized block, so take care of that
|
| 86 |
+
* now.
|
| 87 |
+
* Cap len to not accidentally hit GSO_BY_FRAGS.
|
| 88 |
+
*/
|
| 89 |
+
partial_segs = min(len, GSO_BY_FRAGS - 1) / mss;
|
| 90 |
+
if (partial_segs > 1)
|
| 91 |
+
mss *= partial_segs;
|
| 92 |
+
else
|
| 93 |
+
partial_segs = 0;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
normal:
|
| 97 |
+
headroom = skb_headroom(head_skb);
|
| 98 |
+
pos = skb_headlen(head_skb);
|
| 99 |
+
|
| 100 |
+
if (skb_orphan_frags(head_skb, GFP_ATOMIC))
|
| 101 |
+
return ERR_PTR(-ENOMEM);
|
| 102 |
+
|
| 103 |
+
nfrags = skb_shinfo(head_skb)->nr_frags;
|
| 104 |
+
frag = skb_shinfo(head_skb)->frags;
|
| 105 |
+
frag_skb = head_skb;
|
| 106 |
+
|
| 107 |
+
do {
|
| 108 |
+
struct sk_buff *nskb;
|
| 109 |
+
skb_frag_t *nskb_frag;
|
| 110 |
+
int hsize;
|
| 111 |
+
int size;
|
| 112 |
+
|
| 113 |
+
if (unlikely(mss == GSO_BY_FRAGS)) {
|
| 114 |
+
len = list_skb->len;
|
| 115 |
+
} else {
|
| 116 |
+
len = head_skb->len - offset;
|
| 117 |
+
if (len > mss)
|
| 118 |
+
len = mss;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
hsize = skb_headlen(head_skb) - offset;
|
| 122 |
+
|
| 123 |
+
if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) &&
|
| 124 |
+
(skb_headlen(list_skb) == len || sg)) {
|
| 125 |
+
BUG_ON(skb_headlen(list_skb) > len);
|
| 126 |
+
|
| 127 |
+
nskb = skb_clone(list_skb, GFP_ATOMIC);
|
| 128 |
+
if (unlikely(!nskb))
|
| 129 |
+
goto err;
|
| 130 |
+
|
| 131 |
+
i = 0;
|
| 132 |
+
nfrags = skb_shinfo(list_skb)->nr_frags;
|
| 133 |
+
frag = skb_shinfo(list_skb)->frags;
|
| 134 |
+
frag_skb = list_skb;
|
| 135 |
+
pos += skb_headlen(list_skb);
|
| 136 |
+
|
| 137 |
+
while (pos < offset + len) {
|
| 138 |
+
BUG_ON(i >= nfrags);
|
| 139 |
+
|
| 140 |
+
size = skb_frag_size(frag);
|
| 141 |
+
if (pos + size > offset + len)
|
| 142 |
+
break;
|
| 143 |
+
|
| 144 |
+
i++;
|
| 145 |
+
pos += size;
|
| 146 |
+
frag++;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
list_skb = list_skb->next;
|
| 150 |
+
|
| 151 |
+
if (unlikely(pskb_trim(nskb, len))) {
|
| 152 |
+
kfree_skb(nskb);
|
| 153 |
+
goto err;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
hsize = skb_end_offset(nskb);
|
| 157 |
+
if (skb_cow_head(nskb, doffset + headroom)) {
|
| 158 |
+
kfree_skb(nskb);
|
| 159 |
+
goto err;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
nskb->truesize += skb_end_offset(nskb) - hsize;
|
| 163 |
+
skb_release_head_state(nskb);
|
| 164 |
+
__skb_push(nskb, doffset);
|
| 165 |
+
} else {
|
| 166 |
+
if (hsize < 0)
|
| 167 |
+
hsize = 0;
|
| 168 |
+
if (hsize > len || !sg)
|
| 169 |
+
hsize = len;
|
| 170 |
+
|
| 171 |
+
nskb = __alloc_skb(hsize + doffset + headroom,
|
| 172 |
+
GFP_ATOMIC, skb_alloc_rx_flag(head_skb),
|
| 173 |
+
NUMA_NO_NODE);
|
| 174 |
+
|
| 175 |
+
if (unlikely(!nskb))
|
| 176 |
+
goto err;
|
| 177 |
+
|
| 178 |
+
skb_reserve(nskb, headroom);
|
| 179 |
+
__skb_put(nskb, doffset);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
if (segs)
|
| 183 |
+
tail->next = nskb;
|
| 184 |
+
else
|
| 185 |
+
segs = nskb;
|
| 186 |
+
tail = nskb;
|
| 187 |
+
|
| 188 |
+
__copy_skb_header(nskb, head_skb);
|
| 189 |
+
|
| 190 |
+
skb_headers_offset_update(nskb, skb_headroom(nskb) - headroom);
|
| 191 |
+
skb_reset_mac_len(nskb);
|
| 192 |
+
|
| 193 |
+
skb_copy_from_linear_data_offset(head_skb, -tnl_hlen,
|
| 194 |
+
nskb->data - tnl_hlen,
|
| 195 |
+
doffset + tnl_hlen);
|
| 196 |
+
|
| 197 |
+
if (nskb->len == len + doffset)
|
| 198 |
+
goto perform_csum_check;
|
| 199 |
+
|
| 200 |
+
if (!sg) {
|
| 201 |
+
if (!csum) {
|
| 202 |
+
if (!nskb->remcsum_offload)
|
| 203 |
+
nskb->ip_summed = CHECKSUM_NONE;
|
| 204 |
+
SKB_GSO_CB(nskb)->csum =
|
| 205 |
+
skb_copy_and_csum_bits(head_skb, offset,
|
| 206 |
+
skb_put(nskb,
|
| 207 |
+
len),
|
| 208 |
+
len);
|
| 209 |
+
SKB_GSO_CB(nskb)->csum_start =
|
| 210 |
+
skb_headroom(nskb) + doffset;
|
| 211 |
+
} else {
|
| 212 |
+
if (skb_copy_bits(head_skb, offset, skb_put(nskb, len), len))
|
| 213 |
+
goto err;
|
| 214 |
+
}
|
| 215 |
+
continue;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
nskb_frag = skb_shinfo(nskb)->frags;
|
| 219 |
+
|
| 220 |
+
skb_copy_from_linear_data_offset(head_skb, offset,
|
| 221 |
+
skb_put(nskb, hsize), hsize);
|
| 222 |
+
|
| 223 |
+
skb_shinfo(nskb)->flags |= skb_shinfo(head_skb)->flags &
|
| 224 |
+
SKBFL_SHARED_FRAG;
|
| 225 |
+
|
| 226 |
+
if (skb_zerocopy_clone(nskb, frag_skb, GFP_ATOMIC))
|
| 227 |
+
goto err;
|
| 228 |
+
|
| 229 |
+
while (pos < offset + len) {
|
| 230 |
+
if (i >= nfrags) {
|
| 231 |
+
if (skb_orphan_frags(list_skb, GFP_ATOMIC) ||
|
| 232 |
+
skb_zerocopy_clone(nskb, list_skb,
|
| 233 |
+
GFP_ATOMIC))
|
| 234 |
+
goto err;
|
| 235 |
+
|
| 236 |
+
i = 0;
|
| 237 |
+
nfrags = skb_shinfo(list_skb)->nr_frags;
|
| 238 |
+
frag = skb_shinfo(list_skb)->frags;
|
| 239 |
+
frag_skb = list_skb;
|
| 240 |
+
if (!skb_headlen(list_skb)) {
|
| 241 |
+
BUG_ON(!nfrags);
|
| 242 |
+
} else {
|
| 243 |
+
BUG_ON(!list_skb->head_frag);
|
| 244 |
+
|
| 245 |
+
/* to make room for head_frag. */
|
| 246 |
+
i--;
|
| 247 |
+
frag--;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
list_skb = list_skb->next;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (unlikely(skb_shinfo(nskb)->nr_frags >=
|
| 254 |
+
MAX_SKB_FRAGS)) {
|
| 255 |
+
net_warn_ratelimited(
|
| 256 |
+
"skb_segment: too many frags: %u %u\n",
|
| 257 |
+
pos, mss);
|
| 258 |
+
err = -EINVAL;
|
| 259 |
+
goto err;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
*nskb_frag = (i < 0) ? skb_head_frag_to_page_desc(frag_skb) : *frag;
|
| 263 |
+
__skb_frag_ref(nskb_frag);
|
| 264 |
+
size = skb_frag_size(nskb_frag);
|
| 265 |
+
|
| 266 |
+
if (pos < offset) {
|
| 267 |
+
skb_frag_off_add(nskb_frag, offset - pos);
|
| 268 |
+
skb_frag_size_sub(nskb_frag, offset - pos);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
skb_shinfo(nskb)->nr_frags++;
|
| 272 |
+
|
| 273 |
+
if (pos + size <= offset + len) {
|
| 274 |
+
i++;
|
| 275 |
+
frag++;
|
| 276 |
+
pos += size;
|
| 277 |
+
} else {
|
| 278 |
+
skb_frag_size_sub(nskb_frag, pos + size - (offset + len));
|
| 279 |
+
goto skip_fraglist;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
nskb_frag++;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
skip_fraglist:
|
| 286 |
+
nskb->data_len = len - hsize;
|
| 287 |
+
nskb->len += nskb->data_len;
|
| 288 |
+
nskb->truesize += nskb->data_len;
|
| 289 |
+
|
| 290 |
+
perform_csum_check:
|
| 291 |
+
if (!csum) {
|
| 292 |
+
if (skb_has_shared_frag(nskb) &&
|
| 293 |
+
__skb_linearize(nskb))
|
| 294 |
+
goto err;
|
| 295 |
+
|
| 296 |
+
if (!nskb->remcsum_offload)
|
| 297 |
+
nskb->ip_summed = CHECKSUM_NONE;
|
| 298 |
+
SKB_GSO_CB(nskb)->csum =
|
| 299 |
+
skb_checksum(nskb, doffset,
|
| 300 |
+
nskb->len - doffset, 0);
|
| 301 |
+
SKB_GSO_CB(nskb)->csum_start =
|
| 302 |
+
skb_headroom(nskb) + doffset;
|
| 303 |
+
}
|
| 304 |
+
} while ((offset += len) < head_skb->len);
|
| 305 |
+
|
| 306 |
+
/* Some callers want to get the end of the list.
|
| 307 |
+
* Put it in segs->prev to avoid walking the list.
|
| 308 |
+
* (see validate_xmit_skb_list() for example)
|
| 309 |
+
*/
|
| 310 |
+
segs->prev = tail;
|
| 311 |
+
|
| 312 |
+
if (partial_segs) {
|
| 313 |
+
struct sk_buff *iter;
|
| 314 |
+
int type = skb_shinfo(head_skb)->gso_type;
|
| 315 |
+
unsigned short gso_size = skb_shinfo(head_skb)->gso_size;
|
| 316 |
+
|
| 317 |
+
/* Update type to add partial and then remove dodgy if set */
|
| 318 |
+
type |= (features & NETIF_F_GSO_PARTIAL) / NETIF_F_GSO_PARTIAL * SKB_GSO_PARTIAL;
|
| 319 |
+
type &= ~SKB_GSO_DODGY;
|
| 320 |
+
|
| 321 |
+
/* Update GSO info and prepare to start updating headers on
|
| 322 |
+
* our way back down the stack of protocols.
|
| 323 |
+
*/
|
| 324 |
+
for (iter = segs; iter; iter = iter->next) {
|
| 325 |
+
skb_shi
|
| 326 |
+
|
| 327 |
+
// ... (759 more chars)
|
| 328 |
+
```
|
tasks/csa159/pair_164140/pre_functions.txt
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/core/skbuff.c
|
| 2 |
+
```c
|
| 3 |
+
struct sk_buff *skb_segment(struct sk_buff *head_skb,
|
| 4 |
+
netdev_features_t features)
|
| 5 |
+
{
|
| 6 |
+
struct sk_buff *segs = NULL;
|
| 7 |
+
struct sk_buff *tail = NULL;
|
| 8 |
+
struct sk_buff *list_skb = skb_shinfo(head_skb)->frag_list;
|
| 9 |
+
unsigned int mss = skb_shinfo(head_skb)->gso_size;
|
| 10 |
+
unsigned int doffset = head_skb->data - skb_mac_header(head_skb);
|
| 11 |
+
unsigned int offset = doffset;
|
| 12 |
+
unsigned int tnl_hlen = skb_tnl_header_len(head_skb);
|
| 13 |
+
unsigned int partial_segs = 0;
|
| 14 |
+
unsigned int headroom;
|
| 15 |
+
unsigned int len = head_skb->len;
|
| 16 |
+
struct sk_buff *frag_skb;
|
| 17 |
+
skb_frag_t *frag;
|
| 18 |
+
__be16 proto;
|
| 19 |
+
bool csum, sg;
|
| 20 |
+
int err = -ENOMEM;
|
| 21 |
+
int i = 0;
|
| 22 |
+
int nfrags, pos;
|
| 23 |
+
|
| 24 |
+
if ((skb_shinfo(head_skb)->gso_type & SKB_GSO_DODGY) &&
|
| 25 |
+
mss != GSO_BY_FRAGS && mss != skb_headlen(head_skb)) {
|
| 26 |
+
struct sk_buff *check_skb;
|
| 27 |
+
|
| 28 |
+
for (check_skb = list_skb; check_skb; check_skb = check_skb->next) {
|
| 29 |
+
if (skb_headlen(check_skb) && !check_skb->head_frag) {
|
| 30 |
+
/* gso_size is untrusted, and we have a frag_list with
|
| 31 |
+
* a linear non head_frag item.
|
| 32 |
+
*
|
| 33 |
+
* If head_skb's headlen does not fit requested gso_size,
|
| 34 |
+
* it means that the frag_list members do NOT terminate
|
| 35 |
+
* on exact gso_size boundaries. Hence we cannot perform
|
| 36 |
+
* skb_frag_t page sharing. Therefore we must fallback to
|
| 37 |
+
* copying the frag_list skbs; we do so by disabling SG.
|
| 38 |
+
*/
|
| 39 |
+
features &= ~NETIF_F_SG;
|
| 40 |
+
break;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
__skb_push(head_skb, doffset);
|
| 46 |
+
proto = skb_network_protocol(head_skb, NULL);
|
| 47 |
+
if (unlikely(!proto))
|
| 48 |
+
return ERR_PTR(-EINVAL);
|
| 49 |
+
|
| 50 |
+
sg = !!(features & NETIF_F_SG);
|
| 51 |
+
csum = !!can_checksum_protocol(features, proto);
|
| 52 |
+
|
| 53 |
+
if (sg && csum && (mss != GSO_BY_FRAGS)) {
|
| 54 |
+
if (!(features & NETIF_F_GSO_PARTIAL)) {
|
| 55 |
+
struct sk_buff *iter;
|
| 56 |
+
unsigned int frag_len;
|
| 57 |
+
|
| 58 |
+
if (!list_skb ||
|
| 59 |
+
!net_gso_ok(features, skb_shinfo(head_skb)->gso_type))
|
| 60 |
+
goto normal;
|
| 61 |
+
|
| 62 |
+
/* If we get here then all the required
|
| 63 |
+
* GSO features except frag_list are supported.
|
| 64 |
+
* Try to split the SKB to multiple GSO SKBs
|
| 65 |
+
* with no frag_list.
|
| 66 |
+
* Currently we can do that only when the buffers don't
|
| 67 |
+
* have a linear part and all the buffers except
|
| 68 |
+
* the last are of the same length.
|
| 69 |
+
*/
|
| 70 |
+
frag_len = list_skb->len;
|
| 71 |
+
skb_walk_frags(head_skb, iter) {
|
| 72 |
+
if (frag_len != iter->len && iter->next)
|
| 73 |
+
goto normal;
|
| 74 |
+
if (skb_headlen(iter) && !iter->head_frag)
|
| 75 |
+
goto normal;
|
| 76 |
+
|
| 77 |
+
len -= iter->len;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
if (len != frag_len)
|
| 81 |
+
goto normal;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* GSO partial only requires that we trim off any excess that
|
| 85 |
+
* doesn't fit into an MSS sized block, so take care of that
|
| 86 |
+
* now.
|
| 87 |
+
*/
|
| 88 |
+
partial_segs = len / mss;
|
| 89 |
+
if (partial_segs > 1)
|
| 90 |
+
mss *= partial_segs;
|
| 91 |
+
else
|
| 92 |
+
partial_segs = 0;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
normal:
|
| 96 |
+
headroom = skb_headroom(head_skb);
|
| 97 |
+
pos = skb_headlen(head_skb);
|
| 98 |
+
|
| 99 |
+
if (skb_orphan_frags(head_skb, GFP_ATOMIC))
|
| 100 |
+
return ERR_PTR(-ENOMEM);
|
| 101 |
+
|
| 102 |
+
nfrags = skb_shinfo(head_skb)->nr_frags;
|
| 103 |
+
frag = skb_shinfo(head_skb)->frags;
|
| 104 |
+
frag_skb = head_skb;
|
| 105 |
+
|
| 106 |
+
do {
|
| 107 |
+
struct sk_buff *nskb;
|
| 108 |
+
skb_frag_t *nskb_frag;
|
| 109 |
+
int hsize;
|
| 110 |
+
int size;
|
| 111 |
+
|
| 112 |
+
if (unlikely(mss == GSO_BY_FRAGS)) {
|
| 113 |
+
len = list_skb->len;
|
| 114 |
+
} else {
|
| 115 |
+
len = head_skb->len - offset;
|
| 116 |
+
if (len > mss)
|
| 117 |
+
len = mss;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
hsize = skb_headlen(head_skb) - offset;
|
| 121 |
+
|
| 122 |
+
if (hsize <= 0 && i >= nfrags && skb_headlen(list_skb) &&
|
| 123 |
+
(skb_headlen(list_skb) == len || sg)) {
|
| 124 |
+
BUG_ON(skb_headlen(list_skb) > len);
|
| 125 |
+
|
| 126 |
+
nskb = skb_clone(list_skb, GFP_ATOMIC);
|
| 127 |
+
if (unlikely(!nskb))
|
| 128 |
+
goto err;
|
| 129 |
+
|
| 130 |
+
i = 0;
|
| 131 |
+
nfrags = skb_shinfo(list_skb)->nr_frags;
|
| 132 |
+
frag = skb_shinfo(list_skb)->frags;
|
| 133 |
+
frag_skb = list_skb;
|
| 134 |
+
pos += skb_headlen(list_skb);
|
| 135 |
+
|
| 136 |
+
while (pos < offset + len) {
|
| 137 |
+
BUG_ON(i >= nfrags);
|
| 138 |
+
|
| 139 |
+
size = skb_frag_size(frag);
|
| 140 |
+
if (pos + size > offset + len)
|
| 141 |
+
break;
|
| 142 |
+
|
| 143 |
+
i++;
|
| 144 |
+
pos += size;
|
| 145 |
+
frag++;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
list_skb = list_skb->next;
|
| 149 |
+
|
| 150 |
+
if (unlikely(pskb_trim(nskb, len))) {
|
| 151 |
+
kfree_skb(nskb);
|
| 152 |
+
goto err;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
hsize = skb_end_offset(nskb);
|
| 156 |
+
if (skb_cow_head(nskb, doffset + headroom)) {
|
| 157 |
+
kfree_skb(nskb);
|
| 158 |
+
goto err;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
nskb->truesize += skb_end_offset(nskb) - hsize;
|
| 162 |
+
skb_release_head_state(nskb);
|
| 163 |
+
__skb_push(nskb, doffset);
|
| 164 |
+
} else {
|
| 165 |
+
if (hsize < 0)
|
| 166 |
+
hsize = 0;
|
| 167 |
+
if (hsize > len || !sg)
|
| 168 |
+
hsize = len;
|
| 169 |
+
|
| 170 |
+
nskb = __alloc_skb(hsize + doffset + headroom,
|
| 171 |
+
GFP_ATOMIC, skb_alloc_rx_flag(head_skb),
|
| 172 |
+
NUMA_NO_NODE);
|
| 173 |
+
|
| 174 |
+
if (unlikely(!nskb))
|
| 175 |
+
goto err;
|
| 176 |
+
|
| 177 |
+
skb_reserve(nskb, headroom);
|
| 178 |
+
__skb_put(nskb, doffset);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
if (segs)
|
| 182 |
+
tail->next = nskb;
|
| 183 |
+
else
|
| 184 |
+
segs = nskb;
|
| 185 |
+
tail = nskb;
|
| 186 |
+
|
| 187 |
+
__copy_skb_header(nskb, head_skb);
|
| 188 |
+
|
| 189 |
+
skb_headers_offset_update(nskb, skb_headroom(nskb) - headroom);
|
| 190 |
+
skb_reset_mac_len(nskb);
|
| 191 |
+
|
| 192 |
+
skb_copy_from_linear_data_offset(head_skb, -tnl_hlen,
|
| 193 |
+
nskb->data - tnl_hlen,
|
| 194 |
+
doffset + tnl_hlen);
|
| 195 |
+
|
| 196 |
+
if (nskb->len == len + doffset)
|
| 197 |
+
goto perform_csum_check;
|
| 198 |
+
|
| 199 |
+
if (!sg) {
|
| 200 |
+
if (!csum) {
|
| 201 |
+
if (!nskb->remcsum_offload)
|
| 202 |
+
nskb->ip_summed = CHECKSUM_NONE;
|
| 203 |
+
SKB_GSO_CB(nskb)->csum =
|
| 204 |
+
skb_copy_and_csum_bits(head_skb, offset,
|
| 205 |
+
skb_put(nskb,
|
| 206 |
+
len),
|
| 207 |
+
len);
|
| 208 |
+
SKB_GSO_CB(nskb)->csum_start =
|
| 209 |
+
skb_headroom(nskb) + doffset;
|
| 210 |
+
} else {
|
| 211 |
+
if (skb_copy_bits(head_skb, offset, skb_put(nskb, len), len))
|
| 212 |
+
goto err;
|
| 213 |
+
}
|
| 214 |
+
continue;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
nskb_frag = skb_shinfo(nskb)->frags;
|
| 218 |
+
|
| 219 |
+
skb_copy_from_linear_data_offset(head_skb, offset,
|
| 220 |
+
skb_put(nskb, hsize), hsize);
|
| 221 |
+
|
| 222 |
+
skb_shinfo(nskb)->flags |= skb_shinfo(head_skb)->flags &
|
| 223 |
+
SKBFL_SHARED_FRAG;
|
| 224 |
+
|
| 225 |
+
if (skb_zerocopy_clone(nskb, frag_skb, GFP_ATOMIC))
|
| 226 |
+
goto err;
|
| 227 |
+
|
| 228 |
+
while (pos < offset + len) {
|
| 229 |
+
if (i >= nfrags) {
|
| 230 |
+
if (skb_orphan_frags(list_skb, GFP_ATOMIC) ||
|
| 231 |
+
skb_zerocopy_clone(nskb, list_skb,
|
| 232 |
+
GFP_ATOMIC))
|
| 233 |
+
goto err;
|
| 234 |
+
|
| 235 |
+
i = 0;
|
| 236 |
+
nfrags = skb_shinfo(list_skb)->nr_frags;
|
| 237 |
+
frag = skb_shinfo(list_skb)->frags;
|
| 238 |
+
frag_skb = list_skb;
|
| 239 |
+
if (!skb_headlen(list_skb)) {
|
| 240 |
+
BUG_ON(!nfrags);
|
| 241 |
+
} else {
|
| 242 |
+
BUG_ON(!list_skb->head_frag);
|
| 243 |
+
|
| 244 |
+
/* to make room for head_frag. */
|
| 245 |
+
i--;
|
| 246 |
+
frag--;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
list_skb = list_skb->next;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
if (unlikely(skb_shinfo(nskb)->nr_frags >=
|
| 253 |
+
MAX_SKB_FRAGS)) {
|
| 254 |
+
net_warn_ratelimited(
|
| 255 |
+
"skb_segment: too many frags: %u %u\n",
|
| 256 |
+
pos, mss);
|
| 257 |
+
err = -EINVAL;
|
| 258 |
+
goto err;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
*nskb_frag = (i < 0) ? skb_head_frag_to_page_desc(frag_skb) : *frag;
|
| 262 |
+
__skb_frag_ref(nskb_frag);
|
| 263 |
+
size = skb_frag_size(nskb_frag);
|
| 264 |
+
|
| 265 |
+
if (pos < offset) {
|
| 266 |
+
skb_frag_off_add(nskb_frag, offset - pos);
|
| 267 |
+
skb_frag_size_sub(nskb_frag, offset - pos);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
skb_shinfo(nskb)->nr_frags++;
|
| 271 |
+
|
| 272 |
+
if (pos + size <= offset + len) {
|
| 273 |
+
i++;
|
| 274 |
+
frag++;
|
| 275 |
+
pos += size;
|
| 276 |
+
} else {
|
| 277 |
+
skb_frag_size_sub(nskb_frag, pos + size - (offset + len));
|
| 278 |
+
goto skip_fraglist;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
nskb_frag++;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
skip_fraglist:
|
| 285 |
+
nskb->data_len = len - hsize;
|
| 286 |
+
nskb->len += nskb->data_len;
|
| 287 |
+
nskb->truesize += nskb->data_len;
|
| 288 |
+
|
| 289 |
+
perform_csum_check:
|
| 290 |
+
if (!csum) {
|
| 291 |
+
if (skb_has_shared_frag(nskb) &&
|
| 292 |
+
__skb_linearize(nskb))
|
| 293 |
+
goto err;
|
| 294 |
+
|
| 295 |
+
if (!nskb->remcsum_offload)
|
| 296 |
+
nskb->ip_summed = CHECKSUM_NONE;
|
| 297 |
+
SKB_GSO_CB(nskb)->csum =
|
| 298 |
+
skb_checksum(nskb, doffset,
|
| 299 |
+
nskb->len - doffset, 0);
|
| 300 |
+
SKB_GSO_CB(nskb)->csum_start =
|
| 301 |
+
skb_headroom(nskb) + doffset;
|
| 302 |
+
}
|
| 303 |
+
} while ((offset += len) < head_skb->len);
|
| 304 |
+
|
| 305 |
+
/* Some callers want to get the end of the list.
|
| 306 |
+
* Put it in segs->prev to avoid walking the list.
|
| 307 |
+
* (see validate_xmit_skb_list() for example)
|
| 308 |
+
*/
|
| 309 |
+
segs->prev = tail;
|
| 310 |
+
|
| 311 |
+
if (partial_segs) {
|
| 312 |
+
struct sk_buff *iter;
|
| 313 |
+
int type = skb_shinfo(head_skb)->gso_type;
|
| 314 |
+
unsigned short gso_size = skb_shinfo(head_skb)->gso_size;
|
| 315 |
+
|
| 316 |
+
/* Update type to add partial and then remove dodgy if set */
|
| 317 |
+
type |= (features & NETIF_F_GSO_PARTIAL) / NETIF_F_GSO_PARTIAL * SKB_GSO_PARTIAL;
|
| 318 |
+
type &= ~SKB_GSO_DODGY;
|
| 319 |
+
|
| 320 |
+
/* Update GSO info and prepare to start updating headers on
|
| 321 |
+
* our way back down the stack of protocols.
|
| 322 |
+
*/
|
| 323 |
+
for (iter = segs; iter; iter = iter->next) {
|
| 324 |
+
skb_shinfo(iter)->gso_size = gso_size;
|
| 325 |
+
skb_shinfo(iter)->gso_segs = partial_se
|
| 326 |
+
|
| 327 |
+
// ... (685 more chars)
|
| 328 |
+
```
|
tasks/csa159/pair_164140/task_prompt.md
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `syntax_only`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- Only process_score failed (79.35 below threshold). hard_validation, objective_gate G6, refinement_accepted, semantic_mechanism, semantic_score, anchor_free, and hardcoding_free already passed.
|
| 330 |
+
- Validation-and-recovery scored 7/10 because two synthetic analyzer repros never recovered: one called undeclared min(); the other broke parsing a hand-rolled min/__careful_cmp/__builtin_choose_expr expansion.
|
| 331 |
+
- Plan-to-code consistency scored 9/12: on B = B * P the multiplier extractor can bind the reused divisor VarDecl instead of the recorded quotient.
|
| 332 |
+
- CSA implementation quality marked has_report_logic false (EmitBasicReport without a BugType member or dedicated report helper), costing 0.5/4.
|
| 333 |
+
- Eight fix cycles were consumed recovering compile failures (deprecated StringRef::startswith, undeclared ExprStmt), inflating process cost after checker.so already built.
|
| 334 |
+
|
| 335 |
+
### Preserve from prior rollouts
|
| 336 |
+
|
| 337 |
+
- Preserve successful compile, before/after validation, and code verification.
|
| 338 |
+
- Preserve objective eligibility gate G6.
|
| 339 |
+
- Preserve an accepted or clean refinement outcome.
|
| 340 |
+
- Preserve the previously adequate syntax_only CSA mechanism (same-function AST pattern match of the patched arithmetic; no ProgramState or interprocedural machinery).
|
| 341 |
+
- Preserve semantic score at or above the configured threshold.
|
| 342 |
+
- Do not introduce patch-anchor dependence.
|
| 343 |
+
- Do not introduce patch-local hardcoding.
|
| 344 |
+
|
| 345 |
+
### Required semantic proof
|
| 346 |
+
|
| 347 |
+
- Prove an unsigned same-function idiom P = A / B followed by self-multiply B *= P or B = B * P where dividend A is not statically bounded below the GSO_BY_FRAGS sentinel 0xFFFF, so B * P can wrap to that forbidden value.
|
| 348 |
+
- Treat a min-style cap of A whose subtree evaluates to GSO_BY_FRAGS-1 (65534 / 0xFFFE) as the safe form that keeps B * P <= 65534.
|
| 349 |
+
- The intended true positive is skb_segment GSO-partial arithmetic: uncapped len/mss folded back into mss; the patched min(len, GSO_BY_FRAGS-1)/mss form must be silent.
|
| 350 |
+
- The diagnostic must be raised at the self-multiply sink, not at the division.
|
| 351 |
+
|
| 352 |
+
### Implementation constraints
|
| 353 |
+
|
| 354 |
+
- Implement Checker<check::ASTCodeBody> (or equivalent one-pass function-body AST walk) that records unsigned division assignments then matches a later self-multiply of the same divisor by that quotient.
|
| 355 |
+
- Register a BugType and emit through BugReporter at the multiply statement so report logic is structurally present.
|
| 356 |
+
- Recognize Linux min-family AST (ChooseExpr, StmtExpr, ConditionalOperator, min/min_t/clamp-style calls) plus a constant 65534 as the project GSO cap, not as a file- or hunk-local token.
|
| 357 |
+
- Match only unsigned integer VarDecl pairs inside one function body; do not key off skb_segment, net/core/skbuff.c, CVE ids, or changed line numbers.
|
| 358 |
+
- Use current LLVM/Clang APIs and real Stmt/Expr nodes only.
|
| 359 |
+
- When the multiply RHS is BO_Mul, the matched multiplier must be the recorded quotient VarDecl, never the LHS divisor.
|
| 360 |
+
|
| 361 |
+
### Validation checklist
|
| 362 |
+
|
| 363 |
+
- Fresh sources compile to a loadable checker.so with zero compiler diagnostics.
|
| 364 |
+
- Pre-patch scan of net/core/skbuff.c::skb_segment reports at mss *= partial_segs (median distance about 1 line from the patched arithmetic).
|
| 365 |
+
- Post-patch scan is clean on min(len, GSO_BY_FRAGS-1)/mss (n_patched=0, patched_clean).
|
| 366 |
+
- Differential: relevant warnings disappear only inside skb_segment; unrelated disappearances stay 0; sparsity/relevance remain 1.0.
|
| 367 |
+
- Cross-validation stays VALID and refinement stays accepted or clean.
|
| 368 |
+
- If a standalone repro is used, it must compile with a min() that actually produces a capping AST containing 65534, and any analyzer failure must be recovered.
|
| 369 |
+
- Re-score process_score above threshold without dropping G6 or semantic_score.
|
| 370 |
+
|
| 371 |
+
### Avoid and forbidden regressions
|
| 372 |
+
|
| 373 |
+
- Do not edit, clone, resume, or reconstruct the prior MssOverflowChecker/BodyWalker.
|
| 374 |
+
- Do not finish with unrecovered synthetic repros that cannot compile or cannot expand min().
|
| 375 |
+
- Do not call StringRef::startswith or dyn_cast to ExprStmt.
|
| 376 |
+
- Do not treat either operand of B = B * P as interchangeable.
|
| 377 |
+
- Do not use path-sensitive SVal tracking of mss*partial_segs or a PreStmt-only callback that cannot see the earlier division.
|
| 378 |
+
- Do not encode the patch hunk, source path, or function name as the match key.
|
| 379 |
+
- Do not omit a BugType/report helper.
|
| 380 |
+
- Do not burn repeated compile-fix cycles on deprecated or non-existent AST APIs.
|
tasks/csa159/pair_164279/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_164279/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "6da6680632792709cecf2b006f2fe3ca7857e791",
|
| 4 |
+
"after_commit": "d0aac2363549e12cc79b8e285f13d5a9f42fd08e",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/a38297e3fb012ddfa7ce0321a7e5a8daeb1872b6/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/a38297e3fb012ddfa7ce0321a7e5a8daeb1872b6/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"block/blk-cgroup.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "blk-cgroup: fix list corruption from reorder of WRITE ->lqueued\n\n__blkcg_rstat_flush() can be run anytime, especially when blk_cgroup_bio_start\nis being executed.\n\nIf WRITE of `->lqueued` is re-ordered with READ of 'bisc->lnode.next' in\nthe loop of __blkcg_rstat_flush(), `next_bisc` can be assigned with one\nstat instance being added in blk_cgroup_bio_start(), then the local\nlist in __blkcg_rstat_flush() could be corrupted.\n\nFix the issue by adding one barrier.\n\nCc: Tejun Heo <tj@kernel.org>\nCc: Waiman Long <longman@redhat.com>\nFixes: 3b8cc6298724 (\"blk-cgroup: Optimize blkcg_rstat_flush()\")\nSigned-off-by: Ming Lei <ming.lei@redhat.com>\nLink: https://lore.kernel.org/r/20240515013157.443672-3-ming.lei@redhat.com\nSigned-off-by: Jens Axboe <axboe@kernel.dk>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_164279/patch.diff
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
|
| 2 |
+
index 8699f193cf31..52367a4501d0 100644
|
| 3 |
+
--- a/block/blk-cgroup.c
|
| 4 |
+
+++ b/block/blk-cgroup.c
|
| 5 |
+
@@ -1035,6 +1035,16 @@ static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
|
| 6 |
+
struct blkg_iostat cur;
|
| 7 |
+
unsigned int seq;
|
| 8 |
+
|
| 9 |
+
+ /*
|
| 10 |
+
+ * Order assignment of `next_bisc` from `bisc->lnode.next` in
|
| 11 |
+
+ * llist_for_each_entry_safe and clearing `bisc->lqueued` for
|
| 12 |
+
+ * avoiding to assign `next_bisc` with new next pointer added
|
| 13 |
+
+ * in blk_cgroup_bio_start() in case of re-ordering.
|
| 14 |
+
+ *
|
| 15 |
+
+ * The pair barrier is implied in llist_add() in blk_cgroup_bio_start().
|
| 16 |
+
+ */
|
| 17 |
+
+ smp_mb();
|
| 18 |
+
+
|
| 19 |
+
WRITE_ONCE(bisc->lqueued, false);
|
| 20 |
+
|
| 21 |
+
/* fetch the current per-cpu values */
|
tasks/csa159/pair_164279/post_functions.txt
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: block/blk-cgroup.c
|
| 2 |
+
```c
|
| 3 |
+
static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
|
| 4 |
+
{
|
| 5 |
+
struct llist_head *lhead = per_cpu_ptr(blkcg->lhead, cpu);
|
| 6 |
+
struct llist_node *lnode;
|
| 7 |
+
struct blkg_iostat_set *bisc, *next_bisc;
|
| 8 |
+
unsigned long flags;
|
| 9 |
+
|
| 10 |
+
rcu_read_lock();
|
| 11 |
+
|
| 12 |
+
lnode = llist_del_all(lhead);
|
| 13 |
+
if (!lnode)
|
| 14 |
+
goto out;
|
| 15 |
+
|
| 16 |
+
/*
|
| 17 |
+
* For covering concurrent parent blkg update from blkg_release().
|
| 18 |
+
*
|
| 19 |
+
* When flushing from cgroup, cgroup_rstat_lock is always held, so
|
| 20 |
+
* this lock won't cause contention most of time.
|
| 21 |
+
*/
|
| 22 |
+
raw_spin_lock_irqsave(&blkg_stat_lock, flags);
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
* Iterate only the iostat_cpu's queued in the lockless list.
|
| 26 |
+
*/
|
| 27 |
+
llist_for_each_entry_safe(bisc, next_bisc, lnode, lnode) {
|
| 28 |
+
struct blkcg_gq *blkg = bisc->blkg;
|
| 29 |
+
struct blkcg_gq *parent = blkg->parent;
|
| 30 |
+
struct blkg_iostat cur;
|
| 31 |
+
unsigned int seq;
|
| 32 |
+
|
| 33 |
+
/*
|
| 34 |
+
* Order assignment of `next_bisc` from `bisc->lnode.next` in
|
| 35 |
+
* llist_for_each_entry_safe and clearing `bisc->lqueued` for
|
| 36 |
+
* avoiding to assign `next_bisc` with new next pointer added
|
| 37 |
+
* in blk_cgroup_bio_start() in case of re-ordering.
|
| 38 |
+
*
|
| 39 |
+
* The pair barrier is implied in llist_add() in blk_cgroup_bio_start().
|
| 40 |
+
*/
|
| 41 |
+
smp_mb();
|
| 42 |
+
|
| 43 |
+
WRITE_ONCE(bisc->lqueued, false);
|
| 44 |
+
|
| 45 |
+
/* fetch the current per-cpu values */
|
| 46 |
+
do {
|
| 47 |
+
seq = u64_stats_fetch_begin(&bisc->sync);
|
| 48 |
+
blkg_iostat_set(&cur, &bisc->cur);
|
| 49 |
+
} while (u64_stats_fetch_retry(&bisc->sync, seq));
|
| 50 |
+
|
| 51 |
+
blkcg_iostat_update(blkg, &cur, &bisc->last);
|
| 52 |
+
|
| 53 |
+
/* propagate global delta to parent (unless that's root) */
|
| 54 |
+
if (parent && parent->parent)
|
| 55 |
+
blkcg_iostat_update(parent, &blkg->iostat.cur,
|
| 56 |
+
&blkg->iostat.last);
|
| 57 |
+
}
|
| 58 |
+
raw_spin_unlock_irqrestore(&blkg_stat_lock, flags);
|
| 59 |
+
out:
|
| 60 |
+
rcu_read_unlock();
|
| 61 |
+
}
|
| 62 |
+
```
|
tasks/csa159/pair_164279/pre_functions.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: block/blk-cgroup.c
|
| 2 |
+
```c
|
| 3 |
+
static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
|
| 4 |
+
{
|
| 5 |
+
struct llist_head *lhead = per_cpu_ptr(blkcg->lhead, cpu);
|
| 6 |
+
struct llist_node *lnode;
|
| 7 |
+
struct blkg_iostat_set *bisc, *next_bisc;
|
| 8 |
+
unsigned long flags;
|
| 9 |
+
|
| 10 |
+
rcu_read_lock();
|
| 11 |
+
|
| 12 |
+
lnode = llist_del_all(lhead);
|
| 13 |
+
if (!lnode)
|
| 14 |
+
goto out;
|
| 15 |
+
|
| 16 |
+
/*
|
| 17 |
+
* For covering concurrent parent blkg update from blkg_release().
|
| 18 |
+
*
|
| 19 |
+
* When flushing from cgroup, cgroup_rstat_lock is always held, so
|
| 20 |
+
* this lock won't cause contention most of time.
|
| 21 |
+
*/
|
| 22 |
+
raw_spin_lock_irqsave(&blkg_stat_lock, flags);
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
* Iterate only the iostat_cpu's queued in the lockless list.
|
| 26 |
+
*/
|
| 27 |
+
llist_for_each_entry_safe(bisc, next_bisc, lnode, lnode) {
|
| 28 |
+
struct blkcg_gq *blkg = bisc->blkg;
|
| 29 |
+
struct blkcg_gq *parent = blkg->parent;
|
| 30 |
+
struct blkg_iostat cur;
|
| 31 |
+
unsigned int seq;
|
| 32 |
+
|
| 33 |
+
WRITE_ONCE(bisc->lqueued, false);
|
| 34 |
+
|
| 35 |
+
/* fetch the current per-cpu values */
|
| 36 |
+
do {
|
| 37 |
+
seq = u64_stats_fetch_begin(&bisc->sync);
|
| 38 |
+
blkg_iostat_set(&cur, &bisc->cur);
|
| 39 |
+
} while (u64_stats_fetch_retry(&bisc->sync, seq));
|
| 40 |
+
|
| 41 |
+
blkcg_iostat_update(blkg, &cur, &bisc->last);
|
| 42 |
+
|
| 43 |
+
/* propagate global delta to parent (unless that's root) */
|
| 44 |
+
if (parent && parent->parent)
|
| 45 |
+
blkcg_iostat_update(parent, &blkg->iostat.cur,
|
| 46 |
+
&blkg->iostat.last);
|
| 47 |
+
}
|
| 48 |
+
raw_spin_unlock_irqrestore(&blkg_stat_lock, flags);
|
| 49 |
+
out:
|
| 50 |
+
rcu_read_unlock();
|
| 51 |
+
}
|
| 52 |
+
```
|
tasks/csa159/pair_164279/task_prompt.md
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
tasks/csa159/pair_164624/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_164624/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "8adc718881e0a70127f8843dd70e69a80de39352",
|
| 4 |
+
"after_commit": "78a033433a5ae4fee85511ee075bc9a48312c79e",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/f0e2f00c49db0cba1feff7ce5a5f163d2152056f/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/f0e2f00c49db0cba1feff7ce5a5f163d2152056f/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"drivers/gpu/drm/i915/gt/intel_engine_cs.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "drm/i915/gt: Cleanup partial engine discovery failures\n\nIf we abort driver initialisation in the middle of gt/engine discovery,\nsome engines will be fully setup and some not. Those incompletely setup\nengines only have 'engine->release == NULL' and so will leak any of the\ncommon objects allocated.\n\nv2:\n - Drop the destroy_pinned_context() helper for now. It's not really\n worth it with just a single callsite at the moment. (Janusz)\n\nSigned-off-by: Chris Wilson <chris.p.wilson@intel.com>\nCc: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>\nSigned-off-by: Matt Roper <matthew.d.roper@intel.com>\nReviewed-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>\nLink: https://patchwork.freedesktop.org/patch/msgid/20220915232654.3283095-2-matthew.d.roper@intel.com",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_164624/patch.diff
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
|
| 2 |
+
index 1f7188129cd1..2ddcad497fa3 100644
|
| 3 |
+
--- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c
|
| 4 |
+
+++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
|
| 5 |
+
@@ -1274,8 +1274,13 @@ int intel_engines_init(struct intel_gt *gt)
|
| 6 |
+
return err;
|
| 7 |
+
|
| 8 |
+
err = setup(engine);
|
| 9 |
+
- if (err)
|
| 10 |
+
+ if (err) {
|
| 11 |
+
+ intel_engine_cleanup_common(engine);
|
| 12 |
+
return err;
|
| 13 |
+
+ }
|
| 14 |
+
+
|
| 15 |
+
+ /* The backend should now be responsible for cleanup */
|
| 16 |
+
+ GEM_BUG_ON(engine->release == NULL);
|
| 17 |
+
|
| 18 |
+
err = engine_init_common(engine);
|
| 19 |
+
if (err)
|
tasks/csa159/pair_164624/post_functions.txt
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: drivers/gpu/drm/i915/gt/intel_engine_cs.c
|
| 2 |
+
```c
|
| 3 |
+
int intel_engines_init(struct intel_gt *gt)
|
| 4 |
+
{
|
| 5 |
+
int (*setup)(struct intel_engine_cs *engine);
|
| 6 |
+
struct intel_engine_cs *engine;
|
| 7 |
+
enum intel_engine_id id;
|
| 8 |
+
int err;
|
| 9 |
+
|
| 10 |
+
if (intel_uc_uses_guc_submission(>->uc)) {
|
| 11 |
+
gt->submission_method = INTEL_SUBMISSION_GUC;
|
| 12 |
+
setup = intel_guc_submission_setup;
|
| 13 |
+
} else if (HAS_EXECLISTS(gt->i915)) {
|
| 14 |
+
gt->submission_method = INTEL_SUBMISSION_ELSP;
|
| 15 |
+
setup = intel_execlists_submission_setup;
|
| 16 |
+
} else {
|
| 17 |
+
gt->submission_method = INTEL_SUBMISSION_RING;
|
| 18 |
+
setup = intel_ring_submission_setup;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
for_each_engine(engine, gt, id) {
|
| 22 |
+
err = engine_setup_common(engine);
|
| 23 |
+
if (err)
|
| 24 |
+
return err;
|
| 25 |
+
|
| 26 |
+
err = setup(engine);
|
| 27 |
+
if (err) {
|
| 28 |
+
intel_engine_cleanup_common(engine);
|
| 29 |
+
return err;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/* The backend should now be responsible for cleanup */
|
| 33 |
+
GEM_BUG_ON(engine->release == NULL);
|
| 34 |
+
|
| 35 |
+
err = engine_init_common(engine);
|
| 36 |
+
if (err)
|
| 37 |
+
return err;
|
| 38 |
+
|
| 39 |
+
intel_engine_add_user(engine);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
return 0;
|
| 43 |
+
}
|
| 44 |
+
```
|
tasks/csa159/pair_164624/pre_functions.txt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: drivers/gpu/drm/i915/gt/intel_engine_cs.c
|
| 2 |
+
```c
|
| 3 |
+
int intel_engines_init(struct intel_gt *gt)
|
| 4 |
+
{
|
| 5 |
+
int (*setup)(struct intel_engine_cs *engine);
|
| 6 |
+
struct intel_engine_cs *engine;
|
| 7 |
+
enum intel_engine_id id;
|
| 8 |
+
int err;
|
| 9 |
+
|
| 10 |
+
if (intel_uc_uses_guc_submission(>->uc)) {
|
| 11 |
+
gt->submission_method = INTEL_SUBMISSION_GUC;
|
| 12 |
+
setup = intel_guc_submission_setup;
|
| 13 |
+
} else if (HAS_EXECLISTS(gt->i915)) {
|
| 14 |
+
gt->submission_method = INTEL_SUBMISSION_ELSP;
|
| 15 |
+
setup = intel_execlists_submission_setup;
|
| 16 |
+
} else {
|
| 17 |
+
gt->submission_method = INTEL_SUBMISSION_RING;
|
| 18 |
+
setup = intel_ring_submission_setup;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
for_each_engine(engine, gt, id) {
|
| 22 |
+
err = engine_setup_common(engine);
|
| 23 |
+
if (err)
|
| 24 |
+
return err;
|
| 25 |
+
|
| 26 |
+
err = setup(engine);
|
| 27 |
+
if (err)
|
| 28 |
+
return err;
|
| 29 |
+
|
| 30 |
+
err = engine_init_common(engine);
|
| 31 |
+
if (err)
|
| 32 |
+
return err;
|
| 33 |
+
|
| 34 |
+
intel_engine_add_user(engine);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
return 0;
|
| 38 |
+
}
|
| 39 |
+
```
|
tasks/csa159/pair_164624/task_prompt.md
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `path_sensitive`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- The prior checker tracked an acquired object until an explicit common cleanup, but never cleared or transferred that obligation after backend setup succeeded; it therefore reported the later engine_init_common failure even though backend teardown owns the object at that point.
|
| 330 |
+
- Suffix-based acquire and release matching generalized beyond the specific engine initialization protocol, leaving semantic ownership insufficiently modeled.
|
| 331 |
+
- The rollout remained refinement-unaccepted because its semantic result was only partial, and process quality was below threshold despite successful compilation, validation, and hardcoding checks.
|
| 332 |
+
|
| 333 |
+
### Preserve from prior rollouts
|
| 334 |
+
|
| 335 |
+
- Preserve successful compilation, before/after validation, and code verification.
|
| 336 |
+
- Preserve objective eligibility gate G6.
|
| 337 |
+
- Preserve the previously adequate path-sensitive CSA mechanism level.
|
| 338 |
+
- Preserve semantic score at or above the configured threshold.
|
| 339 |
+
- Do not introduce dependence on patch anchors such as changed line numbers, local patch text, or exact diff locations.
|
| 340 |
+
- Do not introduce patch-local hardcoding.
|
| 341 |
+
|
| 342 |
+
### Required semantic proof
|
| 343 |
+
|
| 344 |
+
- On a path where engine_setup_common(engine) successfully acquires common resources, establish that a nonzero return from the subsequent backend setup(engine) is an error path requiring intel_engine_cleanup_common(engine).
|
| 345 |
+
- Suppress the diagnostic when the acquisition call itself returns the failing value, because that path does not establish a successfully acquired resource.
|
| 346 |
+
- Discharge the common-resource obligation when intel_engine_cleanup_common(engine) executes on the same path.
|
| 347 |
+
- Model successful backend setup(engine) as an ownership transfer to the backend, so a later engine_init_common(engine) failure is not reported as a missing common cleanup.
|
| 348 |
+
- Report the vulnerable return locally in intel_engines_init at the failed backend setup path, and distinguish it from normal zero returns and ownership-transferred paths.
|
| 349 |
+
|
| 350 |
+
### Implementation constraints
|
| 351 |
+
|
| 352 |
+
- Use ProgramState to carry the per-object acquisition, release, acquisition-result, and ownership-transfer facts along each path.
|
| 353 |
+
- Use check::PostCall to observe the relevant helper calls and setup result, and check::PreStmt<ReturnStmt> to inspect the same-path obligation and prove a nonzero integer error return.
|
| 354 |
+
- Key tracked facts by the managed object region and preserve frame ownership so diagnostics are not emitted for unrelated inlined callees or objects.
|
| 355 |
+
- Recognize the specific project protocol represented by engine_setup_common, intel_engine_cleanup_common, setup, and engine_init_common rather than relying on unrestricted suffix-only helper matching.
|
| 356 |
+
- Attach the report to the actual error return and the tracked object, with no diagnostics for normal returns, unconstrained return values, or non-error return types.
|
| 357 |
+
- Keep the checker project-general over the documented helper and ownership convention; do not encode patch line numbers, changed text, local variable names, or exact patch anchors.
|
| 358 |
+
|
| 359 |
+
### Validation checklist
|
| 360 |
+
|
| 361 |
+
- Compile the new checker successfully against the CSA API and verify that the produced checker artifact loads.
|
| 362 |
+
- Run both vulnerable and patched revisions through the scan and code-verification validation without regressing hard validation.
|
| 363 |
+
- Confirm the vulnerable revision reports the failed setup(engine) return in intel_engines_init and that the patched revision has no corresponding report there.
|
| 364 |
+
- Confirm the later engine_init_common failure is not reported in the patched revision because successful setup transferred teardown responsibility.
|
| 365 |
+
- Verify that acquisition-self-failure paths, zero returns, and paths with explicit intel_engine_cleanup_common do not produce diagnostics.
|
| 366 |
+
- Verify differential and scope behavior: the relevant warning disappears after the patch, no unrelated non-patched warnings disappear, and report locations remain near the affected function.
|
| 367 |
+
- Recheck anchor-free and hardcoding-free status, objective gate G6, semantic mechanism level, and configured semantic-score threshold.
|
| 368 |
+
|
| 369 |
+
### Avoid and forbidden regressions
|
| 370 |
+
|
| 371 |
+
- Do not treat every still-pending explicit cleanup obligation as a leak after successful backend setup; represent ownership transfer before evaluating later returns.
|
| 372 |
+
- Do not use syntax-only matching of an if-and-return shape, EndFunction, or PostStmt<ReturnStmt> as the primary proof of the path-specific defect.
|
| 373 |
+
- Do not report merely because a resource lacks an explicit common cleanup when backend ownership has been established.
|
| 374 |
+
- Do not broaden matching to arbitrary names that happen to share acquire or release suffixes without proving the corresponding object protocol.
|
| 375 |
+
- Do not weaken the accepted path-sensitive contract to improve process or differential scores.
|
| 376 |
+
- Do not regress compilation, before/after validation, code verification, objective eligibility, semantic adequacy, anchor independence, or hardcoding independence.
|
tasks/csa159/pair_164760/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_164760/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "965adae5a33a998e2b62ec1b37c5eb21f1875b15",
|
| 4 |
+
"after_commit": "15a901361ec3fb1c393f91880e1cbf24ec0a88bd",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/ffd294d346d185b70e28b1a28abe367bbfe53c04/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/ffd294d346d185b70e28b1a28abe367bbfe53c04/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"net/ipv4/ipmr_base.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "ipmr: do not call mr_mfc_uses_dev() for unres entries\n\nsyzbot found that calling mr_mfc_uses_dev() for unres entries\nwould crash [1], because c->mfc_un.res.minvif / c->mfc_un.res.maxvif\nalias to \"struct sk_buff_head unresolved\", which contain two pointers.\n\nThis code never worked, lets remove it.\n\n[1]\nUnable to handle kernel paging request at virtual address ffff5fff2d536613\nKASAN: maybe wild-memory-access in range [0xfffefff96a9b3098-0xfffefff96a9b309f]\nModules linked in:\nCPU: 1 UID: 0 PID: 7321 Comm: syz.0.16 Not tainted 6.13.0-rc7-syzkaller-g1950a0af2d55 #0\nHardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024\npstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)\n pc : mr_mfc_uses_dev net/ipv4/ipmr_base.c:290 [inline]\n pc : mr_table_dump+0x5a4/0x8b0 net/ipv4/ipmr_base.c:334\n lr : mr_mfc_uses_dev net/ipv4/ipmr_base.c:289 [inline]\n lr : mr_table_dump+0x694/0x8b0 net/ipv4/ipmr_base.c:334\nCall trace:\n mr_mfc_uses_dev net/ipv4/ipmr_base.c:290 [inline] (P)\n mr_table_dump+0x5a4/0x8b0 net/ipv4/ipmr_base.c:334 (P)\n mr_rtm_dumproute+0x254/0x454 net/ipv4/ipmr_base.c:382\n ipmr_rtm_dumproute+0x248/0x4b4 net/ipv4/ipmr.c:2648\n rtnl_dump_all+0x2e4/0x4e8 net/core/rtnetlink.c:4327\n rtnl_dumpit+0x98/0x1d0 net/core/rtnetlink.c:6791\n netlink_dump+0x4f0/0xbc0 net/netlink/af_netlink.c:2317\n netlink_recvmsg+0x56c/0xe64 net/netlink/af_netlink.c:1973\n sock_recvmsg_nosec net/socket.c:1033 [inline]\n sock_recvmsg net/socket.c:1055 [inline]\n sock_read_iter+0x2d8/0x40c net/socket.c:1125\n new_sync_read fs/read_write.c:484 [inline]\n vfs_read+0x740/0x970 fs/read_write.c:565\n ksys_read+0x15c/0x26c fs/read_write.c:708\n\nFixes: cb167893f41e (\"net: Plumb support for filtering ipv4 and ipv6 multicast route dumps\")\nReported-by: syzbot+5cfae50c0e5f2c500013@syzkaller.appspotmail.com\nCloses: https://lore.kernel.org/netdev/678fe2d1.050a0220.15cac.00b3.GAE@google.com/T/#u\nSigned-off-by: Eric Dumazet <edumazet@google.com>\nReviewed-by: David Ahern <dsahern@kernel.org>\nLink: https://patch.msgid.link/20250121181241.841212-1-edumazet@google.com\nSigned-off-by: Jakub Kicinski <kuba@kernel.org>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_164760/patch.diff
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c
|
| 2 |
+
index 03b6eee407a2..28d77d454d44 100644
|
| 3 |
+
--- a/net/ipv4/ipmr_base.c
|
| 4 |
+
+++ b/net/ipv4/ipmr_base.c
|
| 5 |
+
@@ -330,9 +330,6 @@ int mr_table_dump(struct mr_table *mrt, struct sk_buff *skb,
|
| 6 |
+
list_for_each_entry(mfc, &mrt->mfc_unres_queue, list) {
|
| 7 |
+
if (e < s_e)
|
| 8 |
+
goto next_entry2;
|
| 9 |
+
- if (filter->dev &&
|
| 10 |
+
- !mr_mfc_uses_dev(mrt, mfc, filter->dev))
|
| 11 |
+
- goto next_entry2;
|
| 12 |
+
|
| 13 |
+
err = fill(mrt, skb, NETLINK_CB(cb->skb).portid,
|
| 14 |
+
cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, flags);
|
tasks/csa159/pair_164760/post_functions.txt
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/ipv4/ipmr_base.c
|
| 2 |
+
```c
|
| 3 |
+
int mr_table_dump(struct mr_table *mrt, struct sk_buff *skb,
|
| 4 |
+
struct netlink_callback *cb,
|
| 5 |
+
int (*fill)(struct mr_table *mrt, struct sk_buff *skb,
|
| 6 |
+
u32 portid, u32 seq, struct mr_mfc *c,
|
| 7 |
+
int cmd, int flags),
|
| 8 |
+
spinlock_t *lock, struct fib_dump_filter *filter)
|
| 9 |
+
{
|
| 10 |
+
unsigned int e = 0, s_e = cb->args[1];
|
| 11 |
+
unsigned int flags = NLM_F_MULTI;
|
| 12 |
+
struct mr_mfc *mfc;
|
| 13 |
+
int err;
|
| 14 |
+
|
| 15 |
+
if (filter->filter_set)
|
| 16 |
+
flags |= NLM_F_DUMP_FILTERED;
|
| 17 |
+
|
| 18 |
+
list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list,
|
| 19 |
+
lockdep_rtnl_is_held()) {
|
| 20 |
+
if (e < s_e)
|
| 21 |
+
goto next_entry;
|
| 22 |
+
if (filter->dev &&
|
| 23 |
+
!mr_mfc_uses_dev(mrt, mfc, filter->dev))
|
| 24 |
+
goto next_entry;
|
| 25 |
+
|
| 26 |
+
err = fill(mrt, skb, NETLINK_CB(cb->skb).portid,
|
| 27 |
+
cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, flags);
|
| 28 |
+
if (err < 0)
|
| 29 |
+
goto out;
|
| 30 |
+
next_entry:
|
| 31 |
+
e++;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
spin_lock_bh(lock);
|
| 35 |
+
list_for_each_entry(mfc, &mrt->mfc_unres_queue, list) {
|
| 36 |
+
if (e < s_e)
|
| 37 |
+
goto next_entry2;
|
| 38 |
+
|
| 39 |
+
err = fill(mrt, skb, NETLINK_CB(cb->skb).portid,
|
| 40 |
+
cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, flags);
|
| 41 |
+
if (err < 0) {
|
| 42 |
+
spin_unlock_bh(lock);
|
| 43 |
+
goto out;
|
| 44 |
+
}
|
| 45 |
+
next_entry2:
|
| 46 |
+
e++;
|
| 47 |
+
}
|
| 48 |
+
spin_unlock_bh(lock);
|
| 49 |
+
err = 0;
|
| 50 |
+
out:
|
| 51 |
+
cb->args[1] = e;
|
| 52 |
+
return err;
|
| 53 |
+
}
|
| 54 |
+
```
|
tasks/csa159/pair_164760/pre_functions.txt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/ipv4/ipmr_base.c
|
| 2 |
+
```c
|
| 3 |
+
int mr_table_dump(struct mr_table *mrt, struct sk_buff *skb,
|
| 4 |
+
struct netlink_callback *cb,
|
| 5 |
+
int (*fill)(struct mr_table *mrt, struct sk_buff *skb,
|
| 6 |
+
u32 portid, u32 seq, struct mr_mfc *c,
|
| 7 |
+
int cmd, int flags),
|
| 8 |
+
spinlock_t *lock, struct fib_dump_filter *filter)
|
| 9 |
+
{
|
| 10 |
+
unsigned int e = 0, s_e = cb->args[1];
|
| 11 |
+
unsigned int flags = NLM_F_MULTI;
|
| 12 |
+
struct mr_mfc *mfc;
|
| 13 |
+
int err;
|
| 14 |
+
|
| 15 |
+
if (filter->filter_set)
|
| 16 |
+
flags |= NLM_F_DUMP_FILTERED;
|
| 17 |
+
|
| 18 |
+
list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list,
|
| 19 |
+
lockdep_rtnl_is_held()) {
|
| 20 |
+
if (e < s_e)
|
| 21 |
+
goto next_entry;
|
| 22 |
+
if (filter->dev &&
|
| 23 |
+
!mr_mfc_uses_dev(mrt, mfc, filter->dev))
|
| 24 |
+
goto next_entry;
|
| 25 |
+
|
| 26 |
+
err = fill(mrt, skb, NETLINK_CB(cb->skb).portid,
|
| 27 |
+
cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, flags);
|
| 28 |
+
if (err < 0)
|
| 29 |
+
goto out;
|
| 30 |
+
next_entry:
|
| 31 |
+
e++;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
spin_lock_bh(lock);
|
| 35 |
+
list_for_each_entry(mfc, &mrt->mfc_unres_queue, list) {
|
| 36 |
+
if (e < s_e)
|
| 37 |
+
goto next_entry2;
|
| 38 |
+
if (filter->dev &&
|
| 39 |
+
!mr_mfc_uses_dev(mrt, mfc, filter->dev))
|
| 40 |
+
goto next_entry2;
|
| 41 |
+
|
| 42 |
+
err = fill(mrt, skb, NETLINK_CB(cb->skb).portid,
|
| 43 |
+
cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, flags);
|
| 44 |
+
if (err < 0) {
|
| 45 |
+
spin_unlock_bh(lock);
|
| 46 |
+
goto out;
|
| 47 |
+
}
|
| 48 |
+
next_entry2:
|
| 49 |
+
e++;
|
| 50 |
+
}
|
| 51 |
+
spin_unlock_bh(lock);
|
| 52 |
+
err = 0;
|
| 53 |
+
out:
|
| 54 |
+
cb->args[1] = e;
|
| 55 |
+
return err;
|
| 56 |
+
}
|
| 57 |
+
```
|
tasks/csa159/pair_164760/task_prompt.md
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
tasks/csa159/pair_164920/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_164920/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "a47c397bb29fce1751dc755246a2c8deeca5e38f",
|
| 4 |
+
"after_commit": "7a6b1ab7475fd6478eeaf5c9d1163e7a18125c8f",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/c4681547bcce777daf576925a966ffa824edd09d/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/c4681547bcce777daf576925a966ffa824edd09d/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"net/core/neighbour.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "neighbour: allow NUD_NOARP entries to be forced GCed\n\nIFF_POINTOPOINT interfaces use NUD_NOARP entries for IPv6. It's possible to\nfill up the neighbour table with enough entries that it will overflow for\nvalid connections after that.\n\nThis behaviour is more prevalent after commit 58956317c8de (\"neighbor:\nImprove garbage collection\") is applied, as it prevents removal from\nentries that are not NUD_FAILED, unless they are more than 5s old.\n\nFixes: 58956317c8de (neighbor: Improve garbage collection)\nReported-by: Kasper Dupont <kasperd@gjkwv.06.feb.2021.kasperd.net>\nSigned-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>\nSigned-off-by: David Ahern <dsahern@kernel.org>\nSigned-off-by: David S. Miller <davem@davemloft.net>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_164920/patch.diff
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
|
| 2 |
+
index 98f20efbfadf..bf774575ad71 100644
|
| 3 |
+
--- a/net/core/neighbour.c
|
| 4 |
+
+++ b/net/core/neighbour.c
|
| 5 |
+
@@ -238,6 +238,7 @@ static int neigh_forced_gc(struct neigh_table *tbl)
|
| 6 |
+
|
| 7 |
+
write_lock(&n->lock);
|
| 8 |
+
if ((n->nud_state == NUD_FAILED) ||
|
| 9 |
+
+ (n->nud_state == NUD_NOARP) ||
|
| 10 |
+
(tbl->is_multicast &&
|
| 11 |
+
tbl->is_multicast(n->primary_key)) ||
|
| 12 |
+
time_after(tref, n->updated))
|
tasks/csa159/pair_164920/post_functions.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/core/neighbour.c
|
| 2 |
+
```c
|
| 3 |
+
static int neigh_forced_gc(struct neigh_table *tbl)
|
| 4 |
+
{
|
| 5 |
+
int max_clean = atomic_read(&tbl->gc_entries) - tbl->gc_thresh2;
|
| 6 |
+
unsigned long tref = jiffies - 5 * HZ;
|
| 7 |
+
struct neighbour *n, *tmp;
|
| 8 |
+
int shrunk = 0;
|
| 9 |
+
|
| 10 |
+
NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);
|
| 11 |
+
|
| 12 |
+
write_lock_bh(&tbl->lock);
|
| 13 |
+
|
| 14 |
+
list_for_each_entry_safe(n, tmp, &tbl->gc_list, gc_list) {
|
| 15 |
+
if (refcount_read(&n->refcnt) == 1) {
|
| 16 |
+
bool remove = false;
|
| 17 |
+
|
| 18 |
+
write_lock(&n->lock);
|
| 19 |
+
if ((n->nud_state == NUD_FAILED) ||
|
| 20 |
+
(n->nud_state == NUD_NOARP) ||
|
| 21 |
+
(tbl->is_multicast &&
|
| 22 |
+
tbl->is_multicast(n->primary_key)) ||
|
| 23 |
+
time_after(tref, n->updated))
|
| 24 |
+
remove = true;
|
| 25 |
+
write_unlock(&n->lock);
|
| 26 |
+
|
| 27 |
+
if (remove && neigh_remove_one(n, tbl))
|
| 28 |
+
shrunk++;
|
| 29 |
+
if (shrunk >= max_clean)
|
| 30 |
+
break;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
tbl->last_flush = jiffies;
|
| 35 |
+
|
| 36 |
+
write_unlock_bh(&tbl->lock);
|
| 37 |
+
|
| 38 |
+
return shrunk;
|
| 39 |
+
}
|
| 40 |
+
```
|
tasks/csa159/pair_164920/pre_functions.txt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/core/neighbour.c
|
| 2 |
+
```c
|
| 3 |
+
static int neigh_forced_gc(struct neigh_table *tbl)
|
| 4 |
+
{
|
| 5 |
+
int max_clean = atomic_read(&tbl->gc_entries) - tbl->gc_thresh2;
|
| 6 |
+
unsigned long tref = jiffies - 5 * HZ;
|
| 7 |
+
struct neighbour *n, *tmp;
|
| 8 |
+
int shrunk = 0;
|
| 9 |
+
|
| 10 |
+
NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);
|
| 11 |
+
|
| 12 |
+
write_lock_bh(&tbl->lock);
|
| 13 |
+
|
| 14 |
+
list_for_each_entry_safe(n, tmp, &tbl->gc_list, gc_list) {
|
| 15 |
+
if (refcount_read(&n->refcnt) == 1) {
|
| 16 |
+
bool remove = false;
|
| 17 |
+
|
| 18 |
+
write_lock(&n->lock);
|
| 19 |
+
if ((n->nud_state == NUD_FAILED) ||
|
| 20 |
+
(tbl->is_multicast &&
|
| 21 |
+
tbl->is_multicast(n->primary_key)) ||
|
| 22 |
+
time_after(tref, n->updated))
|
| 23 |
+
remove = true;
|
| 24 |
+
write_unlock(&n->lock);
|
| 25 |
+
|
| 26 |
+
if (remove && neigh_remove_one(n, tbl))
|
| 27 |
+
shrunk++;
|
| 28 |
+
if (shrunk >= max_clean)
|
| 29 |
+
break;
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
tbl->last_flush = jiffies;
|
| 34 |
+
|
| 35 |
+
write_unlock_bh(&tbl->lock);
|
| 36 |
+
|
| 37 |
+
return shrunk;
|
| 38 |
+
}
|
| 39 |
+
```
|
tasks/csa159/pair_164920/task_prompt.md
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `control_flow`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- The rollout failed the process-quality and hardcoding-free checks because the design embedded patch-specific context and did not provide a sufficiently general, rigorous implementation argument.
|
| 330 |
+
- Lexical parent lookup was treated as domination, while a whole-function AST scan collected assignments without proving that they reach the reclamation sink, occur before it, or define the guard value used there.
|
| 331 |
+
- The safety test was polarity-insensitive: `nud_state != NUD_NOARP`, negated tests, and arbitrary bit tests could suppress a report even though they exclude rather than admit NUD_NOARP.
|
| 332 |
+
- The analysis did not prove that the state predicate, flag definition, guard, and `neigh_remove_one` argument concern the same neighbour object.
|
| 333 |
+
- The stated consequence was overstated because multicast and age alternatives can still permit removal; the defect is absence of state-based eligibility for NUD_NOARP when the other alternatives are false.
|
| 334 |
+
|
| 335 |
+
### Preserve from prior rollouts
|
| 336 |
+
|
| 337 |
+
- The synthesized checker must compile successfully against the supplied CSA environment.
|
| 338 |
+
- Preserve successful differential validation: diagnostics must occur on the vulnerable source and disappear on the patched source.
|
| 339 |
+
- Preserve code verification and objective eligibility gate G6.
|
| 340 |
+
- Preserve an accepted or clean refinement outcome.
|
| 341 |
+
- Retain at least the previously adequate semantic score and CSA mechanism capability.
|
| 342 |
+
- Remain independent of patch anchors such as changed line numbers or diff locations.
|
| 343 |
+
|
| 344 |
+
### Required semantic proof
|
| 345 |
+
|
| 346 |
+
- Identify a reclamation call whose execution is control-dependent on a local eligibility value derived from predicates over a neighbour object's `nud_state`.
|
| 347 |
+
- Use CFG ordering and reaching-definition relationships to connect only definitions that can reach the sink guard before the sink; unrelated, overwritten, unreachable, or later assignments must not affect the result.
|
| 348 |
+
- Prove object identity between the neighbour passed to reclamation and the neighbour whose state is tested, accounting for casts and equivalent expression forms without conflating different objects.
|
| 349 |
+
- Interpret predicate polarity and Boolean structure so that only a positively effective NUD_NOARP alternative counts as coverage; inequality, negation, or a test on an excluding branch is not safe.
|
| 350 |
+
- Report when setting the relevant object to NUD_NOARP, with independent multicast and age alternatives false, cannot make the sink eligible through the state predicate.
|
| 351 |
+
- Suppress when a reachable definition governing the sink positively admits NUD_NOARP for that same object, as in the added equality disjunct.
|
| 352 |
+
|
| 353 |
+
### Implementation constraints
|
| 354 |
+
|
| 355 |
+
- Use a CSA callback that permits one enclosing-function analysis, such as `check::ASTCodeBody`, or a call callback paired with the enclosing `AnalysisDeclContext` CFG; do not rely solely on lexical ParentMap ancestry.
|
| 356 |
+
- Build explicit CFG control-dependence, dominance, statement-order, and reaching-definition checks between the eligibility definition, guard, and reclamation sink without introducing ProgramState tracking.
|
| 357 |
+
- Normalize relevant Boolean expressions through parentheses, implicit casts, logical operators, and unary negation before deciding whether NUD_NOARP is admitted or excluded.
|
| 358 |
+
- Resolve the state member, NUD_NOARP declaration/value, sink callee, flag declarations, and sink argument through AST declarations and expression identity rather than source-text matching.
|
| 359 |
+
- Emit one diagnostic at the controlling eligibility predicate or guarded reclamation operation, with a source range local to the proven relation.
|
| 360 |
+
- Keep scope project-general within neighbour reclamation semantics; do not restrict matching to `neigh_forced_gc`, a local variable name such as `remove`, a source path, a commit identifier, or a line number.
|
| 361 |
+
- Do not encode the patch as an exact token sequence or use the numeric value `0x40` as a substitute for establishing the NUD_NOARP semantic declaration.
|
| 362 |
+
|
| 363 |
+
### Validation checklist
|
| 364 |
+
|
| 365 |
+
- Compile the checker plugin and verify registration and loading with the supplied Clang Static Analyzer.
|
| 366 |
+
- Scan both supplied vulnerable inputs and confirm relevant diagnostics in `neigh_forced_gc`; scan both patched inputs and confirm zero diagnostics.
|
| 367 |
+
- Confirm diagnostics remain within the changed function and near the eligibility predicate or its guarded `neigh_remove_one` sink, with no warnings in non-patched functions.
|
| 368 |
+
- Verify that unconditional or state-independent `neigh_remove_one` calls are suppressed.
|
| 369 |
+
- Add refinements showing that positive `nud_state == NUD_NOARP` coverage suppresses while `nud_state != NUD_NOARP`, negated equality, and excluding branches do not.
|
| 370 |
+
- Add refinements with unrelated objects, assignments after the sink, unreachable assignments, and overwritten flag definitions; none may falsely establish safety.
|
| 371 |
+
- Add a refinement where NUD_NOARP coverage reaches the sink through an equivalent positively oriented guard and confirm suppression without requiring the exact patch spelling.
|
| 372 |
+
- Run code verification, differential cross-validation, hardcoding detection, and refinement evaluation, requiring G6 and an accepted or clean outcome.
|
| 373 |
+
|
| 374 |
+
### Avoid and forbidden regressions
|
| 375 |
+
|
| 376 |
+
- Do not reuse the failed lexical-parent plus unrestricted whole-function assignment scan as a substitute for CFG proof.
|
| 377 |
+
- Do not treat the mere presence of any NUD_NOARP comparison anywhere in the function as evidence that reclamation accepts that state.
|
| 378 |
+
- Do not classify inequality, polarity-reversed expressions, or arbitrary bitwise occurrence as a safe NUD_NOARP admission.
|
| 379 |
+
- Do not assume every NUD_NOARP entry is unconditionally unreclaimable; phrase the finding around missing state-based eligibility and resulting retention when other alternatives are false.
|
| 380 |
+
- Do not add path-sensitive ProgramState or interprocedural propagation when intraprocedural CFG analysis establishes the required relation.
|
| 381 |
+
- Do not embed patch prose, commit metadata, source locations, changed-function identity, or exact patched syntax in matching logic or checker-facing implementation metadata.
|
tasks/csa159/pair_164974/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_164974/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "a902f3dec70a46332a8c99604de384fbabd734e5",
|
| 4 |
+
"after_commit": "31b62908693c90d4d07db597e685d9f25a120073",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/610a9b8f49fbcf1100716370d3b5f6f884a2835a/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/610a9b8f49fbcf1100716370d3b5f6f884a2835a/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"net/sunrpc/xprtmultipath.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "SUNRPC: Fix a suspicious RCU usage warning\n\nI received the following warning while running cthon against an ontap\nserver running pNFS:\n\n[ 57.202521] =============================\n[ 57.202522] WARNING: suspicious RCU usage\n[ 57.202523] 6.7.0-rc3-g2cc14f52aeb7 #41492 Not tainted\n[ 57.202525] -----------------------------\n[ 57.202525] net/sunrpc/xprtmultipath.c:349 RCU-list traversed in non-reader section!!\n[ 57.202527]\n other info that might help us debug this:\n\n[ 57.202528]\n rcu_scheduler_active = 2, debug_locks = 1\n[ 57.202529] no locks held by test5/3567.\n[ 57.202530]\n stack backtrace:\n[ 57.202532] CPU: 0 PID: 3567 Comm: test5 Not tainted 6.7.0-rc3-g2cc14f52aeb7 #41492 5b09971b4965c0aceba19f3eea324a4a806e227e\n[ 57.202534] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS unknown 2/2/2022\n[ 57.202536] Call Trace:\n[ 57.202537] <TASK>\n[ 57.202540] dump_stack_lvl+0x77/0xb0\n[ 57.202551] lockdep_rcu_suspicious+0x154/0x1a0\n[ 57.202556] rpc_xprt_switch_has_addr+0x17c/0x190 [sunrpc ebe02571b9a8ceebf7d98e71675af20c19bdb1f6]\n[ 57.202596] rpc_clnt_setup_test_and_add_xprt+0x50/0x180 [sunrpc ebe02571b9a8ceebf7d98e71675af20c19bdb1f6]\n[ 57.202621] ? rpc_clnt_add_xprt+0x254/0x300 [sunrpc ebe02571b9a8ceebf7d98e71675af20c19bdb1f6]\n[ 57.202646] rpc_clnt_add_xprt+0x27a/0x300 [sunrpc ebe02571b9a8ceebf7d98e71675af20c19bdb1f6]\n[ 57.202671] ? __pfx_rpc_clnt_setup_test_and_add_xprt+0x10/0x10 [sunrpc ebe02571b9a8ceebf7d98e71675af20c19bdb1f6]\n[ 57.202696] nfs4_pnfs_ds_connect+0x345/0x760 [nfsv4 c716d88496ded0ea6d289bbea684fa996f9b57a9]\n[ 57.202728] ? __pfx_nfs4_test_session_trunk+0x10/0x10 [nfsv4 c716d88496ded0ea6d289bbea684fa996f9b57a9]\n[ 57.202754] nfs4_fl_prepare_ds+0x75/0xc0 [nfs_layout_nfsv41_files e3a4187f18ae8a27b630f9feae6831b584a9360a]\n[ 57.202760] filelayout_write_pagelist+0x4a/0x200 [nfs_layout_nfsv41_files e3a4187f18ae8a27b630f9feae6831b584a9360a]\n[ 57.202765] pnfs_generic_pg_writepages+0xbe/0x230 [nfsv4 c716d88496ded0ea6d289bbea684fa996f9b57a9]\n[ 57.202788] __nfs_pageio_add_request+0x3fd/0x520 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202813] nfs_pageio_add_request+0x18b/0x390 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202831] nfs_do_writepage+0x116/0x1e0 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202849] nfs_writepages_callback+0x13/0x30 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202866] write_cache_pages+0x265/0x450\n[ 57.202870] ? __pfx_nfs_writepages_callback+0x10/0x10 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202891] nfs_writepages+0x141/0x230 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202913] do_writepages+0xd2/0x230\n[ 57.202917] ? filemap_fdatawrite_wbc+0x5c/0x80\n[ 57.202921] filemap_fdatawrite_wbc+0x67/0x80\n[ 57.202924] filemap_write_and_wait_range+0xd9/0x170\n[ 57.202930] nfs_wb_all+0x49/0x180 [nfs 6c976fa593a7c2976f5a0aeb4965514a828e6902]\n[ 57.202947] nfs4_file_flush+0x72/0xb0 [nfsv4 c716d88496ded0ea6d289bbea684fa996f9b57a9]\n[ 57.202969] __se_sys_close+0x46/0xd0\n[ 57.202972] do_syscall_64+0x68/0x100\n[ 57.202975] ? do_syscall_64+0x77/0x100\n[ 57.202976] ? do_syscall_64+0x77/0x100\n[ 57.202979] entry_SYSCALL_64_after_hwframe+0x6e/0x76\n[ 57.202982] RIP: 0033:0x7fe2b12e4a94\n[ 57.202985] Code: 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 80 3d d5 18 0e 00 00 74 13 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 44 c3 0f 1f 00 48 83 ec 18 89 7c 24 0c e8 c3\n[ 57.202987] RSP: 002b:00007ffe857ddb38 EFLAGS: 00000202 ORIG_RAX: 0000000000000003\n[ 57.202989] RAX: ffffffffffffffda RBX: 00007ffe857dfd68 RCX: 00007fe2b12e4a94\n[ 57.202991] RDX: 0000000000002000 RSI: 00007ffe857ddc40 RDI: 0000000000000003\n[ 57.202992] RBP: 00007ffe857dfc50 R08: 7fffffffffffffff R09: 0000000065650f49\n[ 57.202993] R10: 00007fe2b11f8300 R11: 0000000000000202 R12: 0000000000000000\n[ 57.202994] R13: 00007ffe857dfd80 R14: 00007fe2b1445000 R15: 0000000000000000\n[ 57.202999] </TASK>\n\nThe problem seems to be that two out of three callers aren't taking the\nrcu_read_lock() before calling the list_for_each_entry_rcu() function in\nrpc_xprt_switch_has_addr(). I fix this by having\nrpc_xprt_switch_has_addr() unconditionaly take the rcu_read_lock(),\nwhich is okay to do recursively in the case that the lock has already\nbeen taken by a caller.\n\nReviewed-by: Jeff Layton <jlayton@kernel.org>\nSigned-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_164974/patch.diff
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c
|
| 2 |
+
index 701250b305db..0706575d9392 100644
|
| 3 |
+
--- a/net/sunrpc/xprtmultipath.c
|
| 4 |
+
+++ b/net/sunrpc/xprtmultipath.c
|
| 5 |
+
@@ -336,8 +336,9 @@ struct rpc_xprt *xprt_iter_current_entry_offline(struct rpc_xprt_iter *xpi)
|
| 6 |
+
xprt_switch_find_current_entry_offline);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
-bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 10 |
+
- const struct sockaddr *sap)
|
| 11 |
+
+static
|
| 12 |
+
+bool __rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 13 |
+
+ const struct sockaddr *sap)
|
| 14 |
+
{
|
| 15 |
+
struct list_head *head;
|
| 16 |
+
struct rpc_xprt *pos;
|
| 17 |
+
@@ -356,6 +357,18 @@ bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 18 |
+
return false;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
+bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 22 |
+
+ const struct sockaddr *sap)
|
| 23 |
+
+{
|
| 24 |
+
+ bool res;
|
| 25 |
+
+
|
| 26 |
+
+ rcu_read_lock();
|
| 27 |
+
+ res = __rpc_xprt_switch_has_addr(xps, sap);
|
| 28 |
+
+ rcu_read_unlock();
|
| 29 |
+
+
|
| 30 |
+
+ return res;
|
| 31 |
+
+}
|
| 32 |
+
+
|
| 33 |
+
static
|
| 34 |
+
struct rpc_xprt *xprt_switch_find_next_entry(struct list_head *head,
|
| 35 |
+
const struct rpc_xprt *cur, bool check_active)
|
tasks/csa159/pair_164974/post_functions.txt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/sunrpc/xprtmultipath.c
|
| 2 |
+
```c
|
| 3 |
+
static
|
| 4 |
+
struct rpc_xprt *xprt_iter_current_entry_offline(struct rpc_xprt_iter *xpi)
|
| 5 |
+
{
|
| 6 |
+
return _xprt_iter_current_entry(xpi,
|
| 7 |
+
xprt_switch_find_first_entry_offline,
|
| 8 |
+
xprt_switch_find_current_entry_offline);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
static
|
| 12 |
+
bool __rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 13 |
+
const struct sockaddr *sap)
|
| 14 |
+
{
|
| 15 |
+
struct list_head *head;
|
| 16 |
+
struct rpc_xprt *pos;
|
| 17 |
+
|
| 18 |
+
if (xps == NULL || sap == NULL)
|
| 19 |
+
return false;
|
| 20 |
+
|
| 21 |
+
head = &xps->xps_xprt_list;
|
| 22 |
+
list_for_each_entry_rcu(pos, head, xprt_switch) {
|
| 23 |
+
if (rpc_cmp_addr_port(sap, (struct sockaddr *)&pos->addr)) {
|
| 24 |
+
pr_info("RPC: addr %s already in xprt switch\n",
|
| 25 |
+
pos->address_strings[RPC_DISPLAY_ADDR]);
|
| 26 |
+
return true;
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
return false;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 33 |
+
const struct sockaddr *sap)
|
| 34 |
+
{
|
| 35 |
+
bool res;
|
| 36 |
+
|
| 37 |
+
rcu_read_lock();
|
| 38 |
+
res = __rpc_xprt_switch_has_addr(xps, sap);
|
| 39 |
+
rcu_read_unlock();
|
| 40 |
+
|
| 41 |
+
return res;
|
| 42 |
+
}
|
| 43 |
+
```
|
tasks/csa159/pair_164974/pre_functions.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: net/sunrpc/xprtmultipath.c
|
| 2 |
+
```c
|
| 3 |
+
static
|
| 4 |
+
struct rpc_xprt *xprt_iter_current_entry_offline(struct rpc_xprt_iter *xpi)
|
| 5 |
+
{
|
| 6 |
+
return _xprt_iter_current_entry(xpi,
|
| 7 |
+
xprt_switch_find_first_entry_offline,
|
| 8 |
+
xprt_switch_find_current_entry_offline);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
|
| 12 |
+
const struct sockaddr *sap)
|
| 13 |
+
{
|
| 14 |
+
struct list_head *head;
|
| 15 |
+
struct rpc_xprt *pos;
|
| 16 |
+
|
| 17 |
+
if (xps == NULL || sap == NULL)
|
| 18 |
+
return false;
|
| 19 |
+
|
| 20 |
+
head = &xps->xps_xprt_list;
|
| 21 |
+
list_for_each_entry_rcu(pos, head, xprt_switch) {
|
| 22 |
+
if (rpc_cmp_addr_port(sap, (struct sockaddr *)&pos->addr)) {
|
| 23 |
+
pr_info("RPC: addr %s already in xprt switch\n",
|
| 24 |
+
pos->address_strings[RPC_DISPLAY_ADDR]);
|
| 25 |
+
return true;
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
return false;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
static
|
| 32 |
+
struct rpc_xprt *xprt_switch_find_next_entry(struct list_head *head,
|
| 33 |
+
const struct rpc_xprt *cur, bool check_active)
|
| 34 |
+
{
|
| 35 |
+
struct rpc_xprt *pos, *prev = NULL;
|
| 36 |
+
bool found = false;
|
| 37 |
+
|
| 38 |
+
list_for_each_entry_rcu(pos, head, xprt_switch) {
|
| 39 |
+
if (cur == prev)
|
| 40 |
+
found = true;
|
| 41 |
+
/* for request to return active transports return only
|
| 42 |
+
* active, for request to return offline transports
|
| 43 |
+
* return only offline
|
| 44 |
+
*/
|
| 45 |
+
if (found && ((check_active && xprt_is_active(pos)) ||
|
| 46 |
+
(!check_active && !xprt_is_active(pos))))
|
| 47 |
+
return pos;
|
| 48 |
+
prev = pos;
|
| 49 |
+
}
|
| 50 |
+
return NULL;
|
| 51 |
+
}
|
| 52 |
+
```
|
tasks/csa159/pair_164974/task_prompt.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `syntax_only`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- semantic_mechanism failed because path-sensitive RCULockDepth ProgramState tracking plus a static-versus-exported entry heuristic were judged overkill; the required relation is a same-function AST fact.
|
| 330 |
+
- refinement_accepted failed with outcome feedback_required after one round; the rollout never converged on an accepted mechanism.
|
| 331 |
+
- The prior design proved exploded-graph lock-state reachability even though absence of rcu_read_lock in the same non-static function as list_for_each_entry_rcu is visible from an AST walk.
|
| 332 |
+
|
| 333 |
+
### Preserve from prior rollouts
|
| 334 |
+
|
| 335 |
+
- Preserve successful compile, before/after validation, and code verification.
|
| 336 |
+
- Preserve objective eligibility gate G6.
|
| 337 |
+
- Preserve semantic score at or above the configured threshold.
|
| 338 |
+
- Preserve process quality at or above the configured threshold.
|
| 339 |
+
- Do not introduce patch-anchor dependence.
|
| 340 |
+
- Do not introduce patch-local hardcoding.
|
| 341 |
+
|
| 342 |
+
### Required semantic proof
|
| 343 |
+
|
| 344 |
+
- Report when a non-static function body expands an RCU list-traversal macro (list_for_each_entry_rcu and documented friends) and does not itself contain an rcu_read_lock family call; that is the pre-patch rpc_xprt_switch_has_addr defect.
|
| 345 |
+
- Treat as safe when the traversal lives only in a static helper, or when the same function contains rcu_read_lock/rcu_read_lock_bh/rcu_read_lock_sched/rcu_read_lock_nested (post-patch: lock in the public wrapper, walk in static __rpc_xprt_switch_has_addr).
|
| 346 |
+
- Exported functions may be invoked without a held RCU read-side critical section; file-local helpers may rely on their callers and must not be treated as standalone defects.
|
| 347 |
+
|
| 348 |
+
### Implementation constraints
|
| 349 |
+
|
| 350 |
+
- Use an AST-body or AST-declaration callback over function definitions; do not register ProgramState traits or update lock nesting on exploded-graph paths.
|
| 351 |
+
- Detect RCU traversals by macro-expansion names (list_for_each_entry_rcu, list_for_each_entry_continue_rcu, list_for_each_entry_from_rcu, list_for_each_rcu, hlist_for_each_entry_rcu and documented friends) and lock acquisition by callee identifiers in the rcu_read_lock family.
|
| 352 |
+
- Emit the diagnostic at the traversal site inside non-static FunctionDecls only; suppress SC_Static helpers.
|
| 353 |
+
- Remain project_general for the Linux RCU list protocol; do not key checks off net/sunrpc/xprtmultipath.c, rpc_xprt_switch_has_addr, __rpc_xprt_switch_has_addr, or patch line numbers.
|
| 354 |
+
- If walking statements, use the loop-condition or macro-expansion location; these RCU macros need not appear as a ForStmt CFG node.
|
| 355 |
+
|
| 356 |
+
### Validation checklist
|
| 357 |
+
|
| 358 |
+
- Plugin compiles, registers, and keeps hard_validation passing.
|
| 359 |
+
- before_commit scan of net/sunrpc/xprtmultipath.c reports on non-static rpc_xprt_switch_has_addr at list_for_each_entry_rcu with N_buggy > 0.
|
| 360 |
+
- after_commit scan yields N_patched = 0 because the public wrapper contains rcu_read_lock without a traversal and the static helper is suppressed.
|
| 361 |
+
- No warning on pre-existing static helpers such as xprt_switch_find_next_entry that also expand list_for_each_entry_rcu.
|
| 362 |
+
- Reports stay in the patched function near the traversal; no unrelated disappeared diagnostics.
|
| 363 |
+
- Refinement must be accepted; semantic_mechanism must classify the checker as syntax_only rather than path-sensitive overkill.
|
| 364 |
+
|
| 365 |
+
### Avoid and forbidden regressions
|
| 366 |
+
|
| 367 |
+
- Do not reintroduce RCULockDepth, checkBeginFunction entry-depth seeding, checkPreCall lock/unlock counting, or checkBranchCondition sink reporting.
|
| 368 |
+
- Do not treat inlining or exploded-graph lock reachability as required for this instance.
|
| 369 |
+
- Do not emit reports on static RCU helpers whose callers are expected to hold rcu_read_lock.
|
| 370 |
+
- Do not drop compile, before/after, G6, anchor_free, or hardcoding_free invariants to chase mechanism score.
|
tasks/csa159/pair_165542/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|
tasks/csa159/pair_165542/config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"project_id": "torvalds_linux",
|
| 3 |
+
"before_commit": "e3952fcce1aad934f1322843b564ff86256444b2",
|
| 4 |
+
"after_commit": "cc16eecae687912238ee6efbff71ad31e2bc414e",
|
| 5 |
+
"repo_path": "/workspace/repo/torvalds/linux",
|
| 6 |
+
"llvm_build_dir": "/opt/llvm",
|
| 7 |
+
"before_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/cfb92440ee71adcc2105b0890bb01ac3cddb8507/compile_commands.json",
|
| 8 |
+
"after_compile_commands": "/workspace/benchmark/data-pipeline/snapshots/torvalds_linux/cfb92440ee71adcc2105b0890bb01ac3cddb8507/compile_commands.json",
|
| 9 |
+
"changed_files": [
|
| 10 |
+
"fs/jbd2/transaction.c"
|
| 11 |
+
],
|
| 12 |
+
"commit_message": "jbd2: fix use-after-free of transaction_t race\n\njbd2_journal_wait_updates() is called with j_state_lock held. But if\nthere is a commit in progress, then this transaction might get committed\nand freed via jbd2_journal_commit_transaction() ->\njbd2_journal_free_transaction(), when we release j_state_lock.\nSo check for journal->j_running_transaction everytime we release and\nacquire j_state_lock to avoid use-after-free issue.\n\nLink: https://lore.kernel.org/r/948c2fed518ae739db6a8f7f83f1d58b504f87d0.1644497105.git.ritesh.list@gmail.com\nFixes: 4f98186848707f53 (\"jbd2: refactor wait logic for transaction updates into a common function\")\nCc: stable@kernel.org\nReported-and-tested-by: syzbot+afa2ca5171d93e44b348@syzkaller.appspotmail.com\nReviewed-by: Jan Kara <jack@suse.cz>\nSigned-off-by: Ritesh Harjani <riteshh@linux.ibm.com>\nSigned-off-by: Theodore Ts'o <tytso@mit.edu>",
|
| 13 |
+
"t_valid": 50,
|
| 14 |
+
"t_plausible": 20,
|
| 15 |
+
"triage_sample_size": 10,
|
| 16 |
+
"max_synthesis_retry": 0,
|
| 17 |
+
"max_in_session_redesigns": 1,
|
| 18 |
+
"max_refinement_iter": 3
|
| 19 |
+
}
|
tasks/csa159/pair_165542/patch.diff
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
|
| 2 |
+
index 8e2f8275a253..259e00046a8b 100644
|
| 3 |
+
--- a/fs/jbd2/transaction.c
|
| 4 |
+
+++ b/fs/jbd2/transaction.c
|
| 5 |
+
@@ -842,27 +842,38 @@ EXPORT_SYMBOL(jbd2_journal_restart);
|
| 6 |
+
*/
|
| 7 |
+
void jbd2_journal_wait_updates(journal_t *journal)
|
| 8 |
+
{
|
| 9 |
+
- transaction_t *commit_transaction = journal->j_running_transaction;
|
| 10 |
+
+ DEFINE_WAIT(wait);
|
| 11 |
+
|
| 12 |
+
- if (!commit_transaction)
|
| 13 |
+
- return;
|
| 14 |
+
+ while (1) {
|
| 15 |
+
+ /*
|
| 16 |
+
+ * Note that the running transaction can get freed under us if
|
| 17 |
+
+ * this transaction is getting committed in
|
| 18 |
+
+ * jbd2_journal_commit_transaction() ->
|
| 19 |
+
+ * jbd2_journal_free_transaction(). This can only happen when we
|
| 20 |
+
+ * release j_state_lock -> schedule() -> acquire j_state_lock.
|
| 21 |
+
+ * Hence we should everytime retrieve new j_running_transaction
|
| 22 |
+
+ * value (after j_state_lock release acquire cycle), else it may
|
| 23 |
+
+ * lead to use-after-free of old freed transaction.
|
| 24 |
+
+ */
|
| 25 |
+
+ transaction_t *transaction = journal->j_running_transaction;
|
| 26 |
+
|
| 27 |
+
- spin_lock(&commit_transaction->t_handle_lock);
|
| 28 |
+
- while (atomic_read(&commit_transaction->t_updates)) {
|
| 29 |
+
- DEFINE_WAIT(wait);
|
| 30 |
+
+ if (!transaction)
|
| 31 |
+
+ break;
|
| 32 |
+
|
| 33 |
+
+ spin_lock(&transaction->t_handle_lock);
|
| 34 |
+
prepare_to_wait(&journal->j_wait_updates, &wait,
|
| 35 |
+
- TASK_UNINTERRUPTIBLE);
|
| 36 |
+
- if (atomic_read(&commit_transaction->t_updates)) {
|
| 37 |
+
- spin_unlock(&commit_transaction->t_handle_lock);
|
| 38 |
+
- write_unlock(&journal->j_state_lock);
|
| 39 |
+
- schedule();
|
| 40 |
+
- write_lock(&journal->j_state_lock);
|
| 41 |
+
- spin_lock(&commit_transaction->t_handle_lock);
|
| 42 |
+
+ TASK_UNINTERRUPTIBLE);
|
| 43 |
+
+ if (!atomic_read(&transaction->t_updates)) {
|
| 44 |
+
+ spin_unlock(&transaction->t_handle_lock);
|
| 45 |
+
+ finish_wait(&journal->j_wait_updates, &wait);
|
| 46 |
+
+ break;
|
| 47 |
+
}
|
| 48 |
+
+ spin_unlock(&transaction->t_handle_lock);
|
| 49 |
+
+ write_unlock(&journal->j_state_lock);
|
| 50 |
+
+ schedule();
|
| 51 |
+
finish_wait(&journal->j_wait_updates, &wait);
|
| 52 |
+
+ write_lock(&journal->j_state_lock);
|
| 53 |
+
}
|
| 54 |
+
- spin_unlock(&commit_transaction->t_handle_lock);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
@@ -877,8 +888,6 @@ void jbd2_journal_wait_updates(journal_t *journal)
|
| 59 |
+
*/
|
| 60 |
+
void jbd2_journal_lock_updates(journal_t *journal)
|
| 61 |
+
{
|
| 62 |
+
- DEFINE_WAIT(wait);
|
| 63 |
+
-
|
| 64 |
+
jbd2_might_wait_for_commit(journal);
|
| 65 |
+
|
| 66 |
+
write_lock(&journal->j_state_lock);
|
tasks/csa159/pair_165542/post_functions.txt
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: fs/jbd2/transaction.c
|
| 2 |
+
```c
|
| 3 |
+
void jbd2_journal_wait_updates(journal_t *journal)
|
| 4 |
+
{
|
| 5 |
+
DEFINE_WAIT(wait);
|
| 6 |
+
|
| 7 |
+
while (1) {
|
| 8 |
+
/*
|
| 9 |
+
* Note that the running transaction can get freed under us if
|
| 10 |
+
* this transaction is getting committed in
|
| 11 |
+
* jbd2_journal_commit_transaction() ->
|
| 12 |
+
* jbd2_journal_free_transaction(). This can only happen when we
|
| 13 |
+
* release j_state_lock -> schedule() -> acquire j_state_lock.
|
| 14 |
+
* Hence we should everytime retrieve new j_running_transaction
|
| 15 |
+
* value (after j_state_lock release acquire cycle), else it may
|
| 16 |
+
* lead to use-after-free of old freed transaction.
|
| 17 |
+
*/
|
| 18 |
+
transaction_t *transaction = journal->j_running_transaction;
|
| 19 |
+
|
| 20 |
+
if (!transaction)
|
| 21 |
+
break;
|
| 22 |
+
|
| 23 |
+
spin_lock(&transaction->t_handle_lock);
|
| 24 |
+
prepare_to_wait(&journal->j_wait_updates, &wait,
|
| 25 |
+
TASK_UNINTERRUPTIBLE);
|
| 26 |
+
if (!atomic_read(&transaction->t_updates)) {
|
| 27 |
+
spin_unlock(&transaction->t_handle_lock);
|
| 28 |
+
finish_wait(&journal->j_wait_updates, &wait);
|
| 29 |
+
break;
|
| 30 |
+
}
|
| 31 |
+
spin_unlock(&transaction->t_handle_lock);
|
| 32 |
+
write_unlock(&journal->j_state_lock);
|
| 33 |
+
schedule();
|
| 34 |
+
finish_wait(&journal->j_wait_updates, &wait);
|
| 35 |
+
write_lock(&journal->j_state_lock);
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
```
|
tasks/csa159/pair_165542/pre_functions.txt
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### File: fs/jbd2/transaction.c
|
| 2 |
+
```c
|
| 3 |
+
void jbd2_journal_wait_updates(journal_t *journal)
|
| 4 |
+
{
|
| 5 |
+
transaction_t *commit_transaction = journal->j_running_transaction;
|
| 6 |
+
|
| 7 |
+
if (!commit_transaction)
|
| 8 |
+
return;
|
| 9 |
+
|
| 10 |
+
spin_lock(&commit_transaction->t_handle_lock);
|
| 11 |
+
while (atomic_read(&commit_transaction->t_updates)) {
|
| 12 |
+
DEFINE_WAIT(wait);
|
| 13 |
+
|
| 14 |
+
prepare_to_wait(&journal->j_wait_updates, &wait,
|
| 15 |
+
TASK_UNINTERRUPTIBLE);
|
| 16 |
+
if (atomic_read(&commit_transaction->t_updates)) {
|
| 17 |
+
spin_unlock(&commit_transaction->t_handle_lock);
|
| 18 |
+
write_unlock(&journal->j_state_lock);
|
| 19 |
+
schedule();
|
| 20 |
+
write_lock(&journal->j_state_lock);
|
| 21 |
+
spin_lock(&commit_transaction->t_handle_lock);
|
| 22 |
+
}
|
| 23 |
+
finish_wait(&journal->j_wait_updates, &wait);
|
| 24 |
+
}
|
| 25 |
+
spin_unlock(&commit_transaction->t_handle_lock);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
void jbd2_journal_lock_updates(journal_t *journal)
|
| 29 |
+
{
|
| 30 |
+
DEFINE_WAIT(wait);
|
| 31 |
+
|
| 32 |
+
jbd2_might_wait_for_commit(journal);
|
| 33 |
+
|
| 34 |
+
write_lock(&journal->j_state_lock);
|
| 35 |
+
++journal->j_barrier_count;
|
| 36 |
+
|
| 37 |
+
/* Wait until there are no reserved handles */
|
| 38 |
+
if (atomic_read(&journal->j_reserved_credits)) {
|
| 39 |
+
write_unlock(&journal->j_state_lock);
|
| 40 |
+
wait_event(journal->j_wait_reserved,
|
| 41 |
+
atomic_read(&journal->j_reserved_credits) == 0);
|
| 42 |
+
write_lock(&journal->j_state_lock);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/* Wait until there are no running t_updates */
|
| 46 |
+
jbd2_journal_wait_updates(journal);
|
| 47 |
+
|
| 48 |
+
write_unlock(&journal->j_state_lock);
|
| 49 |
+
|
| 50 |
+
/*
|
| 51 |
+
* We have now established a barrier against other normal updates, but
|
| 52 |
+
* we also need to barrier against other jbd2_journal_lock_updates() calls
|
| 53 |
+
* to make sure that we serialise special journal-locked operations
|
| 54 |
+
* too.
|
| 55 |
+
*/
|
| 56 |
+
mutex_lock(&journal->j_barrier);
|
| 57 |
+
}
|
| 58 |
+
```
|
tasks/csa159/pair_165542/task_prompt.md
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task: Synthesize a CSA Checker from a CVE Patch
|
| 2 |
+
|
| 3 |
+
## Your Role
|
| 4 |
+
|
| 5 |
+
You are a static analysis expert. Synthesize a Clang Static Analyzer (CSA) checker
|
| 6 |
+
that detects the bug pattern fixed by the CVE patch in this working directory.
|
| 7 |
+
|
| 8 |
+
You have full filesystem and bash access — use them.
|
| 9 |
+
|
| 10 |
+
### Skills
|
| 11 |
+
|
| 12 |
+
Many skills are available under `.claude/skills/` — covering vulnerability analysis,
|
| 13 |
+
checker design, debugging, code audit, security patterns, and more. Each skill
|
| 14 |
+
encodes reusable expertise: take time to explore them, read their SKILL.md files,
|
| 15 |
+
and invoke those that look useful via the Skill tool. Let the task guide which
|
| 16 |
+
ones you reach for.
|
| 17 |
+
|
| 18 |
+
## File Layout
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
/work/
|
| 22 |
+
├── compile.sh ← RUN ME: compile checker.cpp → checker.so
|
| 23 |
+
├── checker_template.cpp ← skeleton, start here
|
| 24 |
+
├── patch.diff ← the CVE fix
|
| 25 |
+
├── pre_functions.txt ← buggy source (before_commit)
|
| 26 |
+
├── post_functions.txt ← patched source (after_commit)
|
| 27 |
+
├── config.json ← paths, commit_message, commit hashes, flags
|
| 28 |
+
├── scan/
|
| 29 |
+
│ ├── scan_before.sh ← RUN ME: scan before_commit → N_buggy
|
| 30 |
+
│ ├── scan_after.sh ← RUN ME: scan after_commit → N_patched
|
| 31 |
+
│ └── flags_*.txt ← pre-extracted compile flags (-I, -D)
|
| 32 |
+
├── references/
|
| 33 |
+
│ ├── repo_knowledge.md ← project-specific API/convention reference
|
| 34 |
+
│ ├── patterns_summary.md ← (optional) historical bug pattern summary
|
| 35 |
+
│ ├── cwe_cards/ ← CWE knowledge library (all categories)
|
| 36 |
+
│ │ ├── index.json ← lookup index — use to find relevant cards
|
| 37 |
+
│ │ ├── CWE-{id}(-variant).md ← Tier 1/2 per-CWE detection patterns
|
| 38 |
+
│ │ ├── Category-{name}.md ← Tier 3 umbrella cards (rare CWEs grouped)
|
| 39 |
+
│ ├── csa_headers_api.md ← API quick reference (extracted from LLVM 18 headers)
|
| 40 |
+
│ ├── csa_checker_patterns.md ← pattern catalog (resource tracking, null check, etc.)
|
| 41 |
+
│ ├── csa_utility_functions.h ← copy-paste C++ helpers for checker.cpp (AST traversal, expression eval, etc.)
|
| 42 |
+
│ └── examples/
|
| 43 |
+
│ └── llvm-official/ ← 5 official checker sources (with comments)
|
| 44 |
+
│ ├── 01_div_zero.cpp
|
| 45 |
+
│ ├── 02_simple_stream.cpp
|
| 46 |
+
│ ├── 03_undef_result.cpp
|
| 47 |
+
│ ├── 04_nullability.cpp
|
| 48 |
+
│ └── 05_malloc.cpp
|
| 49 |
+
│
|
| 50 |
+
├── checker.cpp ← YOUR OUTPUT: synthesized checker
|
| 51 |
+
├── checker.so ← YOUR OUTPUT: compiled checker
|
| 52 |
+
├── state.json ← YOUR OUTPUT: structured task state
|
| 53 |
+
├── scope_statement.md ← YOUR OUTPUT: checker scope analysis (Level 1/2/3)
|
| 54 |
+
└── summary.json ← YOUR OUTPUT: final report
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
**Read these before writing any code:**
|
| 60 |
+
|
| 61 |
+
1. **`references/csa_headers_api.md`** — CSA API quick reference. Extracted directly from
|
| 62 |
+
LLVM 18 headers. Covers all checker callbacks, ProgramState operations, SVal types,
|
| 63 |
+
MemRegion hierarchy, and bug reporting. **Read this first whenever you need API info.**
|
| 64 |
+
|
| 65 |
+
2. **`references/csa_checker_patterns.md`** — Pattern catalog. Documents 5 battle-tested
|
| 66 |
+
patterns from official LLVM checkers: resource tracking, null checking, undefined
|
| 67 |
+
value detection, division-by-zero, and malloc/free. Each pattern includes skeleton
|
| 68 |
+
code, state traits, and key API usage.
|
| 69 |
+
|
| 70 |
+
3. **`references/examples/llvm-official/`** — 5 official LLVM 18 checker implementations
|
| 71 |
+
with explanatory comments:
|
| 72 |
+
- `01_div_zero.cpp` — simplest checker (169 lines, 1 callback)
|
| 73 |
+
- `02_simple_stream.cpp` — resource tracking (292 lines, fopen/fclose)
|
| 74 |
+
- `03_undef_result.cpp` — PostStmt pattern (160 lines)
|
| 75 |
+
- `04_nullability.cpp` — multi-callback checker (1247 lines)
|
| 76 |
+
- `05_malloc.cpp` — comprehensive malloc/free (1511 lines)
|
| 77 |
+
|
| 78 |
+
4. **`checker_template.cpp`** — Skeleton with placeholders. Start here.
|
| 79 |
+
|
| 80 |
+
5. **`references/repo_knowledge.md`** — Project-specific reference. Contains this
|
| 81 |
+
repository's memory allocation API, key data types, source layout, and typical
|
| 82 |
+
CVE patterns. **Read this before writing the checker** — knowing the project's
|
| 83 |
+
alloc/free conventions and common bug patterns saves many grep rounds.
|
| 84 |
+
|
| 85 |
+
5b. **`references/patterns_summary.md`** — (may not exist) Historical synthesis
|
| 86 |
+
patterns for this project. If present, it contains a concise summary of the
|
| 87 |
+
most common bug patterns, frequent CWE categories, and reusable checker
|
| 88 |
+
architectures observed in previous synthesis runs. Read after repo_knowledge.md.
|
| 89 |
+
|
| 90 |
+
6. **`references/cwe_cards/`** — Complete CWE knowledge base covering all
|
| 91 |
+
vulnerability categories. **The framework provides the full library —
|
| 92 |
+
you must identify the vulnerability type yourself.** Workflow:
|
| 93 |
+
|
| 94 |
+
1. Analyse the patch diff and commit message to determine the vulnerability
|
| 95 |
+
type (buffer overflow, UAF, null deref, integer overflow, race condition,
|
| 96 |
+
etc.). Do NOT rely on the CWE label — treat it as a hint at most.
|
| 97 |
+
2. Open ``index.json`` to discover available cards and their tiers.
|
| 98 |
+
3. Read the relevant card(s) for **detection strategies**, **checker
|
| 99 |
+
architecture suggestions**, and **known false-positive patterns**.
|
| 100 |
+
|
| 101 |
+
Card tiers:
|
| 102 |
+
- ``CWE-{id}(-{variant}).md`` — Tier 1/2 cards for common CWEs; kernel /
|
| 103 |
+
userspace variants when the detection strategy differs substantially.
|
| 104 |
+
- ``Category-{name}.md`` — Tier 3 umbrella cards grouping rarer CWEs by
|
| 105 |
+
category (input validation, resource management, etc.).
|
| 106 |
+
|
| 107 |
+
7. **`references/csa_utility_functions.h`** — Copy-paste C++ helper functions for
|
| 108 |
+
checker.cpp. Includes AST traversal (`findSpecificTypeInParents/Children`),
|
| 109 |
+
expression evaluation (`EvaluateExprToInt`, `inferSymbolMaxVal`), array/string
|
| 110 |
+
size extraction, MemRegion helpers, and `ExprHasName()` for robust function
|
| 111 |
+
matching. All verified against LLVM 18. **Read before implementing detection
|
| 112 |
+
logic** — these save writing boilerplate that's easy to get wrong.
|
| 113 |
+
|
| 114 |
+
## Environment
|
| 115 |
+
|
| 116 |
+
Key paths are in ``config.json``.
|
| 117 |
+
|
| 118 |
+
### Pre-built scripts
|
| 119 |
+
|
| 120 |
+
| Script | What it does |
|
| 121 |
+
|--------|-------------|
|
| 122 |
+
| `bash compile.sh` | Compile checker.cpp → checker.so (with correct flags) |
|
| 123 |
+
| `CHECKER_NAME=<name> bash scan/scan_before.sh` | Scan before_commit, count warnings → N_buggy |
|
| 124 |
+
| `CHECKER_NAME=<name> bash scan/scan_after.sh` | Scan after_commit, count warnings → N_patched |
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Compile (run from workdir root)
|
| 128 |
+
bash compile.sh
|
| 129 |
+
|
| 130 |
+
# Scan — set CHECKER_NAME to the string passed to addChecker<>()
|
| 131 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_before.sh # → N_buggy
|
| 132 |
+
CHECKER_NAME=your.CheckerName bash scan/scan_after.sh # → N_patched
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
- ``compile.sh`` already has the correct ``-I`` / ``-fno-rtti`` flags.
|
| 136 |
+
- ``scan/scan_*.sh`` count only warnings tagged with your checker name.
|
| 137 |
+
- Scan environments (source files + compile flags) are pre-built in ``scan/``.
|
| 138 |
+
|
| 139 |
+
### Scan Script Integrity (CRITICAL)
|
| 140 |
+
|
| 141 |
+
The scan scripts (``scan/scan_before.sh``, ``scan/scan_after.sh``) are the **only
|
| 142 |
+
valid measurement** of N_buggy and N_patched. They are the ground truth that the
|
| 143 |
+
Python-side validator will also use. You MUST obey these rules:
|
| 144 |
+
|
| 145 |
+
**1. Never bypass the scan scripts.** Do NOT run ``clang --analyze`` directly
|
| 146 |
+
to measure warning counts. The Python validator runs the same scan scripts
|
| 147 |
+
— if you measured with a different command, your numbers will not reproduce
|
| 148 |
+
and the synthesis will be rejected.
|
| 149 |
+
|
| 150 |
+
**2. If the scan script prints COMPILE_ERROR** (missing headers, undeclared
|
| 151 |
+
identifiers, etc.), the scan environment needs repair. You MUST fix it:
|
| 152 |
+
- Add missing ``-I`` include paths to the flags files in ``scan/``
|
| 153 |
+
- Copy needed generated headers (e.g. ``autoconf.h``) from the snapshot
|
| 154 |
+
- If the file fundamentally cannot be compiled by clang, stop and write
|
| 155 |
+
``summary.json`` with ``status: "failed"`` and an honest ``failure_reason``
|
| 156 |
+
|
| 157 |
+
**3. Only trust scan script output.** The ``Total <name> warnings: N`` line
|
| 158 |
+
printed by the scan script is the number that goes into ``summary.json``.
|
| 159 |
+
If the scan script says 0, write 0. Fabricating numbers that the scan
|
| 160 |
+
script did not produce will cause the Python validator to reject the
|
| 161 |
+
synthesis.
|
| 162 |
+
|
| 163 |
+
- If compile fails: read the error, fix ``checker.cpp``, retry (max 3 cycles).
|
| 164 |
+
- If validation fails: revise checker logic, re-compile, re-scan.
|
| 165 |
+
|
| 166 |
+
## MCP Tools
|
| 167 |
+
|
| 168 |
+
You have access to 3 MCP tools under the `csa-tools` server (prefixed `mcp__csa-tools__`).
|
| 169 |
+
Each returns **source context embedded in the result** — no need to follow up with Read.
|
| 170 |
+
|
| 171 |
+
| Tool | What it does | Key advantage |
|
| 172 |
+
|------|-------------|---------------|
|
| 173 |
+
| `search(pattern, scope)` | Search for a pattern in source / LLVM headers / workdir | Returns file:line + 3 lines context — grep + Read in one call |
|
| 174 |
+
| `compile()` | Run compile.sh, return parsed diagnostics | Errors include checker.cpp context — fix without reading the file |
|
| 175 |
+
| `scan(checker_name)` | Run before/after scan, return N_buggy + N_patched + warning locations | Each warning includes source context — no manual clang --analyze needed |
|
| 176 |
+
|
| 177 |
+
### When to use each
|
| 178 |
+
|
| 179 |
+
- **`search`**: Whenever you would type `grep -rn "X"` or `find ... -name`. Use `scope="source"` for CVE code, `scope="llvm"` for CSA API headers, `scope="all"` when unsure.
|
| 180 |
+
- **`compile`**: Instead of `bash compile.sh` followed by reading checker.cpp at error lines.
|
| 181 |
+
- **`scan`**: Instead of running scan_before.sh + scan_after.sh + manual clang inspection. Returns everything you need to decide next action.
|
| 182 |
+
|
| 183 |
+
## Semantic Design Contract — before writing checker.cpp
|
| 184 |
+
|
| 185 |
+
Create the analysis portions of `state.json` and `scope_statement.md` **before**
|
| 186 |
+
writing checker.cpp. They are a design contract, not a retrospective summary.
|
| 187 |
+
After compilation, update only implementation facts such as `build_attempts`.
|
| 188 |
+
|
| 189 |
+
In `patch_analysis`, distinguish the vulnerable operation, its trigger, and the
|
| 190 |
+
semantic fact introduced by the patch that makes it safe. In `detection_plan`,
|
| 191 |
+
make `report_condition`, `safe_condition`, and `source_level_signal` concrete
|
| 192 |
+
CSA-observable facts. In `api_choice`, record the mechanism level and explain
|
| 193 |
+
why the selected callback can observe and prove those facts.
|
| 194 |
+
|
| 195 |
+
In `scope_statement.md`, include this mapping table and check it again after
|
| 196 |
+
implementation:
|
| 197 |
+
|
| 198 |
+
| Semantic condition | CSA evidence | checker.cpp implementation |
|
| 199 |
+
| --- | --- | --- |
|
| 200 |
+
| report condition | AST / SVal / MemRegion / CFG evidence | callback, helper, and branch that reports |
|
| 201 |
+
| safe condition | path constraint, guard, state discharge, or structural fact | branch that suppresses the report |
|
| 202 |
+
|
| 203 |
+
Every condition in the plan must have an implementation entry. Do not claim a
|
| 204 |
+
condition that checker.cpp does not implement, and do not silently add a code
|
| 205 |
+
condition absent from the plan.
|
| 206 |
+
|
| 207 |
+
## Mechanism Selection — diagnose before coding
|
| 208 |
+
|
| 209 |
+
Choose the weakest CSA mechanism that can prove the vulnerability property:
|
| 210 |
+
|
| 211 |
+
1. **syntax-only AST**: only when local AST shape itself is the defect;
|
| 212 |
+
2. **control flow / dominance**: when guard placement relative to a sink matters;
|
| 213 |
+
3. **path-sensitive ProgramState/SVal**: when an unsafe state must reach a use;
|
| 214 |
+
4. **cross-procedure/dataflow**: when the required fact crosses function boundaries.
|
| 215 |
+
|
| 216 |
+
For a guard-based patch, prove both that the guard rejects the unsafe value and
|
| 217 |
+
that it dominates the vulnerable use. For path-sensitive or cross-procedure
|
| 218 |
+
defects, do not replace the required state or flow proof with local AST matching
|
| 219 |
+
or source-text substring matching merely because it passes the differential scan.
|
| 220 |
+
Record the selected level as `api_choice.mechanism_level`.
|
| 221 |
+
|
| 222 |
+
## Semantic identity, locality, and final validation
|
| 223 |
+
|
| 224 |
+
Before accepting the checker, verify that its primary matching logic does not
|
| 225 |
+
depend on patch-local variable names, labels, line numbers, commit IDs, or unique
|
| 226 |
+
literals. Project APIs, types, and stable semantic call relationships are valid
|
| 227 |
+
scope anchors when they define the vulnerability class. Attach the report to the
|
| 228 |
+
actual vulnerable operation, and implement every suppression as a real safe
|
| 229 |
+
condition rather than the mere presence of a nearby guard-shaped statement.
|
| 230 |
+
|
| 231 |
+
The required final sequence is: **compile → before scan → after scan → inspect
|
| 232 |
+
the final checker name, artifacts, and report locations → write summary.json**.
|
| 233 |
+
Always run the final compile and both scans. `MAX_IN_SESSION_REDESIGNS` limits only
|
| 234 |
+
additional redesign cycles after a failed validation; if it is zero, preserve the
|
| 235 |
+
real validation evidence and report failure honestly rather than fabricating counts.
|
| 236 |
+
|
| 237 |
+
## Validation Criteria
|
| 238 |
+
|
| 239 |
+
```
|
| 240 |
+
VALID : N_buggy > N_patched AND N_patched < 50
|
| 241 |
+
INVALID : otherwise → revise and re-validate (max 1 attempts)
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
## Refinement
|
| 245 |
+
|
| 246 |
+
Do NOT self-refine the checker repeatedly. Your goal is to produce the first
|
| 247 |
+
checker that passes the Validation Criteria above — fix compile errors and
|
| 248 |
+
validation failures only. False positives are triaged and repaired by the
|
| 249 |
+
framework's refinement stage: you will receive a concrete FP list via
|
| 250 |
+
session resume (if needed) and fix only those. Reserve budget for that stage.
|
| 251 |
+
|
| 252 |
+
## Output
|
| 253 |
+
|
| 254 |
+
Produce all of the following **only when completely done**:
|
| 255 |
+
|
| 256 |
+
| File | Content |
|
| 257 |
+
|------|---------|
|
| 258 |
+
| ``checker.cpp`` | Synthesized checker source code |
|
| 259 |
+
| ``checker.so`` | Compiled checker plugin |
|
| 260 |
+
| ``state.json`` | Structured task state (see schema below) |
|
| 261 |
+
| ``scope_statement.md`` | Checker scope analysis in prose (Level 1/2/3) |
|
| 262 |
+
| ``summary.json`` | Final report (see schema below) |
|
| 263 |
+
|
| 264 |
+
Writing ``summary.json`` signals completion. Do NOT write it early.
|
| 265 |
+
|
| 266 |
+
### ``state.json``
|
| 267 |
+
|
| 268 |
+
Create this before writing checker.cpp to capture the design contract. After the
|
| 269 |
+
checker compiles, update only implementation facts and retain the original
|
| 270 |
+
semantic plan.
|
| 271 |
+
|
| 272 |
+
```json
|
| 273 |
+
{
|
| 274 |
+
"patch_analysis": {
|
| 275 |
+
"summary": "One sentence describing the vulnerability this patch fixes",
|
| 276 |
+
"changed_files": ["file1.c", "file2.h"],
|
| 277 |
+
"changed_functions": ["func_a", "func_b"],
|
| 278 |
+
"bug_type": "buffer_overflow | use_after_free | null_deref | integer_overflow | race_condition | resource_leak | double_free | input_validation | other",
|
| 279 |
+
"fix_strategy": "add_bounds_check | add_null_check | add_size_check | add_early_return | reorder_operations | change_api_signature | other",
|
| 280 |
+
"affected_types": ["GF_BitStream", "custom_struct_t"],
|
| 281 |
+
"critical_calls": ["gf_strdup", "memcpy"]
|
| 282 |
+
},
|
| 283 |
+
"detection_plan": {
|
| 284 |
+
"bug_pattern": "High-level description of the vulnerability pattern (e.g. 'heap buffer overflow when reading variable-length data into a fixed-size stack buffer without size bound')",
|
| 285 |
+
"report_condition": "When should the checker emit a warning? (e.g. 'call to gf_strdup where the argument originates from a fixed-size local array that was populated by variable-length bitstream reads')",
|
| 286 |
+
"safe_condition": "When should the checker NOT emit a warning? (e.g. 'argument originates from a heap allocation or a size-bounded source')",
|
| 287 |
+
"source_level_signal": "What AST / MemRegion / SVal property does the checker look for? (e.g. 'MemRegion extent < parameter size at a PreCall to gf_strdup')"
|
| 288 |
+
},
|
| 289 |
+
"api_choice": {
|
| 290 |
+
"mechanism_level": "syntactic_ast | control_flow | path_sensitive | interprocedural_dataflow",
|
| 291 |
+
"callback": "check::PreCall | check::PostCall | check::PreStmt | check::PostStmt | check::Bind | check::DeadSymbols | check::EndFunction | ...",
|
| 292 |
+
"reasoning": "Why this callback and its AST/state/CFG evidence prove the report and safe conditions",
|
| 293 |
+
"alternatives_considered": ["check::PostCall"]
|
| 294 |
+
},
|
| 295 |
+
"implementation": {
|
| 296 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 297 |
+
"checker_name": "project.CheckerName",
|
| 298 |
+
"build_attempts": 1
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
### ``summary.json``
|
| 304 |
+
|
| 305 |
+
```json
|
| 306 |
+
{
|
| 307 |
+
"status": "plausible | failed",
|
| 308 |
+
"bug_pattern": "One sentence describing the bug pattern",
|
| 309 |
+
"scope_level": "patch_specific | project_general | cross_project",
|
| 310 |
+
"checker_cpp": "checker.cpp",
|
| 311 |
+
"checker_so": "checker.so",
|
| 312 |
+
"n_buggy": 0,
|
| 313 |
+
"n_patched": 0,
|
| 314 |
+
"total_reports": 0,
|
| 315 |
+
"fp_rate_estimate": 0.0,
|
| 316 |
+
"failure_reason": null
|
| 317 |
+
}
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
## Feedback-derived requirements for this fresh synthesis
|
| 321 |
+
|
| 322 |
+
A prior independent rollout exposed the risks below. Start again from the patch
|
| 323 |
+
in this new session. Do not reconstruct, edit, or assume the prior checker.
|
| 324 |
+
|
| 325 |
+
Required mechanism level: `path_sensitive`
|
| 326 |
+
|
| 327 |
+
### Current failure diagnosis
|
| 328 |
+
|
| 329 |
+
- The rollout proved the syntactic sequence of memory load, blocking call, and later dereference, but did not prove that synchronization or ownership protection had been relinquished so that the pointee could actually be freed.
|
| 330 |
+
- Treating every memory-loaded local pointer as stale after any classified blocking call was semantically broader than the CVE and exposed false-positive risk for pointers protected by a live lock, reference, or refcount.
|
| 331 |
+
- The refinement round ended with feedback_required, so the proposed scope and transfer rules were not accepted as clean or converged.
|
| 332 |
+
- Process quality remained below threshold because project scans were repeated after parse failures without resolving the missing-header or invalid-flag environment, even though later harness validation supplied successful differential evidence.
|
| 333 |
+
- The 10-before and 0-after result demonstrated patch discrimination, but patch discrimination alone did not establish the use-after-free root cause required by semantic_mechanism.
|
| 334 |
+
|
| 335 |
+
### Preserve from prior rollouts
|
| 336 |
+
|
| 337 |
+
- Preserve successful checker compilation, before/after validation, and code verification.
|
| 338 |
+
- Preserve objective eligibility gate G6.
|
| 339 |
+
- Preserve semantic score at or above the configured threshold.
|
| 340 |
+
- Do not introduce dependence on changed lines, patch anchors, or diagnostic proximity to the patch.
|
| 341 |
+
- Do not introduce patch-local hardcoding such as jbd2 function, field, type, file, or line names.
|
| 342 |
+
|
| 343 |
+
### Required semantic proof
|
| 344 |
+
|
| 345 |
+
- Track a pointer value loaded from shared mutable memory and retain its identity through relevant local copies along an analyzed execution path.
|
| 346 |
+
- Establish that the protection relevant to that shared pointer is relinquished before a scheduling or blocking operation, creating the concurrency window identified by the patch evidence.
|
| 347 |
+
- Require a feasible path from the original load through the protection-release and scheduling window to a dereference of the same cached value.
|
| 348 |
+
- Report only when no reload from the shared memory location replaces the cached value after the last qualifying scheduling window and before the dereference on that path.
|
| 349 |
+
- Treat a reload after the release-schedule-reacquire cycle as the safety operation demonstrated by the patched loop.
|
| 350 |
+
- Exclude cases where path evidence shows that protection or a live ownership/reference guarantee remains effective across the blocking operation.
|
| 351 |
+
|
| 352 |
+
### Implementation constraints
|
| 353 |
+
|
| 354 |
+
- Use path-sensitive CSA callbacks and ProgramState traits to represent cached-value origin, relevant protection or ownership status, exposure to a qualifying scheduling window, and replacement by reload.
|
| 355 |
+
- Model assignments and initializers through bind or equivalent expression-value events so facts follow the pointer value through local copies and are killed when overwritten by an unrelated value.
|
| 356 |
+
- Observe direct scheduling/blocking calls and relevant protection transitions in statement callbacks; do not mark every live pointer stale merely because a function contains a blocking call.
|
| 357 |
+
- Recognize dereference sinks including member access through a pointer, unary dereference, array subscripting, and address-taking of a member used in call arguments.
|
| 358 |
+
- Keep the analysis intraprocedural unless the required event is directly represented in the current exploded path; do not claim a callee-side free has been proven when only a generic call name was observed.
|
| 359 |
+
- Emit a path-sensitive report at the stale dereference, with supporting load and qualifying scheduling-window events when CSA path diagnostics can represent them.
|
| 360 |
+
- Keep scope project-general by using semantic AST types, regions, symbols, and documented kernel synchronization or scheduling APIs rather than patch-specific identifiers.
|
| 361 |
+
|
| 362 |
+
### Validation checklist
|
| 363 |
+
|
| 364 |
+
- Build the fresh checker plugin successfully against the supplied Clang Static Analyzer API and verify registration under the intended checker name.
|
| 365 |
+
- Resolve the project parsing environment before scanning; confirm both supplied source versions are analyzed with no skipped files or compile errors.
|
| 366 |
+
- Scan the vulnerable source and require diagnostics for the stale transaction value that survives the lock-release and schedule cycle to the later dereference.
|
| 367 |
+
- Scan the patched source and require no diagnostic because each loop iteration reloads j_running_transaction after the prior scheduling cycle.
|
| 368 |
+
- Verify the primary diagnostic is located at the stale dereference in jbd2_journal_wait_updates, with load and scheduling-window events represented as supporting path context rather than separate warnings.
|
| 369 |
+
- Add focused cases for no blocking call, reload after blocking, unrelated overwrite, local or parameter origin, local-copy propagation, and dereferences nested in call arguments.
|
| 370 |
+
- Add refinement cases where a lock or live reference remains protective across a wait and require no report, addressing the semantic false-positive concern.
|
| 371 |
+
- Re-run differential and code verification and retain the observed eligibility properties: vulnerable presence, patched cleanliness, relevant disappearance, and no unrelated disappearance.
|
| 372 |
+
|
| 373 |
+
### Avoid and forbidden regressions
|
| 374 |
+
|
| 375 |
+
- Do not repeat a function-wide AST or CFG may-analysis that marks all cached pointers crossed after any blocking primitive without path-specific protection evidence.
|
| 376 |
+
- Do not equate sleeping or scheduling by itself with proof that an arbitrary pointee can be freed.
|
| 377 |
+
- Do not use diagnostic disappearance in the patched revision as a substitute for proving pointer identity, exposure, and missing reload.
|
| 378 |
+
- Do not report at the load, lock operation, or blocking call when the vulnerability manifests at the later stale dereference.
|
| 379 |
+
- Do not infer safety from a reload on only some alternate path; the analyzed reporting path must still carry the old value to the sink.
|
| 380 |
+
- Do not broaden scheduling primitive lists or exclude APIs solely to tune this patch's warning count.
|
| 381 |
+
- Do not repeat scans after parser failure without first correcting and verifying the compilation flags and header environment.
|
| 382 |
+
- Do not rely on the prior checker implementation as an artifact to edit, repair, resume, reconstruct, or copy.
|
tasks/csa159/pair_165550/checker_template.cpp
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// CSA Checker Template
|
| 3 |
+
// ============================================================================
|
| 4 |
+
// Fill in the sections marked with TODO to implement your checker.
|
| 5 |
+
// The checker is compiled with -fno-rtti to match the LLVM 18 build config.
|
| 6 |
+
// It is loaded via: clang -cc1 -load checker.so -analyzer-checker=your.CheckerName
|
| 7 |
+
//
|
| 8 |
+
// Compilation:
|
| 9 |
+
// clang++ -std=c++17 -fPIC -shared -fno-rtti -fno-exceptions \
|
| 10 |
+
// -I${LLVM_BUILD_DIR}/include \
|
| 11 |
+
// checker.cpp -o checker.so \
|
| 12 |
+
// -Wl,--allow-shlib-undefined
|
| 13 |
+
//
|
| 14 |
+
// Usage:
|
| 15 |
+
// clang -cc1 -load ./checker.so -analyzer-checker=your.CheckerName -analyze <file>
|
| 16 |
+
// ============================================================================
|
| 17 |
+
|
| 18 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
|
| 19 |
+
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
| 20 |
+
#include "clang/StaticAnalyzer/Core/Checker.h"
|
| 21 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
| 22 |
+
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
| 23 |
+
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 |
+
|
| 25 |
+
using namespace clang;
|
| 26 |
+
using namespace ento;
|
| 27 |
+
|
| 28 |
+
namespace {
|
| 29 |
+
|
| 30 |
+
// ────────────────────────────────────────────────────────────────
|
| 31 |
+
// TODO: Rename this class to describe your checker's purpose.
|
| 32 |
+
// ────────────────────────────────────────────────────────────────
|
| 33 |
+
class {{CHECKER_CLASS_NAME}}
|
| 34 |
+
: public Checker<check::PreCall, // for checking before function calls
|
| 35 |
+
check::PostCall> // for checking after function calls
|
| 36 |
+
{
|
| 37 |
+
// TODO: Customize the bug type name and category.
|
| 38 |
+
mutable std::unique_ptr<BugType> BT;
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
{{CHECKER_CLASS_NAME}}()
|
| 42 |
+
: BT(new BugType(this, "{{BUG_NAME}}", "{{BUG_CATEGORY}}")) {}
|
| 43 |
+
|
| 44 |
+
// ── PreCall callback (fires before every function call) ──────
|
| 45 |
+
void checkPreCall(const CallEvent &Call, CheckerContext &C) const {
|
| 46 |
+
// TODO: Implement your pre-call analysis logic here.
|
| 47 |
+
//
|
| 48 |
+
// Common patterns:
|
| 49 |
+
//
|
| 50 |
+
// 1. Check if the called function matches a specific name:
|
| 51 |
+
// if (Call.getCalleeIdentifier()) {
|
| 52 |
+
// StringRef name = Call.getCalleeIdentifier()->getName();
|
| 53 |
+
// if (name == "target_function") { ... }
|
| 54 |
+
// }
|
| 55 |
+
//
|
| 56 |
+
// 2. Get the program state:
|
| 57 |
+
// ProgramStateRef State = C.getState();
|
| 58 |
+
//
|
| 59 |
+
// 3. Get arguments:
|
| 60 |
+
// SVal Arg = Call.getArgSVal(0);
|
| 61 |
+
//
|
| 62 |
+
// 4. Generate a bug report:
|
| 63 |
+
// ExplodedNode *ErrNode = C.generateErrorNode();
|
| 64 |
+
// if (ErrNode) {
|
| 65 |
+
// auto R = std::make_unique<PathSensitiveBugReport>(
|
| 66 |
+
// *BT, "Description of the bug", ErrNode);
|
| 67 |
+
// C.emitReport(std::move(R));
|
| 68 |
+
// }
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ── PostCall callback (fires after every function call) ─────
|
| 72 |
+
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
|
| 73 |
+
// TODO: Implement your post-call analysis logic here.
|
| 74 |
+
//
|
| 75 |
+
// Common pattern — check the return value:
|
| 76 |
+
// SVal RetVal = Call.getReturnValue();
|
| 77 |
+
// if (RetVal.isUnknownOrUndef()) return;
|
| 78 |
+
//
|
| 79 |
+
// ProgramStateRef State = C.getState();
|
| 80 |
+
// // Modify state based on post-call conditions...
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
} // anonymous namespace
|
| 85 |
+
|
| 86 |
+
// ────────────────────────────────────────────────────────────────
|
| 87 |
+
// Registration — DO NOT modify the function signatures.
|
| 88 |
+
// ────────────────────────────────────────────────────────────────
|
| 89 |
+
|
| 90 |
+
extern "C" void clang_registerCheckers(CheckerRegistry ®istry) {
|
| 91 |
+
registry.addChecker<{{CHECKER_CLASS_NAME}}>(
|
| 92 |
+
"{{CHECKER_FULL_NAME}}", // e.g., "your.NullDereferenceChecker"
|
| 93 |
+
"{{CHECKER_DESC}}", // e.g., "Detects null pointer dereference"
|
| 94 |
+
"{{CHECKER_DOC_URI}}"); // e.g., "https://example.com/docs"
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
extern "C" const char clang_analyzerAPIVersionString[] =
|
| 98 |
+
CLANG_ANALYZER_API_VERSION_STRING;
|