Skip to content

Data flow: Add FeatureEscapesSourceCallContext(OrEqualSourceSinkCallContext) flow feature#21404

Open
hvitved wants to merge 4 commits intogithub:mainfrom
hvitved:dataflow/no-enclosing-stack-flow-feature
Open

Data flow: Add FeatureEscapesSourceCallContext(OrEqualSourceSinkCallContext) flow feature#21404
hvitved wants to merge 4 commits intogithub:mainfrom
hvitved:dataflow/no-enclosing-stack-flow-feature

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Mar 3, 2026

This PR adds two new flow features FeatureEscapesSourceCallContext and FeatureEscapesSourceCallContextOrEqualSourceSinkCallContext.

The former implies that the sink must be reached from the source by escaping the source call context, that is, flow must either return from the callable containing the source or use a jump-step before reaching the sink. The latter is the disjunction of the former and the existing FeatureEqualSourceSinkCallContext flow feature.

This allows us to greatly simplify the Rust query AccessAfterLifetime.ql, in addition to improving performance and precision of said query, since filtering of results now happen as part of the data flow computation instead of an ad-hoc after-the-fact filter.

DCA for all languages except Rust is uneventful, and for Rust it shows that we achieve a significant speedup.

@github-actions github-actions bot added Rust Pull requests that update Rust code DataFlow Library labels Mar 3, 2026
@hvitved hvitved force-pushed the dataflow/no-enclosing-stack-flow-feature branch 2 times, most recently from 2e494c1 to 79dfb75 Compare March 4, 2026 08:41
@hvitved hvitved changed the title Data flow: Add new FeatureNoEnclosingCallStack(Strict) feature Data flow: Add FeatureEscapesSourceCallContext(OrEqualSourceSinkCallContext) flow feature Mar 4, 2026
@hvitved hvitved force-pushed the dataflow/no-enclosing-stack-flow-feature branch from b4f38a0 to 04fdc29 Compare March 4, 2026 09:14
@hvitved hvitved force-pushed the dataflow/no-enclosing-stack-flow-feature branch from 04fdc29 to 4474e25 Compare March 4, 2026 09:44
@hvitved hvitved marked this pull request as ready for review March 4, 2026 11:23
@hvitved hvitved requested review from a team as code owners March 4, 2026 11:23
@hvitved hvitved requested review from aschackmull and Copilot March 4, 2026 11:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the shared global data flow implementation with two new flow features to constrain results based on whether flow escapes the source call context, and updates the Rust AccessAfterLifetime query to use these features for simpler and faster filtering.

Changes:

  • Add FeatureEscapesSourceCallContext and FeatureEscapesSourceCallContextOrEqualSourceSinkCallContext as new flow configuration features in shared dataflow internals.
  • Update shared dataflow internals to track and enforce the new “escapes source call context” constraint during flow computation.
  • Simplify Rust AccessAfterLifetime.ql by relying on the new flow feature and adjust Rust tests/expected output accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
shared/dataflow/codeql/dataflow/internal/DataFlowImplStage1.qll Adds Stage 1 predicate plumbing for the new escape-context feature.
shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll Defines the new flow feature types and public feature classes.
shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll Implements summary-context handling to enforce the new feature during dataflow.
shared/dataflow/change-notes/2026-03-04-flow-feature-escapes-source-call-context.md Adds changelog entry documenting the new flow features.
rust/ql/src/queries/security/CWE-825/AccessAfterLifetime.ql Switches the query to use the new flow feature and removes ad-hoc filtering logic.
rust/ql/test/query-tests/security/CWE-825/lifetime.rs Updates inline expectations to reflect the new/changed result.
rust/ql/test/query-tests/security/CWE-825/AccessAfterLifetime.expected Updates expected output to match new analysis results.

}

/**
* A flow configuration feature that is the disjuction of `FeatureEscapesSourceCallContext`
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

Typo in comment: "disjuction" should be "disjunction".

Suggested change
* A flow configuration feature that is the disjuction of `FeatureEscapesSourceCallContext`
* A flow configuration feature that is the disjunction of `FeatureEscapesSourceCallContext`

Copilot uses AI. Check for mistakes.

predicate hasSourceCallCtx();

predicate hasFeatureEscapesSourceCallContext(boolean nonEmpty);
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The boolean parameter name in the signature uses nonEmpty, but the implementation and the underlying feature use strict. Consider renaming the parameter in the signature to strict for consistency/readability.

Copilot generated this review using guidance from repository custom instructions.
TSummaryCtxSome(ParamNd p, Typ t, Ap ap, TypOption stored) {
fwdFlowInFlowThrough(p, _, t, ap, stored)
}
TSummaryCtxSome(ParamNd p, Typ t, Ap ap, TypOption stored, Boolean mustReturn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TSummaryCtxSome(ParamNd p, Typ t, Ap ap, TypOption stored, Boolean mustReturn) {
TSummaryCtxSome(ParamNd p, Typ t, Ap ap, TypOption stored, boolean mustReturn) {

Comment on lines +1008 to +1010
exists(SummaryCtx summaryCtx |
FwdFlowInNoThrough::fwdFlowIn(_, _, _, p, _, innercc, summaryCtx, t, ap, stored, _) and
summaryCtx.isValidForFlowInNoThrough(innerSummaryCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename this to include the "outer" prefix to make it more clear.

Suggested change
exists(SummaryCtx summaryCtx |
FwdFlowInNoThrough::fwdFlowIn(_, _, _, p, _, innercc, summaryCtx, t, ap, stored, _) and
summaryCtx.isValidForFlowInNoThrough(innerSummaryCtx)
exists(SummaryCtx outerSummaryCtx |
FwdFlowInNoThrough::fwdFlowIn(_, _, _, p, _, innercc, outerSummaryCtx, t, ap, stored, _) and
outerSummaryCtx.isValidForFlowInNoThrough(innerSummaryCtx)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe not, I think skipping the prefix is more consistent with what we've done elsewhere. See also below.

) {
FwdFlowInThrough::fwdFlowIn(_, _, _, p, _, innercc, _, t, ap, stored, _)
exists(SummaryCtx outerSummaryCtx |
Copy link
Contributor

Choose a reason for hiding this comment

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

Skip the "outer" prefix as per above comment.

@@ -46,10 +47,11 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
}
}

private newtype TFlowFeature =
newtype TFlowFeature =
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix accidental public.

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

A few nits, otherwise LGTM.

@hvitved hvitved force-pushed the dataflow/no-enclosing-stack-flow-feature branch from 2536be0 to db491fc Compare March 4, 2026 13:53
@hvitved hvitved requested a review from aschackmull March 4, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DataFlow Library documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants