Skip to content

IFDSTaintAnalysis: propagate taint through select and phi - #872

Merged
fabianbs96 merged 3 commits into
secure-software-engineering:developmentfrom
rana1911:fix/select-phi-taint
Nov 7, 2026
Merged

fabianbs96 merged 3 commits into
secure-software-engineering:developmentfrom
rana1911:fix/select-phi-taint

Conversation

@rana1911

@rana1911 rana1911 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #871.

IFDSTaintAnalysis::getNormalFlowFunction had no case for llvm::SelectInst or llvm::PHINode, so both fell through to identityFlow() and their results were never tainted. Leaks were missed for ?: even at -O0, and for ordinary if/switch/loop code once mem2reg/SimplifyCFG run.

Changes

  • IFDSTaintAnalysis.cpp: two flow functions before the identityFlow() fallback, following the existing BinaryOperator case. The result is tainted if a value operand of the select (true/false value, not the condition) or an incoming value of the phi is tainted. Other instructions are unaffected.
  • Tests: 3 programs in dummy_source_sink/ and 4 tests in IFDSTaintAnalysisTest:
    • TaintTest_Select_01: ternary at -O1 (select)
    • TaintTest_Select_01_m2r: same program after mem2reg (phi)
    • TaintTest_Select_02: if assignment that SimplifyCFG turns into a select at -O1
    • TaintTest_Select_03: select of two constants must not be tainted; a direct flow in the same function is still reported
  • CMakeLists.txt: a new list compiled with the existing generate_ll_file(... DEBUG O1) option, as in inst_interaction.

TaintTest_Select_02 matches the select by line with column 0 (any column), because LLVM 18 and 21 attach it to different columns of the same line.

Testing

  • All IFDSTaintAnalysisTest tests pass (LLVM 21.1.8, GCC 15.2).
  • Without the change to IFDSTaintAnalysis.cpp, Select_01, Select_01_m2r and Select_02 fail and Select_03 passes.
  • Formatted with clang-format 19.1.7.

Related: #846 (item 11), the same gap in IDEExtendedTaintAnalysis. Intrinsics such as llvm.smax also drop taint at -O1+; I'll handle that in a separate PR.

@fabianbs96 fabianbs96 added the enhancement New feature or request label Nov 7, 2026

@fabianbs96 fabianbs96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @rana1911,
thanks for your contribution.

Looks good to me!

@fabianbs96
fabianbs96 merged commit 9063321 into secure-software-engineering:development Nov 7, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IFDSTaintAnalysis: taint is not propagated through select and phi instructions

2 participants