Skip to content

docs(invariants): add programmability screening methodology and canar… - #6

Merged
zjy-dev merged 3 commits into
mainfrom
features/canary-invariant-screening
May 28, 2026
Merged

zjy-dev merged 3 commits into
mainfrom
features/canary-invariant-screening

Conversation

@zjy-dev

@zjy-dev zjy-dev commented May 28, 2026 •

Copy link
Copy Markdown
Owner

…y results

Introduce a project-level screening framework in invariants/README.md so each mechanism's invariant survey can separate "checker-worthy" rows from explicitly-excluded ones using the same four dimensions (observability, decisiveness, cost, static/dynamic category). Apply the framework to stack-canary.md, listing 10 invariants that pass and 18 that are excluded with reasons pointing back to specific dimensions.

Summary by Sourcery

Define a shared project-level methodology for screening invariants for programmability and apply it to the stack canary invariant survey, classifying which invariants are checker-worthy and which are explicitly excluded with reasons.

Documentation:

  • Document a common four-dimensional framework for evaluating which invariants should become automated checkers and how they map to static vs dynamic analysis.
  • Update the stack canary invariants doc to list the invariants that pass the programmability screening and those that are excluded, with categorized reasons referencing the shared framework.

…y results

Introduce a project-level screening framework in invariants/README.md so
each mechanism's invariant survey can separate "checker-worthy" rows from
explicitly-excluded ones using the same four dimensions (observability,
decisiveness, cost, static/dynamic category). Apply the framework to
stack-canary.md, listing 10 invariants that pass and 18 that are
excluded with reasons pointing back to specific dimensions.
@sourcery-ai

sourcery-ai Bot commented May 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces a shared project-level methodology for determining which documented invariants are suitable for automated checking, and applies it to the stack-canary invariants by adding a new section that classifies each invariant as checker-worthy or explicitly excluded with reasons tied to the four screening dimensions.

Flow diagram for invariant programmability screening methodology

flowchart TD
    A[Invariant from survey] --> B[Evaluate observability]
    B --> C[Evaluate decisiveness]
    C --> D[Evaluate implementation_cost]
    D --> E[Determine static_vs_dynamic category]

    E --> F{Any dimension severely inadequate?}

    F -- Yes --> G[Classify as excluded_invariant]
    G --> H[Record 排除理由 referencing specific dimension]

    F -- No --> I[Classify as checker_worthy_invariant]
    I --> J[Record 通过理由 referencing dimensions]

    J --> K[Emit entry under stack_canary 可程序化 invariants]
    H --> K
Loading

File-Level Changes

Change Details Files
Define a project-wide programmability screening methodology for invariants and integrate it into the invariants documentation structure.
  • Replace the previous "写新 survey 的流程" section 4 with a new "可程序化筛选方法论" section describing the purpose of programmability screening and its distinction from the broader research-oriented invariant survey.
  • Introduce four evaluation dimensions (observability, decisiveness, implementation cost, static/dynamic category) with definitions and typical failure signals, and clarify that any single dimension can be a sufficient exclusion reason.
  • Specify criteria for classifying invariants as static vs dynamic and how this maps to oracle categories and existing documentation (story_line.md, invariant.go).
  • Define a standard recording format for per-mechanism "可程序化 invariants" chapters, including required fields for accepted and excluded invariants and explicit links back to the shared methodology section.
  • Clarify documentation conventions: per-mechanism docs should not repeat the methodology, should avoid implementation details and prioritization, and must phrase exclusion reasons in terms of the four dimensions.
docs/tech-docs/invariants/README.md
Apply the new programmability screening framework to the stack-canary invariants by adding a dedicated section that classifies which invariants should become checkers and which should be excluded, with rationale.
  • Insert a new section "可程序化 invariants" before the existing open-questions section in the stack-canary survey, referencing the shared methodology in README.md instead of re-describing it.
  • List "通过筛选" stack-canary invariants (10 items) including guard symbol presence, main/no_stack_protector behavior, attribute-driven protection, VLA/alloca-triggered canaries, canary layout and sharing, stack_chk_fail semantics, epilogue scrub behavior, and the GCC 2023-4039 historical violation, each tagged as static or dynamic with a short acceptance rationale tied to observability, decisiveness, cost, and reuse of existing checkers/templates.
  • List "未通过筛选" stack-canary invariants (18 items) covering heuristic flags, configuration/linker contracts, compiler-internal state, hardening-ideal properties, ISA-specific layout details, guard source/placement, runtime hooks, LTO interactions, and cross-DSO behavior, each with an explicit exclusion reason mapped to a screening dimension such as observability gaps, decisiveness issues, or implementation cost.
  • Adjust section numbering so that the new "可程序化 invariants" section becomes section 11 and the previous "开放问题 / 未覆盖 invariants (Follow-ups)" moves to section 12.
  • Ensure the new section reuses existing terminology (e.g., references to BinaryInspector, DynamicBufferSearchChecker, EpilogueCanaryScrubChecker, seed templates, and dynamic search channels) to make it clear how the classified invariants relate to current and potential oracle implementations.
