File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
cpp/ql/src/experimental/Security/CVE Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ import cpp
2+ import semmle.code.cpp.dataflow.DataFlow
3+
4+
5+ class WrtieAccessCheckMacro extends Macro {
6+ VariableAccess va ;
7+ WrtieAccessCheckMacro ( ) {
8+ this .getName ( ) = [ "user_write_access_begin" ,
9+ "user_access_begin" ]
10+ and
11+ va .getEnclosingElement ( ) = this .getAnInvocation ( ) .getAnExpandedElement ( )
12+ }
13+
14+ VariableAccess getArgument ( ) {
15+ result = va
16+ }
17+ }
18+
19+
20+ class UnSafePutUserMacro extends Macro {
21+ PointerDereferenceExpr writeUserPtr ;
22+
23+ UnSafePutUserMacro ( ) {
24+ this .getName ( ) = "unsafe_put_user" and
25+ writeUserPtr .getEnclosingElement ( ) = this .getAnInvocation ( ) .getAnExpandedElement ( )
26+ }
27+
28+ Expr getUserModePtr ( ) {
29+ result = writeUserPtr .getOperand ( ) .( AddressOfExpr ) .getOperand ( ) .( FieldAccess ) .getQualifier ( )
30+ }
31+ }
32+
33+ class ExploitableUserModePtrParam extends Parameter {
34+ ExploitableUserModePtrParam ( ) {
35+ not exists ( WrtieAccessCheckMacro writeAccessCheck |
36+ DataFlow:: localFlow ( DataFlow:: parameterNode ( this ) , DataFlow:: exprNode ( writeAccessCheck .getArgument ( ) ) )
37+ )
38+ }
39+ }
40+
41+
42+ from ExploitableUserModePtrParam p , UnSafePutUserMacro unsafePutUser
43+ where
44+ DataFlow:: localFlow ( DataFlow:: parameterNode ( p ) , DataFlow:: exprNode ( unsafePutUser .getUserModePtr ( ) ) )
45+ select
46+ p , unsafePutUser , "potential wrtie user mode ptr without check."
47+
48+
49+
You can’t perform that action at this time.
0 commit comments