Skip to content

Commit d476493

Browse files
authored
Add double-fetch.ql under CWE-362 directory
1 parent dd4e821 commit d476493

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @name Linux kernel double-fetch vulnerability detection
3+
* @description Double-fetch is a very common vulnerability pattern
4+
* in linux kernel, attacker can exploit double-fetch
5+
* issues to obatain root privilege.
6+
* Double-fetch is caused by fetching data from user
7+
* mode by calling copy_from_user twice, CVE-2016-6480
8+
* is quite a good example for your information.
9+
* @kind problem
10+
* @id cpp/linux-kernel-double-fetch-vulnerability
11+
* @problem.severity warning
12+
* @security-severity 7.5
13+
* @tags security
14+
* external/cwe/cwe-362
15+
*/
16+
17+
import cpp
18+
19+
class CopyFromUserFunctionCall extends FunctionCall{
20+
CopyFromUserFunctionCall(){
21+
this.getTarget().getName() = "copy_from_user"
22+
and not this.getArgument(1) instanceof AddressOfExpr
23+
}
24+
25+
predicate hasSameArguments(CopyFromUserFunctionCall another){
26+
this.getArgument(0).toString() = another.getArgument(0).toString()
27+
and this.getArgument(1).toString() = another.getArgument(1).toString()
28+
}
29+
30+
}
31+
32+
from CopyFromUserFunctionCall p1, CopyFromUserFunctionCall p2
33+
where
34+
not p1 = p2
35+
and p1.hasSameArguments(p2)
36+
and exists(IfStmt ifStmt|
37+
p1.getBasicBlock().getAFalseSuccessor*() = ifStmt.getBasicBlock()
38+
and ifStmt.getBasicBlock().getAFalseSuccessor*() = p2.getBasicBlock()
39+
)
40+
and not exists(AssignPointerAddExpr assignPtrAdd |
41+
p1.getArgument(1).toString() = assignPtrAdd.getLValue().toString()
42+
and p1.getBasicBlock().getAFalseSuccessor*() = assignPtrAdd.getBasicBlock()
43+
)
44+
select
45+
"first fetch", p1, "double fetch", p2
46+
47+
48+

0 commit comments

Comments
 (0)