Skip to content

Commit f66838c

Browse files
authored
Merge pull request #43 from github/offensive-con-workshop-materials
Adds offensivecon's workshop slides and materials
2 parents 58144b4 + 1b8ae49 commit f66838c

33 files changed

Lines changed: 268 additions & 0 deletions

File tree

8.5 MB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cpp
2+
import semmle.code.cpp.dataflow.DataFlow
3+
4+
class KMalloc extends Function {
5+
KMalloc() { getName() = "kmalloc" }
6+
}
7+
8+
from KMalloc fun, FunctionCall source, Expr sink
9+
where
10+
source = fun.getACallToThisFunction() and
11+
DataFlow::localExprFlow(source, sink)
12+
select source, sink, sink.getEnclosingStmt()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cpp
2+
import semmle.code.cpp.dataflow.DataFlow
3+
4+
class KMalloc extends Function {
5+
KMalloc() { getName() = "kmalloc" }
6+
}
7+
8+
from KMalloc fun, FunctionCall source
9+
where
10+
source = fun.getACallToThisFunction() and
11+
not exists(IfStmt sink | DataFlow::localExprFlow(source, sink.getControllingExpr()))
12+
select source
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import cpp
2+
import semmle.code.cpp.dataflow.DataFlow
3+
4+
class KMalloc extends Function {
5+
KMalloc() {
6+
getName() = "kmalloc" or
7+
getName() = "acpi_os_allocate_zeroed" or
8+
getName() = "kzalloc" or
9+
getName() = "kcalloc" or
10+
getName() = "kmalloc_array" or
11+
getName() = "acpi_os_allocate" or
12+
getName() = "mempool_kmalloc" or
13+
getName() = "alloc_resource" or
14+
getName() = "bitmap_alloc" or
15+
getName() = "sg_kmalloc" or
16+
getName() = "pcpu_mem_zalloc" or
17+
getName() = "bitmap_zalloc"
18+
}
19+
}
20+
21+
from KMalloc fun, FunctionCall source
22+
where
23+
source = fun.getACallToThisFunction() and
24+
not exists(IfStmt sink |
25+
DataFlow::localExprFlow(source, sink.getControllingExpr().getAChild*())
26+
)
27+
select source
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
3+
from Function fun
4+
where fun.getName().matches("%ioctl%") and fun.hasDefinition()
5+
select fun
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
3+
from Function fun, FunctionCall call
4+
where
5+
fun.getName().matches("%ioctl%") and
6+
fun.hasDefinition() and
7+
call = fun.getACallToThisFunction()
8+
select call.getEnclosingFunction(), call
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import cpp
2+
3+
from Function fun, FunctionAccess access
4+
where
5+
fun.getName().matches("%ioctl%") and
6+
access = fun.getAnAccess()
7+
select access, fun
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cpp
2+
3+
class UnusedFunction extends Function {
4+
UnusedFunction() {
5+
this.hasDefinition() and
6+
not exists(FunctionCall call | call.getTarget() = this) and
7+
not exists(FunctionAccess access | access.getTarget() = this)
8+
}
9+
}
10+
11+
from UnusedFunction unused
12+
select unused
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
3+
class UnusedVariable extends LocalVariable {
4+
UnusedVariable() { not exists(VariableAccess access | access.getTarget() = this) }
5+
}
6+
7+
from UnusedVariable unused
8+
select unused
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import cpp
2+
3+
class InterestingAssignment extends Assignment {
4+
InterestingAssignment() {
5+
this.getRValue().getUnderlyingType() != this.getLValue().getUnderlyingType()
6+
}
7+
}
8+
9+
from InterestingAssignment unused
10+
select unused, unused.getLValue().getUnderlyingType(), unused.getRValue().getUnderlyingType()

0 commit comments

Comments
 (0)