Improving Security Through Software De bloating
1 March 2019
Michael D. Brown
Research Scientist, GTRI
1
1
Agenda
2
Introduction
Software security is a complex arms race:
This isn’t going anywhere anytime soon; Software security is an undecidable problem.
In this talk, we will explore a proactive method for improving security.
3
What is Software Bloat?
Modern software engineering practices favor software and systems that are:
This helps engineers rapidly develop complex and widely deployable software.
However, it comes at a cost – when software is deployed and executed it contains large portions of code that will never be used. This is software bloat.
4
Sources of Software Bloat - Vertical
Software bloat occurs vertically throughout the software stack, primarily at layers of abstraction.
Example: glibc modularizes a large number of common C functions via an API.
It is very unlikely that a program linking this library uses all of its functions, but the entire library is loaded at execution time.
5
Sources of Software Bloat - Lateral
Software bloat occurs laterally within a software package due to feature creep.
Example: cURL supports data transfer via 23 different protocols:
DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet and TFTP
Common users of cURL or libcurl are unlikely to full utilize this level of feature variety.
6
Prevalence of Software Bloat
A recent study of vertical software bloat by Quach et al [1] found:
7
Negative Effects of Software Bloat
Security:
Harder to analyze with bug finding tools
Bloat code may contain reachable attack vectors / vulnerabilities
Bloat code may increase the overhead of security defenses
Bloat code can potentially be used in a code reuse attack
Performance:
Increases code size / complexity
Increases memory footprint
Increases execution time (not always significant)
Increases power consumption
8
Background: Code Re-use Attacks
9
Gadget Based Code Reuse: Return Oriented Programming (ROP)
10
Gadget Based Code Reuse: Return Oriented Programming (ROP)
11
Gadget Based Code Reuse: Jump Oriented Programming (JOP)
12
Software Bloat and Gadgets
13
Software Debloating
In response to this problem, researchers are developing ways to debloat software.
Software debloating is a type of software transformation, and can be generalized as follows:
P’ = Debloat(P, context)
Stated plainly, debloating takes as input a package P and the context in which P is intended to be deployed, and produces a variant P’ that contains just enough functionality to satisfy the specified context.
14
Software Debloating
Software debloating can be performed at many different points in the software lifecycle:
Original
Source
Code
Preprocessor
Compiler
Front End
Middle End
Compiler
Back End
Linker
Package
Binary
Loader
Debloat Source Code
Debloat Intermediate
Representation (IR)
Debloat Code
in Memory
Debloat Binary via Rewriting
15
Overview of Software Debloating Techniques - CHISEL
CHISEL [2] is an automated debloating tool that targets unnecessary feature code.
It takes as input a test script written by the user that expresses the desired functionality of a debloated variant.
This test is used as part of a feedback directed program reduction method based on delta debugging principles.
16
Overview of Software Debloating Techniques - TRIMMER
TRIMMER [3] is an automated debloating tool that targets unnecessary feature code.
It takes as input a user defined static package configuration that expresses the compile time configuration of the package.
Configuration data is treated as a compile time constant, and is propagated throughout the program.
This is followed by custom, aggressive compiler optimizations to prune functionality from the program.
17
Overview of Software Debloating Techniques - PCL
Piece-wise Compilation and Loading (PCL) [5] is an automated debloating technique that targets software bloat originating from shared libraries (described as load time dead code elimination).
During compilation, the piecewise compiler generates an external dependency graph which is used at run time to eliminate code bloat in memory.
Memory locations that contain bloat are marked non-executable, preventing them from being used in a code re-use attack.
18
Claims of Positive Effects of Software Debloating on Security
19
Difficulties in Measuring Claims of Improved Security
20
Measuring the Impact of Debloating on Gadgets
Measuring the impact of debloating on gadget reduction is simple.
Static Analysis tools like ROPgadget [6] will scan a binary and count gadgets by type.
We can subtract the number of gadgets found in the debloated package from the number of gadgets found in the original and calculate the rate of gadget count reduction.
On average:
CHISEL reduced total gadgets by 54.1%
TRIMMER reduced total gadgets by 20%
PCL reduced total gadgets by 71%
21
So, reducing gadget counts in programs is good and improves security, right?
Well…. It’s complicated.
22
Shortcomings of Gadget Count Reduction
In our research, we discovered that gadget count reduction is too superficial to be an accurate metric for measuring security improvement.
We explored the effect debloating has on security using measures from the attacker’s perspective by asking the question:
How does debloating make constructing a code reuse attack more challenging or difficult?
In our experiments, it was fairly common for software debloating to achieve good gadget count reduction, yet fail to improve security.
Worse yet, we observed instances where security was made worse through software debloating despite achieving positive gadget reduction.
23
Analysis Methodology
24
Analysis Methodology
We focused our analysis on three areas:
25
Results – Gadget Composition
26
Gadget Introduction Mechanisms – Compiler Optimization
27
Gadget Introduction Mechanisms – Unintended Gadgets
28
Results – Gadget Composition
29
Prevalence of Gadget Introduction
Introduction Rate: Introduced Gadgets / Total Gadgets in Debloated Variant * 100
30
Gadget Introduction and Gadget Quality
31
Individual Gadget Quality – Special Purpose Gadgets
32
Individual Gadget Quality – Special Purpose Gadgets
Key Observations:
33
Gadget Set Quality – Expressivity of Set
34
Gadget Set Quality – Expressivity of Set
35
Results
36
Results
Key Observations:
37
High Level Summary
Of the nine debloating scenarios we explored, only one scenario resulted in a clear improvement to security across all our analysis methods. One scenario resulted in a clear negative impact on security. In the other seven scenarios, the results were mixed or neutral.
38
Alternative to Gadget Count Reduction
39
How Can We Best Incorporate These Measures
40
How Can We Best Incorporate These Measures
41
A case study – Max debloating does not mean max security improvement
42
Summary of Key Takeaways
43
Questions?
44
References
45