docs/tech-docs/invariants/stack-canary.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

张景耀 added 2 commits May 28, 2026 13:18
Rewrite stack-canary.md and invariants/README.md as pure research
artifacts. Remove project-specific coupling that crept in:

- drop oracle_mapping field; replace with observation describing
  the phenomenon rather than how DeFuzz detects it
- drop all references to checker file paths, seed templates, exit
  code conventions, sentinel markers, and DREV identifiers
- delete the §10 "DeFuzz Canary Oracle 映射总表" and §12 usage
  advice — these are implementation docs, not invariants research
- rewrite INV-SP-R03 entry around the observable phenomenon
  (guard residue in callee-saved register at function return)
  instead of the EpilogueCanaryScrubChecker probe protocol

Verify versions against current upstream:

- GCC 16.1 (released 2026-04-30) confirmed for stack_protect_*
  predicates in cfgexpand.cc
- -fhardened meta-flag list re-checked against GCC 14+ docs
- add S/390 follow-up note for GCC 16.1 backend coverage

Drop "正控/负控" jargon throughout in favor of plain language.
Restrict stack-canary.md and the cross-mechanism source survey to invariants
whose violation results in silent bypass: the defense appears to run, no
trap fires, but control-data is overwritten or the guard is predictable.
Items whose violation only causes mechanism strengthening, compile-time
errors, or link-time errors are removed.

stack-canary.md:
- New unified threat model: silent bypass.
- Drop heuristic-detail/flag-precondition/attribute/runtime-contract/
  guard-source/non-bypass register-convention invariants (E01-E03, F02-F03,
  X01-X02, A01-A03, G01-G04, R01-R02, H01-H02 details).
- Retain and reframe: L01 (canary between vulnerable locals and saved
  regs/retaddr), L02 (VLA/alloca on stack-low side, CVE-2023-4039), L03
  (multiple vulnerable objects share canary protection face).
- Add L04 (protector slot must not be reallocated after locals; CERT
  VU#129209 / LLVM D64759).
- Add V01 (epilogue compares guard value, not address; GCC 9 Cortex-M4 bug).
- Add V02 (__stack_chk_fail must be noreturn).
- Add S01 (guard value/address must not spill to attacker-writable stack;
  GCC PR 85434, LLVM D64759).
- Add S02 (epilogue must clobber registers holding canary; GCC PR 96191 +
  meta-bug 125045).
- Keep H01 only as the documentation-level guarantee that VLA/alloca
  functions are always instrumented (its violation is whole-function silent
  bypass).
- Add a "Known silent-bypass cases" table mapping CVE-2023-4039, CERT
  VU#129209, GCC 9 Cortex-M4 codegen bug, GCC PR 85434, GCC PR 96191 +
  125045 to the invariants they violate.

gcc-llvm-defense-invariant-source-survey.md:
- Retitle and rescope to silent-bypass perspective; explicitly state the
  threat model.
- Restate the implicit-constraint bullet list to highlight silent-failure
  paths (layout, verification logic, secrecy, dedicated registers, ELF
  notes, runtime contracts, byte-pattern constraints).
- Replace the verification anchor table with known silent-bypass cases
  (CVE-2023-4039, CERT VU#129209, GCC PR 85434, GCC PR 96191 + 125045,
  GCC 9 Cortex-M4 codegen, _FORTIFY_SOURCE degradation, IBT byte
  collision, missing CET ELF note, SCS x86_64 removal, Clang CFI
  -flto/-fvisibility prerequisites).
- Rewrite the usage-recommendation section to drop project coupling
  (DeFuzz, oracle_mapping) and align with the README field convention.

Evidence verified by web search and source review for each new invariant
(CVE-2023-4039 patch series, CERT VU#129209 advisory, LLVM D64759, GCC
PR 85434 / 96191 / 125045, GCC 9 Cortex-M4 bug report).
@zjy-dev
zjy-dev merged commit 82c1c64 into main May 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant