Programming-split
Programming-split
Library Robustness
Manuel Rigger1, René Mayrhofer1, Roland Schatz2, Matthias Grimmer2,
Hanspeter Mössenböck1
1 Johannes Kepler University Linz, Austria
2 Oracle Labs Linz, Austria
<Programming> 2018,
12 April 2018, Nice, France.
Problem: Errors in C
2
Problem: Errors in C
Buffer Overflows
• No bounds checks
• No bounds information
3
Problem: Errors in C
Memory Management Errors
Invalid free error Double-free error
Use-after-free error free(stackobject); free(heapobject);
free(heapobject); free(heapobject);
heapobject[0] = val; Memory leak
free(heapobject);
4
Problem: Errors in C
Type Confusion
• No type safety
• No type information
5
Problem: Errors in C
Type Confusion int f(int arg1)
• No type safety
• No type information
5
Problem: Errors in C
Format String Vulnerabilities
Type Confusion
printf("%s", 3);
Missing argument
printf("%d %d %s" , 3, 5);
6
Problem: Errors in C
7
State-of-the-art Run-time Approaches
8
State-of-the-art Run-time Approaches
• LLVM’s sanitizers
• Valgrind, Dr. Memory
• Libcrunch
• SoftBound+CETS
• Safe Sulong
9
State-of-the-art Run-time Approaches
• LLVM’s sanitizers
• Valgrind, Dr. Memory
• Libcrunch These systems track object
• SoftBound+CETS metadata to implement checks
• Safe Sulong
9
Problem: Errors in C
Unaddressed
10
Goal
11
Motivation
Log error
and
continue
Goals
Return
Add
error
assertions
code
12
Motivation
Log error
and
continue
Return
Add
error
assertions
code
12
Structure
Introspection interface
Implementation in tools
Ongoing work
13
Introspection interface
14
Introspection Functions
Object
bounds
Types
15
Bounds
16
Bounds
sizeof(int) * 10
_size_left()
17
Bounds
sizeof(int) * 10
_size_right()
18
Memory Location
enum Location {
INVALID,
AUTOMATIC,
DYNAMIC,
STATIC
};
19
Memory Location
int a;
void func() {
static int b;
int c;
int *d = malloc(sizeof(int) * 10);
free(d);
}
20
Memory Location
void func() {
static int b;
int c;
int *d = malloc(sizeof(int) * 10);
free(d);
}
20
Memory Location
int a;
void func() {
static int b; location(&b) STATIC
int c;
int *d = malloc(sizeof(int) * 10);
free(d);
}
20
Memory Location
int a;
void func() {
static int b;
int c; location(&c) AUTOMATIC
int *d = malloc(sizeof(int) * 10);
free(d);
}
20
Memory Location
int a;
void func() {
static int b;
int c;
int *d = malloc(sizeof(int) * 10);
free(d); location(d) DYNAMIC
}
20
Memory Location
int a;
void func() {
static int b;
int c;
int *d = malloc(sizeof(int) * 10);
free(d);
}
location(d) INVALID
20
Type Information
21
Type Information
21
Type Information
22
Type Information
Check if an object is
"compatible" with a type
22
Type Information
int arr[10];
int *ptr = &(arr[9]);
int val;
val = try_cast(&ptr, type(val));
23
Variadic Arguments
int count_varargs();
void* get_vararg(int i, struct Type* type);
24
Variadic Arguments
"%d %d %s"
25
Case Study on Libc
26
Introspection Goals
Improve
availability
of the
system
Goals
Improve Fix
bug-finding incomplete
capabilities APIs
27
Introspection to Increase Availability
28
Example: strlen()
29
Example: strlen()
... P r o g r a m m i n g \0 ...
29
Example: strlen()
... P r o g r a m m i n g \0 ...
29
Example: strlen()
... P r o g r a m m i n g \0 ...
29
Example: strlen()
... P r o g r a m m i n g ...
30
Example: strlen()
... P r o g r a m m i n g ...
30
Example: strlen()
... P r o g r a m m i n g ...
30
Example: strlen()
... P r o g r a m m i n g ...
31
Example: strlen()
... P r o g r a m m i n g ...
31
Example: strlen()
... P r o g r a m m i n g ...
31
Introspection to Improve Bug-Finding
• Check invariants
• Abort when detecting inconsistencies
• E.g., allow libc’s “safe” functions to detect incorrect buffer sizes
32
Improve bug-finding capabilities
33
Improve bug-finding capabilities
... P r o g r a m m i n g \0 ... 100
33
Improve bug-finding capabilities
... P r o g r a m m i n g \0 ... 100
33
Improve bug-finding capabilities
... P r o g r a m m i n g \0 ... 100
33
Improve bug-finding capabilities
35
Introspection to Fix Errors in API Design
... ...
35
Introspection to Fix Errors in API Design
... ...
35
Introspection to Fix Errors in API Design
36
Introspection to Fix Errors in API Design
36
Other examples
37
Other examples
37
Other examples
38
Other examples
38
Other examples
39
Other examples
39
Implementation in Tools
40
Implementation in Safe Sulong
Execute on
JVM
41
Implementation in Safe Sulong
Execute on
JVM
41
Implementation in Safe Sulong
42
Implementation in Safe Sulong
ptr: Address
I32Array
data
offset=4
contents {0, 0, 0}
location=DYNAMIC
location=AUTOMATIC
42
Implementation in Safe Sulong
ptr: Address
I32Array
data
offset=4
contents {0, 0, 0}
location=DYNAMIC
location=AUTOMATIC
ptr: Address
I32Array
data
offset=4
contents {0, 0, 0}
location=DYNAMIC
location=AUTOMATIC
location(ptr) DYNAMIC
43
Implementation in Safe Sulong
ptr: Address
I32Array
data
offset=4
contents {0, 0, 0}
location=DYNAMIC
location=AUTOMATIC
44
Ongoing Work
• Implementation in other tools
• Case Study on real-world bugs
45
Ongoing work: LLVM’s AddressSanitizer
... ...
size_right()
46
Ongoing work: LLVM’s AddressSanitizer
... ...
size_right()
46
Ongoing work: GCC’s Intel MPX Bounds
Checks Instrumentation
47
Ongoing work: GCC’s Intel MPX Bounds
Checks Instrumentation
47
Ongoing work: SoftBound
48
Ongoing work: Real-world bugs
49
CVE-2017-14493
state->mac_len = opt6_len(opt) - 2;
memcpy(&state->mac[0], opt6_ptr(opt, 2),
state->mac_len);
50
CVE-2017-14493
state->mac_len = opt6_len(opt) - 2;
memcpy(&state->mac[0], opt6_ptr(opt, 2),
state->mac_len);
if (content->name != NULL)
strcat(buf, (char *) content->name);
51
CVE-2017-9047
if (content->name != NULL)
strcat(buf, (char *) content->name);
51
CVE-2017-16352
52
CVE-2017-16352
53
CVE-2017-16352
54
CVE-2017-16352
55
Discussion
... P r o g r a m m i n g ...
56
Discussion
... P r o g r a m m i n g ...
56
Discussion
... P r o g r a m m i n g ...
56
Discussion
... P r o g r a m m i n g ...
57
Discussion
size_right(ptr); LONG_MAX
57
Discussion
size_right(ptr); LONG_MAX
57
Discussion
Legacy software
58
Discussion
59
Conclusion
@RiggerManuel
60