FindEFIVariables stub, QIP

This commit is contained in:
Giulio De Pasquale 2023-02-18 11:25:22 -08:00
parent a7afce0884
commit 016fa7ef2b
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,12 @@
---
lockVersion: 1.0.0
dependencies:
codeql/cpp-all:
version: 0.5.2
codeql/ssa:
version: 0.0.10
codeql/tutorial:
version: 0.0.3
codeql/suite-helpers:
version: 0.4.1
compiled: false

View File

@ -0,0 +1,42 @@
import cpp
import semmle.code.cpp.security.FlowSources
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
class EFIVarFunction extends Function {
EFIVarFunction() {
this.hasGlobalOrStdOrBslName("SmmSetVariable") or
this.hasGlobalOrStdOrBslName("SmmGetVariable")
}
}
class EFIVarPtrFunction extends PointerFieldAccess {
EFIVarPtrFunction() {
this.getTarget().hasName("SmmSetVariable") or
this.getTarget().hasName("SmmGetVariable")
}
}
predicate callHandlesEFIVariable(Expr e, Call c) {
exists(Call x, PointerFieldAccess fa |
// in case it is just a normal function call
x.getParent() = e and x.getTarget() instanceof EFIVarFunction
or
// in case the function call is actually a pointer field access, the function name will be the name of the field itself
c = x and
c instanceof VariableCall and
fa instanceof EFIVarPtrFunction and
x.getParent() = e and
c.(VariableCall).getVariable() = fa.getTarget()
)
}
class EFIVar extends Variable {
EFIVar() { exists(Expr e | callHandlesEFIVariable(e, _) and e.(Access).getTarget() = this) }
}
from Expr e, Call c, Variable v
where
callHandlesEFIVariable(e, c) and
e.(Access).getTarget() = v
select v, "This expression uses EFI variables"

View File

@ -0,0 +1,8 @@
name: codeql/cpp-queries
groups:
- cpp
- queries
dependencies:
codeql/cpp-all: "*"
codeql/suite-helpers: "*"
extractor: cpp