PointsTo
Static Use-After-Free Detector for C/C++
Presented by: Peter Goodman
PointsTo detects use-after-free bugs
2
Use-after-frees are bad!
delete x;�…�y = x->foo;
3
what is this I don’t even
Example use-after-free
x = new X;�…�delete x;�…�y = new Y;�…�y->bar = 2;�x->foo = 1;
4
(1)
Example use-after-free
x = new X;�…�delete x;�…�y = new Y;�…�y->bar = 2;�x->foo = 0xBEEF;
5
x
(2)
Example use-after-free
x = new X;�…�delete x;�…�y = new Y;�…�y->bar = 2;�x->foo = 0xBEEF;
6
x
(3)
Example use-after-free
x = new X;�…�delete x;�…�y = new Y;�…�y->bar = 2;�x->foo = 0xBEEF;
7
x
y
x and y point to the same memory!
(4)
Example use-after-free
x = new X;�…�delete x;�…�y = new Y;�…�y->bar = 2;�x->foo = 0xBEEF;
8
x
y
2
(5)
Example use-after-free
x = new X;�…�delete x;�…�y = new Y;�…�y->bar = 2;�x->foo = 0xBEEF;
9
x
y
0xBEEF
Delicious
Corruption!
(6)
… but I don’t write buggy code
10
Is it possible that a use-after-free existed before you committed code?
11
How do you find use-after-frees?
12
Static use-after-free detection is hard
13
Analyzing paths for use-after-frees
14
A *a = new A; if (...) { delete a; } a->x = 10; | |
(1)
Analyzing paths for use-after-frees
15
A *a = new A; if (...) { delete a; a = ERROR; } a->x = 10; | |
(2)
Analyzing paths for use-after-frees
�
16
A *a = new A; if (...) { delete a; a = ERROR; } a->x = 10; | |
(2)
Analyzing paths for use-after-frees
17
A *a0 = new A; if (...) { a1 = ERROR; } a2 = φ(a0,a1) a2->x = 10; | |
(3)
Analyzing paths for use-after-frees
18
A *a0 = new A; if (...) { a1 = ERROR; } a2 = φ(a0,a1) a2->x = 10; | |
(4)
a0
a1
a2
E
A
->x
Analyzing paths for use-after-frees
19
A *a0 = new A; if (...) { a1 = ERROR; } a2 = φ(a0,a1) a2->x = 10; | |
(5)
a0
a1
a2
E
A
->x
How do we represent this graph?
20
a0
a1
a2
E
A
->x
(1)
How do we represent this graph?
21
a0
a1
a2
E
A
->x
(2)
A 0 000
E 1 001
a0 2 010
a1 3 011
a2 4 100
>x 5 101
Labeled Nodes
How do we represent this graph?
22
a0
a1
a2
E
A
->x
(3)
A 0 000
E 1 001
a0 2 010
a1 3 011
a2 4 100
>x 5 101
Labeled Nodes
Edges as a boolean formula
(a0,A) = 010 000 1
(a1,E) = 011 001 1
(a2,a0) = 100 010 1
(a2,a1) = 100 011 1
(>x,a2) = 101 100 1
… = … 0
How do we represent this graph?
23
(4)
(not the same boolean formula)
What about function calls?
24
void (*)(void)
Points-to analysis
25
int x; int y; int *p = &x; int *q = p; p = &y; | |
(1)
Points-to analysis
26
int x; int y; int *p = &x; int *q = p; p = &y; | |
p
x
y
(2)
Points-to analysis
27
int x; int y; int *p = &x; int *q = p; p = &y; | |
p
x
y
q
(3)
Points-to analysis
28
int x; int y; int *p = &x; int *q = p; p = &y; | |
p
x
y
q
(4)
Points-to analysis
29
(5)
And so the pieces come together
30
Now I understand, how do I use it?
Show me a demo!
31
Demo!
32
Any questions?
33