<s>
Memory	B-Application
safety	I-Application
is	O
the	O
state	O
of	O
being	O
protected	O
from	O
various	O
software	B-Error_Name
bugs	I-Error_Name
and	O
security	O
vulnerabilities	O
when	O
dealing	O
with	O
memory	B-Architecture
access	O
,	O
such	O
as	O
buffer	B-General_Concept
overflows	I-General_Concept
and	O
dangling	B-Error_Name
pointers	I-Error_Name
.	O
</s>
<s>
For	O
example	O
,	O
Java	B-Language
is	O
said	O
to	O
be	O
memory-safe	B-Application
because	O
its	O
runtime	O
error	O
detection	O
checks	O
array	O
bounds	O
and	O
pointer	O
dereferences	O
.	O
</s>
<s>
In	O
contrast	O
,	O
C	B-Language
and	O
C++	B-Language
allow	O
arbitrary	O
pointer	O
arithmetic	O
with	O
pointers	O
implemented	O
as	O
direct	O
memory	B-Architecture
addresses	O
with	O
no	O
provision	O
for	O
bounds	B-Data_Structure
checking	I-Data_Structure
,	O
and	O
thus	O
are	O
potentially	O
memory-unsafe	O
.	O
</s>
<s>
Memory	B-Architecture
errors	O
were	O
first	O
considered	O
in	O
the	O
context	O
of	O
resource	O
management_(computing )	O
and	O
time-sharing	B-General_Concept
systems	I-General_Concept
,	O
in	O
an	O
effort	O
to	O
avoid	O
problems	O
such	O
as	O
fork	B-Operating_System
bombs	I-Operating_System
.	O
</s>
<s>
Developments	O
were	O
mostly	O
theoretical	O
until	O
the	O
Morris	O
worm	O
,	O
which	O
exploited	O
a	O
buffer	B-General_Concept
overflow	I-General_Concept
in	O
fingerd	O
.	O
</s>
<s>
The	O
field	O
of	O
computer	O
security	O
developed	O
quickly	O
thereafter	O
,	O
escalating	O
with	O
multitudes	O
of	O
new	O
attacks	O
such	O
as	O
the	O
return-to-libc	B-Language
attack	I-Language
and	O
defense	O
techniques	O
such	O
as	O
the	O
non-executable	O
stack	O
and	O
address	O
space	O
layout	O
randomization	O
.	O
</s>
<s>
Randomization	O
prevents	O
most	O
buffer	B-General_Concept
overflow	I-General_Concept
attacks	O
and	O
requires	O
the	O
attacker	O
to	O
use	O
heap	O
spraying	O
or	O
other	O
application-dependent	O
methods	O
to	O
obtain	O
addresses	O
,	O
although	O
its	O
adoption	O
has	O
been	O
slow	O
.	O
</s>
<s>
In	O
2019	O
,	O
a	O
Microsoft	O
security	O
engineer	O
reported	O
that	O
70	O
percent	O
of	O
all	O
security	O
vulnerabilities	O
were	O
caused	O
by	O
memory	B-Application
safety	I-Application
issues	O
.	O
</s>
<s>
In	O
2020	O
,	O
a	O
team	O
at	O
Google	B-Application
similarly	O
reported	O
that	O
70	O
percent	O
of	O
all	O
"	O
severe	O
security	O
bugs	B-Error_Name
"	O
in	O
Google	B-Language
Chromium	I-Language
were	O
caused	O
by	O
memory	B-Application
safety	I-Application
problems	O
.	O
</s>
<s>
Many	O
other	O
high-profile	O
vulnerabilities	O
and	O
exploits	O
in	O
critical	O
software	O
have	O
ultimately	O
stemmed	O
from	O
a	O
lack	O
of	O
memory	B-Application
safety	I-Application
,	O
including	O
Heartbleed	B-Error_Name
and	O
a	O
long-standing	O
privilege	O
escalation	O
bug	B-Error_Name
in	O
sudo	B-Device
.	O
</s>
<s>
The	O
pervasiveness	O
and	O
severity	O
of	O
vulnerabilities	O
and	O
exploits	O
arising	O
from	O
memory	B-Application
safety	I-Application
issues	O
have	O
led	O
several	O
security	O
researchers	O
to	O
describe	O
identifying	O
memory	B-Application
safety	I-Application
issues	O
as	O
"	O
shooting	O
fish	O
in	O
a	O
barrel	O
"	O
.	O
</s>
<s>
Most	O
modern	O
high-level	O
programming	O
languages	O
are	O
memory-safe	B-Application
by	O
default	O
,	O
though	O
not	O
completely	O
since	O
they	O
only	O
check	O
their	O
own	O
code	O
and	O
not	O
the	O
system	O
they	O
interact	O
with	O
.	O
</s>
<s>
Automatic	B-General_Concept
memory	I-General_Concept
management	I-General_Concept
in	O
the	O
form	O
of	O
garbage	B-General_Concept
collection	I-General_Concept
is	O
the	O
most	O
common	O
technique	O
for	O
preventing	O
some	O
of	O
the	O
memory	B-Application
safety	I-Application
problems	O
,	O
since	O
it	O
prevents	O
common	O
memory	B-Application
safety	I-Application
errors	O
like	O
use-after-free	B-Error_Name
for	O
all	O
data	O
allocated	O
within	O
the	O
language	O
runtime	O
.	O
</s>
<s>
When	O
combined	O
with	O
automatic	O
bounds	B-Data_Structure
checking	I-Data_Structure
on	O
all	O
array	O
accesses	O
and	O
no	O
support	O
for	O
raw	O
pointer	O
arithmetic	O
,	O
garbage	B-General_Concept
collected	I-General_Concept
languages	O
provide	O
strong	O
memory	B-Application
safety	I-Application
guarantees	O
(	O
though	O
the	O
guarantees	O
may	O
be	O
weaker	O
for	O
low-level	O
operations	O
explicitly	O
marked	O
unsafe	O
,	O
such	O
as	O
use	O
of	O
a	O
foreign	B-Application
function	I-Application
interface	I-Application
)	O
.	O
</s>
<s>
However	O
,	O
the	O
performance	O
overhead	O
of	O
garbage	B-General_Concept
collection	I-General_Concept
makes	O
these	O
languages	O
unsuitable	O
for	O
certain	O
performance-critical	O
applications	O
.	O
</s>
<s>
For	O
languages	O
that	O
use	O
manual	B-Application
memory	I-Application
management	I-Application
,	O
memory	B-Application
safety	I-Application
is	O
not	O
usually	O
guaranteed	O
by	O
the	O
runtime	O
.	O
</s>
<s>
Instead	O
,	O
memory	B-Application
safety	I-Application
properties	O
must	O
either	O
be	O
guaranteed	O
by	O
the	O
compiler	O
via	O
static	O
program	O
analysis	O
and	O
automated	B-Application
theorem	I-Application
proving	I-Application
or	O
carefully	O
managed	O
by	O
the	O
programmer	O
at	O
runtime	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
Rust	B-Application
programming	I-Application
language	I-Application
implements	O
a	O
borrow	O
checker	O
to	O
ensure	O
memory	B-Application
safety	I-Application
,	O
while	O
C	B-Language
and	O
C++	B-Language
provide	O
no	O
memory	B-Application
safety	I-Application
guarantees	O
.	O
</s>
<s>
The	O
substantial	O
amount	O
of	O
software	O
written	O
in	O
C	B-Language
and	O
C++	B-Language
has	O
motivated	O
the	O
development	O
of	O
external	O
static	O
analysis	O
tools	O
like	O
Coverity	O
,	O
which	O
offers	O
static	O
memory	B-Architecture
analysis	O
for	O
C	B-Language
.	O
</s>
<s>
DieHard	O
,	O
its	O
redesign	O
DieHarder	O
,	O
and	O
the	O
Allinea	B-Application
Distributed	I-Application
Debugging	I-Application
Tool	I-Application
are	O
special	O
heap	O
allocators	O
that	O
allocate	B-General_Concept
objects	O
in	O
their	O
own	O
random	O
virtual	O
memory	B-Architecture
page	O
,	O
allowing	O
invalid	O
reads	O
and	O
writes	O
to	O
be	O
stopped	O
and	O
debugged	O
at	O
the	O
exact	O
instruction	O
that	O
causes	O
them	O
.	O
</s>
<s>
Protection	O
relies	O
upon	O
hardware	O
memory	B-General_Concept
protection	I-General_Concept
and	O
thus	O
overhead	O
is	O
typically	O
not	O
substantial	O
,	O
although	O
it	O
can	O
grow	O
significantly	O
if	O
the	O
program	O
makes	O
heavy	O
use	O
of	O
allocation	O
.	O
</s>
<s>
Randomization	O
provides	O
only	O
probabilistic	O
protection	O
against	O
memory	B-Architecture
errors	O
,	O
but	O
can	O
often	O
be	O
easily	O
implemented	O
in	O
existing	O
software	O
by	O
relinking	O
the	O
binary	O
.	O
</s>
<s>
The	O
memcheck	O
tool	O
of	O
Valgrind	B-Application
uses	O
an	O
instruction	B-Application
set	I-Application
simulator	I-Application
and	O
runs	O
the	O
compiled	O
program	O
in	O
a	O
memory-checking	O
virtual	O
machine	O
,	O
providing	O
guaranteed	O
detection	O
of	O
a	O
subset	O
of	O
runtime	O
memory	B-Architecture
errors	O
.	O
</s>
<s>
However	O
,	O
it	O
typically	O
slows	O
the	O
program	O
down	O
by	O
a	O
factor	O
of	O
40	O
,	O
and	O
furthermore	O
must	O
be	O
explicitly	O
informed	O
of	O
custom	O
memory	B-General_Concept
allocators	I-General_Concept
.	O
</s>
<s>
With	O
access	O
to	O
the	O
source	O
code	O
,	O
libraries	O
exist	O
that	O
collect	O
and	O
track	O
legitimate	O
values	O
for	O
pointers	O
(	O
"	O
metadata	O
"	O
)	O
and	O
check	O
each	O
pointer	O
access	O
against	O
the	O
metadata	O
for	O
validity	O
,	O
such	O
as	O
the	O
Boehm	B-Language
garbage	I-Language
collector	I-Language
.	O
</s>
<s>
In	O
general	O
,	O
memory	B-Application
safety	I-Application
can	O
be	O
safely	O
assured	O
using	O
tracing	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
and	O
the	O
insertion	O
of	O
runtime	O
checks	O
on	O
every	O
memory	B-Architecture
access	O
;	O
this	O
approach	O
has	O
overhead	O
,	O
but	O
less	O
than	O
that	O
of	O
Valgrind	B-Application
.	O
</s>
<s>
For	O
C	B-Language
and	O
C++	B-Language
,	O
many	O
tools	O
exist	O
that	O
perform	O
a	O
compile-time	O
transformation	O
of	O
the	O
code	O
to	O
do	O
memory	B-Application
safety	I-Application
checks	O
at	O
runtime	O
,	O
such	O
as	O
CheckPointer	O
and	O
AddressSanitizer	B-Application
which	O
imposes	O
an	O
average	O
slowdown	O
factor	O
of	O
2	O
.	O
</s>
<s>
Many	O
different	O
types	O
of	O
memory	B-Architecture
errors	O
can	O
occur	O
:	O
</s>
<s>
Buffer	B-General_Concept
overflow	I-General_Concept
–	O
out-of-bound	O
writes	O
can	O
corrupt	O
the	O
content	O
of	O
adjacent	O
objects	O
,	O
or	O
internal	O
data	O
(	O
like	O
bookkeeping	O
information	O
for	O
the	O
heap	O
)	O
or	O
return	B-Language
addresses	O
.	O
</s>
<s>
Buffer	B-General_Concept
over-read	I-General_Concept
–	O
out-of-bound	O
reads	O
can	O
reveal	O
sensitive	O
data	O
or	O
help	O
attackers	O
bypass	O
address	O
space	O
layout	O
randomization	O
.	O
</s>
<s>
Invalid	O
page	O
fault	O
–	O
accessing	O
a	O
pointer	O
outside	O
the	O
virtual	O
memory	B-Architecture
space	O
.	O
</s>
<s>
A	O
null	O
pointer	O
dereference	O
will	O
often	O
cause	O
an	O
exception	O
or	O
program	O
termination	O
in	O
most	O
environments	O
,	O
but	O
can	O
cause	O
corruption	O
in	O
operating	B-Operating_System
system	I-Operating_System
kernels	I-Operating_System
or	O
systems	O
without	O
memory	B-General_Concept
protection	I-General_Concept
,	O
or	O
when	O
use	O
of	O
the	O
null	O
pointer	O
involves	O
a	O
large	O
or	O
negative	O
offset	O
.	O
</s>
<s>
Use	B-Error_Name
after	I-Error_Name
free	I-Error_Name
–	O
dereferencing	O
a	O
dangling	B-Error_Name
pointer	I-Error_Name
storing	O
the	O
address	O
of	O
an	O
object	O
that	O
has	O
been	O
deleted	O
.	O
</s>
<s>
Uninitialized	B-Error_Name
variables	I-Error_Name
–	O
a	O
variable	O
that	O
has	O
not	O
been	O
assigned	O
a	O
value	O
is	O
used	O
.	O
</s>
<s>
Wild	B-Error_Name
pointers	I-Error_Name
arise	O
when	O
a	O
pointer	O
is	O
used	O
prior	O
to	O
initialization	O
to	O
some	O
known	O
state	O
.	O
</s>
<s>
They	O
show	O
the	O
same	O
erratic	O
behaviour	O
as	O
dangling	B-Error_Name
pointers	I-Error_Name
,	O
though	O
they	O
are	O
less	O
likely	O
to	O
stay	O
undetected	O
.	O
</s>
<s>
Stack	B-Error_Name
exhaustion	I-Error_Name
–	O
occurs	O
when	O
a	O
program	O
runs	O
out	O
of	O
stack	O
space	O
,	O
typically	O
because	O
of	O
too	O
deep	O
recursion	O
.	O
</s>
<s>
A	O
guard	B-General_Concept
page	I-General_Concept
typically	O
halts	O
the	O
program	O
,	O
preventing	O
memory	B-Architecture
corruption	O
,	O
but	O
functions	O
with	O
large	O
stack	O
frames	O
may	O
bypass	O
the	O
page	O
.	O
</s>
<s>
Heap	B-General_Concept
exhaustion	I-General_Concept
–	O
the	O
program	O
tries	O
to	O
allocate	B-General_Concept
more	O
memory	B-Architecture
than	O
the	O
amount	O
available	O
.	O
</s>
<s>
Double	O
free	B-Language
–	O
repeated	O
calls	O
to	O
free	B-Language
may	O
prematurely	O
free	B-Language
a	O
new	O
object	O
at	O
the	O
same	O
address	O
.	O
</s>
<s>
If	O
the	O
exact	O
address	O
has	O
not	O
been	O
reused	O
,	O
other	O
corruption	O
may	O
occur	O
,	O
especially	O
in	O
allocators	O
that	O
use	O
free	B-General_Concept
lists	I-General_Concept
.	O
</s>
<s>
Invalid	O
free	B-Language
–	O
passing	O
an	O
invalid	O
address	O
to	O
free	B-Language
can	O
corrupt	O
the	O
heap	O
.	O
</s>
<s>
Unwanted	O
aliasing	B-Application
–	O
when	O
the	O
same	O
memory	B-Architecture
location	O
is	O
allocated	O
and	O
modified	O
twice	O
for	O
unrelated	O
purposes	O
.	O
</s>
