baggy bounds checking
play

Baggyboundschecking PeriklisAkri5dis,ManuelCosta, - PowerPoint PPT Presentation

Baggyboundschecking PeriklisAkri5dis,ManuelCosta, MiguelCastro,StevenHand C/C++programsarevulnerable Lotsofexis5ngcodeinCandC++ MorebeingwriEeneveryday


  1. Baggy
bounds
checking
 Periklis
Akri5dis,
Manuel
Costa,
 Miguel
Castro,
Steven
Hand


  2. C/C++
programs
are
vulnerable 
 • Lots
of
exis5ng
code
in
C
and
C++
 • More
being
wriEen
every
day
 • C/C++
programs
are
prone
to
bounds
errors
 • Bounds
errors
can
be
exploited
by
aEackers
 2


  3. Previous
solu5ons
are
not
enough 
 • Finding
all
bugs
is
unfeasible
 • Using
safe
languages
requires
por5ng
 • Exis5ng
solu5ons
using
fat
pointers
(Ccured, 
Cyclone)
break
binary
compa5bility
 • Backwards
compa5ble
solu5ons
are
slow
 • And
performance
is
cri5cal
for
adop5on
 3


  4. Baggy
bounds
checking
(BBC) 
 • Enforce
alloca5on
instead
of
object
bounds
 • Constrain
alloca5on
sizes
and
alignment
to 
powers
of
two
 • Fit
size
in
one
byte
 • No
need
to
store
base
address
 • Fast
lookup
using
linear
table
 4


  5. BBC
Benefits 
 • Works
on
unmodified
source
code
 • Broad
coverage
of
aEacks
 • Interoperability
with
uninstrumented
binaries
 • Good
performance
 – 30%
average
CPU
overhead
 • 6‐fold
improvement
over
previous
approaches
on
SPEC
 – 7.5%
average
memory
overhead
 – 8%
throughput
degrada5on
for
Apache
 5


  6. System
overview
 6


  7. AEack
Example
 • Pointers
start
off
valid
 p
=
malloc(200);
 • May
become
invalid
 q
=
p
+
300;
 • And
then
can
be
used
to
hijack
the
program
 *q
=
0x00000BAD
 7


  8. Tradi5onal
Bounds
Checking
 [Jones
and
Kelly]
 • Use
table
to
map
allocated
range
to
bounds
 p
=
malloc(200);

 • Lookup
bounds
using
source
p
 q
=
p
+
300;
 • Check
result
q
using
bounds
 • Note
that
source
pointer
p
assumed
valid
 – points
to
alloca5on
or
result
of
checked
arithme5c
 – maintain
this
invariant
throughout
execu5on
 • But
keeping
bounds
informa5on
is
expensive…
 8


  9. Baggy
Bounds
 • Pad
alloca5ons
to
power
of
2
 – malloc(200)
‐>
malloc(256)
 • Align
to
alloca5on
size
 – Upper
bound:
 FF
 – Lower
bound:
 00
 • Can
recover
bounds
using
 – The
valid
source
pointer
 – The
binary
logarithm
of
the
alloca5on
size
 9


  10. Bound
table
implementa5on
 • Previous
solu5ons
need
e.g.
splay
tree
to
 lookup
bounds
for
a
given
source
pointer
 • If
force
alloca5ons
to
be
a
mul5ple
of
16
byte
 slots ,
can
use
an
array
with
1
byte
per
slot
 10


  11. Efficient
table
lookup
 mov
eax,
p 
 
;
Copy
pointer
 shr
eax,
4 
 
 
;
Right‐shio
by
4
 mov
al,
[TABLE+eax] 
;
One
memory
read
 • Loads
alloca5on
size
logarithm
in
register
%al
 • However:
 • No
need
to
recover
explicit
bounds
 • Use
valid
pointer
and
alloca5on
size
directly
 11


  12. Efficient
Checks
 
 
 
 
 

q
=
p
+
300;
 mov
ebx,
p 
;
copy
source 
0x88888800
 xor
ebx,
q 
 
;
xor
with
result 
0x8888892C
 
 
 
 
 
 
 
 
0x0000012C
 shr
ebx,
al 
 
;
right
shio 
 





>>
8
 

 
 
 
 
;
by
table
entry 
0x00000001
 jnz
error 
 
;
check
for
zero 
 
!!! 12


  13. (Legal)
Out‐of‐bounds
pointers
 • C
programs
can
use
out‐of‐bounds
pointers
 • Cannot
dereference
 • Can
use
in
pointer
arithme5c
 • C
standard
allows
only
one
byte
beyond
object
 – Some
programs
go
beyond,
or
below
object
e.g.
 
 
char
*array
=
malloc(100)
–
1;
 
 
 
 
 
 
 //
now
can
use
array[1..100]
 13


  14. Dealing
with
OOB
pointers
 • 1.
Mark
to
avoid
dereference
 – Set
pointer
top
bit
[Dhurja5
et
al.]
 – Protect
top
half
of
address
space
 • 2.
Recover
valid
pointer
if
marked
 – Can
use
extra
data
structure
[Ruwase
and
Lam]
 – BBC:
support
most
cases
without
a
data
structure
 – (can
support
more
in
64‐bit
mode
–
see
later)
 14


  15. Common
out‐of‐bounds
pointers
 15


  16. Extra
check
in
fast
path
 16


  17. Op5mized
fast
path
 17


  18. Memory
Alloca5ons
 • Heap
using
binary
buddy
system
 – Perfect
fit
for
baggy
bounds
 • Align
stack
frames
at
run5me
 – Only
if
contains
array
or
address
taken
variable
 • Pad
and
align
globals
at
compile
5me
 • Memory
allocated
by
uninstrumented
code
 has
default
table
entry
 – Default
value
31:
maximal
bounds
 18


  19. Performance
Evalua5on
 • Measured
CPU
and
memory
overhead
 – Olden
and
SPEC
benchmarks
 • Baggy
 – Baggy
bounds
checking
as
described
 • Splay
 – Splay
tree
from
previous
solu5ons
 – Standard
allocator
 – Same
checks
 19


  20. Execu5on
Time
vs.
Splay
Tree
 Baggy
 Splay
 20
 Normalized
Execu0on
Time
 18
 16
 14
 12
 10
 8
 6
 4
 2
 0
 bh
 bisort
 em3d
 perimeter
 power
 treeadd
 tsp
 bzip2
 craoy
 gap
 gzip
 mcf
 parser
 twolf
 vortex
 average
 • 30%
for
baggy
vs.
6x
for
splay
tree
on
average
 20


  21. • 7.5%
for
baggy
vs.
100%
for
splay
on
average
 Normalized
Peak
Memory
 Memory
Usage
vs.
Splay
Tree
 0.5
 1.5
 2.5
 3.5
 4.5
 0
 1
 2
 3
 4
 bh
 bisort
 em3d
 health
 mst
 perimeter
 Baggy
 power
 treeadd
 tsp
 Splay
 bzip2
 craoy
 gap
 gzip
 mcf
 parser
 twolf
 vortex
 average
 21


  22. Apache
Throughput
 6000
 5000
 Requests
per
second
 4000
 3000
 Base
 2000
 Baggy
 1000
 0
 1
 2
 3
 4
 5
 6
 Concurrency
 • 8%
throughput
decrease
with
saturated
CPU
 22


  23. Effec5veness 
 • Evaluated
using
buffer
overflow
suite 
[Wilander
and
Kamkar]
 • Blocked
17
out
of
18
aEacks
 • Missed
overflow
between
structure
fields
 23


  24. Baggy
bounds
on
x64 
 • Baggy
bounds
can
fit
inside
pointers
 Avoid
memory
lookup
en5rely:
 
 
mov
rax,
p 
;
copy
pointer
 
 
shr
rax,
38 
;
shio
tag
to
%al
 24


  25. x64
Out‐of‐bounds
pointers
 • Adjust
pointer
by
offset
in
spare
bits
 • Greatly
increases
out‐of‐bounds
range
 25


  26. Conclusions
 • Baggy
Bounds
Checking
provides
prac5cal
 protec5on
from
bounds
errors
in
C\C++
 • Works
on
unmodified
programs
 • Preserves
binary
compa5bility
 • Good
performance
 – Low
CPU
overhead
(30%
average)
 – Low
memory
overhead
(7.5%
average)
 • Can
protect
systems
in
produc5on
runs
 26


Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend