<s>
Buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
is	O
any	O
of	O
various	O
techniques	O
used	O
during	O
software	O
development	O
to	O
enhance	O
the	O
security	O
of	O
executable	O
programs	O
by	O
detecting	O
buffer	B-General_Concept
overflows	I-General_Concept
on	O
stack-allocated	O
variables	O
,	O
and	O
preventing	O
them	O
from	O
causing	O
program	O
misbehavior	O
or	O
from	O
becoming	O
serious	O
security	O
vulnerabilities	O
.	O
</s>
<s>
A	O
stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
occurs	O
when	O
a	O
program	O
writes	O
to	O
a	O
memory	O
address	O
on	O
the	O
program	O
's	O
call	B-General_Concept
stack	I-General_Concept
outside	O
of	O
the	O
intended	O
data	B-General_Concept
structure	I-General_Concept
,	O
which	O
is	O
usually	O
a	O
fixed-length	O
buffer	O
.	O
</s>
<s>
Stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
bugs	O
are	O
caused	O
when	O
a	O
program	O
writes	O
more	O
data	O
to	O
a	O
buffer	O
located	O
on	O
the	O
stack	B-General_Concept
than	O
what	O
is	O
actually	O
allocated	O
for	O
that	O
buffer	O
.	O
</s>
<s>
This	O
almost	O
always	O
results	O
in	O
corruption	O
of	O
adjacent	O
data	O
on	O
the	O
stack	B-General_Concept
,	O
which	O
could	O
lead	O
to	O
program	O
crashes	O
,	O
incorrect	O
operation	O
,	O
or	O
security	O
issues	O
.	O
</s>
<s>
Typically	O
,	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
modifies	O
the	O
organization	O
of	O
stack-allocated	O
data	O
so	O
it	O
includes	O
a	O
canary	O
value	O
that	O
,	O
when	O
destroyed	O
by	O
a	O
stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
,	O
shows	O
that	O
a	O
buffer	O
preceding	O
it	O
in	O
memory	O
has	O
been	O
overflowed	O
.	O
</s>
<s>
Other	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
techniques	O
include	O
bounds	B-Data_Structure
checking	I-Data_Structure
,	O
which	O
checks	O
accesses	O
to	O
each	O
allocated	O
block	O
of	O
memory	O
so	O
they	O
cannot	O
go	O
beyond	O
the	O
actually	O
allocated	O
space	O
,	O
and	O
tagging	O
,	O
which	O
ensures	O
that	O
memory	O
allocated	O
for	O
storing	O
data	O
cannot	O
contain	O
executable	O
code	O
.	O
</s>
<s>
Overfilling	O
a	O
buffer	O
allocated	O
on	O
the	O
stack	B-General_Concept
is	O
more	O
likely	O
to	O
influence	O
program	O
execution	O
than	O
overfilling	O
a	O
buffer	O
on	O
the	O
heap	B-General_Concept
because	O
the	O
stack	B-General_Concept
contains	O
the	O
return	O
addresses	O
for	O
all	O
active	O
function	O
calls	O
.	O
</s>
<s>
However	O
,	O
similar	O
implementation-specific	O
protections	O
also	O
exist	O
against	O
heap-based	O
overflows	O
.	O
</s>
<s>
There	O
are	O
several	O
implementations	O
of	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
,	O
including	O
those	O
for	O
the	O
GNU	B-Application
Compiler	I-Application
Collection	I-Application
,	O
LLVM	B-Application
,	O
Microsoft	B-Application
Visual	I-Application
Studio	I-Application
,	O
and	O
other	O
compilers	O
.	O
</s>
<s>
A	O
stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
occurs	O
when	O
a	O
program	O
writes	O
to	O
a	O
memory	O
address	O
on	O
the	O
program	O
's	O
call	B-General_Concept
stack	I-General_Concept
outside	O
of	O
the	O
intended	O
data	B-General_Concept
structure	I-General_Concept
,	O
which	O
is	O
usually	O
a	O
fixed-length	O
buffer	O
.	O
</s>
<s>
Stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
bugs	O
are	O
caused	O
when	O
a	O
program	O
writes	O
more	O
data	O
to	O
a	O
buffer	O
located	O
on	O
the	O
stack	B-General_Concept
than	O
what	O
is	O
actually	O
allocated	O
for	O
that	O
buffer	O
.	O
</s>
<s>
This	O
almost	O
always	O
results	O
in	O
corruption	O
of	O
adjacent	O
data	O
on	O
the	O
stack	B-General_Concept
,	O
and	O
in	O
cases	O
where	O
the	O
overflow	O
was	O
triggered	O
by	O
mistake	O
,	O
will	O
often	O
cause	O
the	O
program	O
to	O
crash	O
or	O
operate	O
incorrectly	O
.	O
</s>
<s>
Stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
is	O
a	O
type	O
of	O
the	O
more	O
general	O
programming	O
malfunction	O
known	O
as	O
buffer	B-General_Concept
overflow	I-General_Concept
(	O
or	O
buffer	B-General_Concept
overrun	I-General_Concept
)	O
.	O
</s>
<s>
Overfilling	O
a	O
buffer	O
on	O
the	O
stack	B-General_Concept
is	O
more	O
likely	O
to	O
derail	O
program	O
execution	O
than	O
overfilling	O
a	O
buffer	O
on	O
the	O
heap	B-General_Concept
because	O
the	O
stack	B-General_Concept
contains	O
the	O
return	O
addresses	O
for	O
all	O
active	O
function	O
calls	O
.	O
</s>
<s>
Stack	B-General_Concept
buffer	I-General_Concept
overflow	I-General_Concept
can	O
be	O
caused	O
deliberately	O
as	O
part	O
of	O
an	O
attack	O
known	O
as	O
stack	B-General_Concept
smashing	I-General_Concept
.	O
</s>
<s>
If	O
the	O
affected	O
program	O
is	O
running	O
with	O
special	O
privileges	O
,	O
or	O
if	O
it	O
accepts	O
data	O
from	O
untrusted	O
network	O
hosts	O
(	O
for	O
example	O
,	O
a	O
public	O
webserver	B-Application
)	O
,	O
then	O
the	O
bug	O
is	O
a	O
potential	O
security	O
vulnerability	O
that	O
allows	O
an	O
attacker	O
to	O
inject	O
executable	O
code	O
into	O
the	O
running	O
program	O
and	O
take	O
control	O
of	O
the	O
process	O
.	O
</s>
<s>
Typically	O
,	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
modifies	O
the	O
organization	O
of	O
data	O
in	O
the	O
stack	B-General_Concept
frame	O
of	O
a	O
function	O
call	O
to	O
include	O
a	O
"	O
canary	O
"	O
value	O
that	O
,	O
when	O
destroyed	O
,	O
shows	O
that	O
a	O
buffer	O
preceding	O
it	O
in	O
memory	O
has	O
been	O
overflowed	O
.	O
</s>
<s>
Stack-smashing	O
protection	O
is	O
unable	O
to	O
protect	O
against	O
certain	O
forms	O
of	O
attack	O
.	O
</s>
<s>
For	O
example	O
,	O
it	O
cannot	O
protect	O
against	O
buffer	B-General_Concept
overflows	I-General_Concept
in	O
the	O
heap	B-General_Concept
.	O
</s>
<s>
There	O
is	O
no	O
sane	O
way	O
to	O
alter	O
the	O
layout	O
of	O
data	O
within	O
a	O
structure	B-General_Concept
;	O
structures	O
are	O
expected	O
to	O
be	O
the	O
same	O
between	O
modules	O
,	O
especially	O
with	O
shared	O
libraries	O
.	O
</s>
<s>
Any	O
data	O
in	O
a	O
structure	B-General_Concept
after	O
a	O
buffer	O
is	O
impossible	O
to	O
protect	O
with	O
canaries	O
;	O
thus	O
,	O
programmers	O
must	O
be	O
very	O
careful	O
about	O
how	O
they	O
organize	O
their	O
variables	O
and	O
use	O
their	O
structures	O
.	O
</s>
<s>
Canaries	O
or	O
canary	O
words	O
are	O
known	O
values	O
that	O
are	O
placed	O
between	O
a	O
buffer	O
and	O
control	O
data	O
on	O
the	O
stack	B-General_Concept
to	O
monitor	O
buffer	B-General_Concept
overflows	I-General_Concept
.	O
</s>
<s>
When	O
the	O
buffer	B-General_Concept
overflows	I-General_Concept
,	O
the	O
first	O
data	O
to	O
be	O
corrupted	O
will	O
usually	O
be	O
the	O
canary	O
,	O
and	O
a	O
failed	O
verification	O
of	O
the	O
canary	O
data	O
will	O
therefore	O
alert	O
of	O
an	O
overflow	O
,	O
which	O
can	O
then	O
be	O
handled	O
,	O
for	O
example	O
,	O
by	O
invalidating	O
the	O
corrupted	O
data	O
.	O
</s>
<s>
A	O
canary	O
value	O
should	O
not	O
be	O
confused	O
with	O
a	O
sentinel	B-Data_Structure
value	I-Data_Structure
.	O
</s>
<s>
There	O
are	O
three	O
types	O
of	O
canaries	O
in	O
use	O
:	O
terminator	O
,	O
random	O
,	O
and	O
random	O
XOR	B-Application
.	O
</s>
<s>
Current	O
versions	O
of	O
StackGuard	B-Error_Name
support	O
all	O
three	O
,	O
while	O
ProPolice	O
supports	O
terminator	O
and	O
random	O
canaries	O
.	O
</s>
<s>
Terminator	O
canaries	O
use	O
the	O
observation	O
that	O
most	O
buffer	B-General_Concept
overflow	I-General_Concept
attacks	O
are	O
based	O
on	O
certain	O
string	O
operations	O
which	O
end	O
at	O
string	O
terminators	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
the	O
attacker	O
must	O
write	O
a	O
null	O
character	O
before	O
writing	O
the	O
return	B-Language
address	I-Language
to	O
avoid	O
altering	O
the	O
canary	O
.	O
</s>
<s>
Random	O
canaries	O
are	O
randomly	O
generated	O
,	O
usually	O
from	O
an	O
entropy-gathering	O
daemon	B-Operating_System
,	O
in	O
order	O
to	O
prevent	O
an	O
attacker	O
from	O
knowing	O
their	O
value	O
.	O
</s>
<s>
Usually	O
,	O
it	O
is	O
not	O
logically	O
possible	O
or	O
plausible	O
to	O
read	O
the	O
canary	O
for	O
exploiting	O
;	O
the	O
canary	O
is	O
a	O
secure	O
value	O
known	O
only	O
by	O
those	O
who	O
need	O
to	O
know	O
itthe	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
code	O
in	O
this	O
case	O
.	O
</s>
<s>
It	O
may	O
still	O
be	O
possible	O
to	O
read	O
the	O
canary	O
if	O
the	O
attacker	O
knows	O
where	O
it	O
is	O
or	O
can	O
get	O
the	O
program	O
to	O
read	O
from	O
the	O
stack	B-General_Concept
.	O
</s>
<s>
Random	O
XOR	B-Application
canaries	O
are	O
random	O
canaries	O
that	O
are	O
XOR-scrambled	O
using	O
all	O
or	O
part	O
of	O
the	O
control	O
data	O
.	O
</s>
<s>
Random	O
XOR	B-Application
canaries	O
have	O
the	O
same	O
vulnerabilities	O
as	O
random	O
canaries	O
,	O
except	O
that	O
the	O
"	O
read	O
from	O
stack	B-General_Concept
"	O
method	O
of	O
getting	O
the	O
canary	O
is	O
a	O
bit	O
more	O
complicated	O
.	O
</s>
<s>
In	O
addition	O
,	O
random	O
XOR	B-Application
canaries	O
can	O
protect	O
against	O
a	O
certain	O
type	O
of	O
attack	O
involving	O
overflowing	O
a	O
buffer	O
in	O
a	O
structure	B-General_Concept
into	O
a	O
pointer	O
to	O
change	O
the	O
pointer	O
to	O
point	O
at	O
a	O
piece	O
of	O
control	O
data	O
.	O
</s>
<s>
Because	O
of	O
the	O
XOR	B-Application
encoding	O
,	O
the	O
canary	O
will	O
be	O
wrong	O
if	O
the	O
control	O
data	O
or	O
return	B-Language
value	I-Language
is	O
changed	O
.	O
</s>
<s>
Because	O
of	O
the	O
pointer	O
,	O
the	O
control	O
data	O
or	O
return	B-Language
value	I-Language
can	O
be	O
changed	O
without	O
overflowing	O
over	O
the	O
canary	O
.	O
</s>
<s>
Bounds	B-Data_Structure
checking	I-Data_Structure
is	O
a	O
compiler-based	O
technique	O
that	O
adds	O
run-time	O
bounds	O
information	O
for	O
each	O
allocated	O
block	O
of	O
memory	O
,	O
and	O
checks	O
all	O
pointers	O
against	O
those	O
at	O
run-time	O
.	O
</s>
<s>
For	O
C	B-Language
and	O
C++	O
,	O
bounds	B-Data_Structure
checking	I-Data_Structure
can	O
be	O
performed	O
at	O
pointer	O
calculation	O
time	O
or	O
at	O
dereference	O
time	O
.	O
</s>
<s>
Tagging	O
is	O
a	O
compiler-based	O
or	O
hardware-based	O
(	O
requiring	O
a	O
tagged	B-Architecture
architecture	I-Architecture
)	O
technique	O
for	O
tagging	O
the	O
type	O
of	O
a	O
piece	O
of	O
data	O
in	O
memory	O
,	O
used	O
mainly	O
for	O
type	O
checking	O
.	O
</s>
<s>
Also	O
,	O
certain	O
areas	O
of	O
memory	O
can	O
be	O
marked	O
as	O
non-allocated	O
,	O
preventing	O
buffer	B-General_Concept
overflows	I-General_Concept
.	O
</s>
<s>
Historically	O
,	O
tagging	O
has	O
been	O
used	O
for	O
implementing	O
high-level	O
programming	O
languages	O
;	O
with	O
appropriate	O
support	O
from	O
the	O
operating	B-General_Concept
system	I-General_Concept
,	O
tagging	O
can	O
also	O
be	O
used	O
to	O
detect	O
buffer	B-General_Concept
overflows	I-General_Concept
.	O
</s>
<s>
An	O
example	O
is	O
the	O
NX	B-General_Concept
bit	I-General_Concept
hardware	O
feature	O
,	O
supported	O
by	O
Intel	O
,	O
AMD	O
and	O
ARM	B-Architecture
processors	I-Architecture
.	O
</s>
<s>
Stack-smashing	O
protection	O
was	O
first	O
implemented	O
by	O
StackGuard	B-Error_Name
in	O
1997	O
,	O
and	O
published	O
at	O
the	O
1998	O
USENIX	B-Operating_System
Security	I-Operating_System
Symposium	I-Operating_System
.	O
</s>
<s>
StackGuard	B-Error_Name
was	O
introduced	O
as	O
a	O
set	O
of	O
patches	O
to	O
the	O
Intel	B-Operating_System
x86	I-Operating_System
backend	O
of	O
GCC	B-Application
2.7	O
.	O
</s>
<s>
StackGuard	B-Error_Name
was	O
maintained	O
for	O
the	O
Immunix	O
Linux	O
distribution	O
from	O
1998	O
to	O
2003	O
,	O
and	O
was	O
extended	O
with	O
implementations	O
for	O
terminator	O
,	O
random	O
and	O
random	O
XOR	B-Application
canaries	O
.	O
</s>
<s>
StackGuard	B-Error_Name
was	O
suggested	O
for	O
inclusion	O
in	O
GCC	B-Application
3.x	O
at	O
the	O
GCC	B-Application
2003	O
Summit	O
Proceedings	O
,	O
but	O
this	O
was	O
never	O
achieved	O
.	O
</s>
<s>
From	O
2001	O
to	O
2005	O
,	O
IBM	O
developed	O
GCC	B-Application
patches	O
for	O
stack-smashing	O
protection	O
,	O
known	O
as	O
ProPolice	O
.	O
</s>
<s>
It	O
improved	O
on	O
the	O
idea	O
of	O
StackGuard	B-Error_Name
by	O
placing	O
buffers	O
after	O
local	O
pointers	O
and	O
function	O
arguments	O
in	O
the	O
stack	B-General_Concept
frame	O
.	O
</s>
<s>
Red	O
Hat	O
engineers	O
identified	O
problems	O
with	O
ProPolice	O
though	O
,	O
and	O
in	O
2005	O
re-implemented	O
stack-smashing	O
protection	O
for	O
inclusion	O
in	O
GCC	B-Application
4.1	O
.	O
</s>
<s>
In	O
2012	O
,	O
Google	B-Application
engineers	O
implemented	O
the	O
-fstack-protector-strong	O
flag	O
to	O
strike	O
a	O
better	O
balance	O
between	O
security	O
and	O
performance	O
.	O
</s>
<s>
It	O
is	O
available	O
in	O
GCC	B-Application
since	O
its	O
version	O
4.9	O
.	O
</s>
<s>
Most	O
packages	O
in	O
Ubuntu	B-Operating_System
are	O
compiled	O
with	O
-fstack-protector	O
since	O
6.10	O
.	O
</s>
<s>
Stack	B-Error_Name
protection	I-Error_Name
is	O
only	O
used	O
for	O
some	O
packages	O
in	O
Debian	O
,	O
and	O
only	O
for	O
the	O
FreeBSD	B-Operating_System
base	O
system	O
since	O
8.0	O
.	O
</s>
<s>
Stack	B-Error_Name
protection	I-Error_Name
is	O
standard	O
in	O
certain	O
operating	B-General_Concept
systems	I-General_Concept
,	O
including	O
OpenBSD	B-Operating_System
,	O
Hardened	O
Gentoo	O
and	O
DragonFly	B-Application
BSD	I-Application
.	O
</s>
<s>
StackGuard	B-Error_Name
and	O
ProPolice	O
cannot	O
protect	O
against	O
overflows	O
in	O
automatically	O
allocated	O
structures	O
that	O
overflow	O
into	O
function	O
pointers	O
.	O
</s>
<s>
The	O
compiler	O
suite	O
from	O
Microsoft	O
implements	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
since	O
version	O
2003	O
through	O
the	O
command-line	O
switch	O
,	O
which	O
is	O
enabled	O
by	O
default	O
since	O
version	O
2005	O
.	O
</s>
<s>
Stack-smashing	O
protection	O
can	O
be	O
turned	O
on	O
by	O
the	O
compiler	O
flag	O
-qstackprotect	O
.	O
</s>
<s>
Clang	O
supports	O
the	O
same	O
-fstack-protector	O
options	O
as	O
GCC	B-Application
and	O
a	O
stronger	O
"	O
safe	O
stack	B-General_Concept
"	O
(	O
)	O
system	O
with	O
similarly	O
low	O
performance	O
impact	O
.	O
</s>
<s>
Clang	O
also	O
has	O
three	O
buffer	B-General_Concept
overflow	I-General_Concept
detectors	O
,	O
namely	O
AddressSanitizer	B-Application
(	O
-fsanitize	O
=	O
address	O
)	O
,	O
UBSan	O
(	O
-fsanitize	O
=	O
bounds	O
)	O
,	O
</s>
<s>
and	O
the	O
unofficial	O
SafeCode	O
(	O
last	O
updated	O
for	O
LLVM	B-Application
3.0	O
)	O
.	O
</s>
<s>
Stack	B-Error_Name
protection	I-Error_Name
is	O
standard	O
in	O
certain	O
operating	B-General_Concept
systems	I-General_Concept
,	O
including	O
OpenBSD	B-Operating_System
.	O
</s>
<s>
Intel	O
's	O
C	B-Language
and	O
C++	O
compiler	O
supports	O
stack-smashing	O
protection	O
with	O
options	O
similar	O
to	O
those	O
provided	O
by	O
GCC	B-Application
and	O
Microsoft	B-Application
Visual	I-Application
Studio	I-Application
.	O
</s>
<s>
Fail-Safe	O
C	B-Language
is	O
an	O
open-source	O
memory-safe	O
ANSI	O
C	B-Language
compiler	O
that	O
performs	O
bounds	B-Data_Structure
checking	I-Data_Structure
based	O
on	O
fat	O
pointers	O
and	O
object-oriented	O
memory	O
access	O
.	O
</s>
<s>
Invented	O
by	O
Mike	O
Frantzen	O
,	O
StackGhost	O
is	O
a	O
simple	O
tweak	O
to	O
the	O
register	O
window	O
spill/fill	O
routines	O
which	O
makes	O
buffer	B-General_Concept
overflows	I-General_Concept
much	O
more	O
difficult	O
to	O
exploit	O
.	O
</s>
<s>
It	O
uses	O
a	O
unique	O
hardware	O
feature	O
of	O
the	O
Sun	O
Microsystems	O
SPARC	B-Architecture
architecture	O
(	O
that	O
being	O
:	O
deferred	O
on-stack	O
in-frame	O
register	O
window	O
spill/fill	O
)	O
to	O
detect	O
modifications	O
of	O
return	B-General_Concept
pointers	I-General_Concept
(	O
a	O
common	O
way	O
for	O
an	O
exploit	O
to	O
hijack	O
execution	O
paths	O
)	O
transparently	O
,	O
automatically	O
protecting	O
all	O
applications	O
without	O
requiring	O
binary	O
or	O
source	O
modifications	O
.	O
</s>
<s>
The	O
resulting	O
gdb	B-Language
issues	O
were	O
resolved	O
by	O
Mark	O
Kettenis	O
two	O
years	O
later	O
,	O
allowing	O
enabling	O
of	O
the	O
feature	O
.	O
</s>
<s>
Following	O
this	O
event	O
,	O
the	O
StackGhost	O
code	O
was	O
integrated	O
(	O
and	O
optimized	O
)	O
into	O
OpenBSD/SPARC	O
.	O
</s>
<s>
Normal	O
buffer	O
allocation	O
for	O
x86	B-Operating_System
architectures	I-Operating_System
and	O
other	O
similar	O
architectures	O
is	O
shown	O
in	O
the	O
buffer	B-General_Concept
overflow	I-General_Concept
entry	O
.	O
</s>
<s>
Here	O
,	O
we	O
will	O
show	O
the	O
modified	O
process	O
as	O
it	O
pertains	O
to	O
StackGuard	B-Error_Name
.	O
</s>
<s>
When	O
a	O
function	O
is	O
called	O
,	O
a	O
stack	B-General_Concept
frame	O
is	O
created	O
.	O
</s>
<s>
A	O
stack	B-General_Concept
frame	O
is	O
built	O
from	O
the	O
end	O
of	O
memory	O
to	O
the	O
beginning	O
;	O
and	O
each	O
stack	B-General_Concept
frame	O
is	O
placed	O
on	O
the	O
top	O
of	O
the	O
stack	B-General_Concept
,	O
closest	O
to	O
the	O
beginning	O
of	O
memory	O
.	O
</s>
<s>
Thus	O
,	O
running	O
off	O
the	O
end	O
of	O
a	O
piece	O
of	O
data	O
in	O
a	O
stack	B-General_Concept
frame	O
alters	O
data	O
previously	O
entered	O
into	O
the	O
stack	B-General_Concept
frame	O
;	O
and	O
running	O
off	O
the	O
end	O
of	O
a	O
stack	B-General_Concept
frame	O
places	O
data	O
into	O
the	O
previous	O
stack	B-General_Concept
frame	O
.	O
</s>
<s>
A	O
typical	O
stack	B-General_Concept
frame	O
may	O
look	O
as	O
below	O
,	O
having	O
a	O
return	B-Language
address	I-Language
(	O
RETA	O
)	O
placed	O
first	O
,	O
followed	O
by	O
other	O
control	O
information	O
(	O
CTLI	O
)	O
.	O
</s>
<s>
In	O
C	B-Language
,	O
a	O
function	O
may	O
contain	O
many	O
different	O
per-call	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
Each	O
piece	O
of	O
data	O
created	O
on	O
call	O
is	O
placed	O
in	O
the	O
stack	B-General_Concept
frame	O
in	O
order	O
,	O
and	O
is	O
thus	O
ordered	O
from	O
the	O
end	O
to	O
the	O
beginning	O
of	O
memory	O
.	O
</s>
<s>
Below	O
is	O
a	O
hypothetical	O
function	O
and	O
its	O
stack	B-General_Concept
frame	O
.	O
</s>
<s>
In	O
this	O
hypothetical	O
situation	O
,	O
if	O
more	O
than	O
ten	O
bytes	O
are	O
written	O
to	O
the	O
array	O
,	O
or	O
more	O
than	O
13	O
to	O
the	O
character	O
array	O
,	O
the	O
excess	O
will	O
overflow	O
into	O
integer	O
pointer	O
,	O
then	O
into	O
integer	O
,	O
then	O
into	O
the	O
control	O
information	O
,	O
and	O
finally	O
the	O
return	B-Language
address	I-Language
.	O
</s>
<s>
By	O
overwriting	O
RETA	O
,	O
the	O
function	O
can	O
be	O
made	O
to	O
execute	O
other	O
code	O
(	O
when	O
it	O
attempts	O
to	O
return	O
)	O
,	O
either	O
existing	O
functions	O
(	O
ret2libc	B-Language
)	O
or	O
code	O
written	O
into	O
the	O
stack	B-General_Concept
during	O
the	O
overflow	O
.	O
</s>
<s>
The	O
goal	O
of	O
buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
is	O
to	O
detect	O
this	O
issue	O
in	O
the	O
least	O
intrusive	O
way	O
possible	O
.	O
</s>
<s>
Buffer	B-Error_Name
overflow	I-Error_Name
protection	I-Error_Name
is	O
implemented	O
as	O
a	O
change	O
to	O
the	O
compiler	O
.	O
</s>
<s>
As	O
such	O
,	O
it	O
is	O
possible	O
for	O
the	O
protection	O
to	O
alter	O
the	O
structure	B-General_Concept
of	O
the	O
data	O
on	O
the	O
stack	B-General_Concept
frame	O
.	O
</s>
<s>
The	O
above	O
function	O
's	O
automatic	O
variables	O
are	O
rearranged	O
more	O
safely	O
:	O
arrays	O
and	O
are	O
allocated	O
first	O
in	O
the	O
stack	B-General_Concept
frame	O
,	O
which	O
places	O
integer	O
and	O
integer	O
pointer	O
before	O
them	O
in	O
memory	O
.	O
</s>
<s>
An	O
extra	O
piece	O
of	O
information	O
,	O
called	O
a	O
"	O
canary	O
"	O
(	O
CNRY	O
)	O
,	O
is	O
placed	O
after	O
the	O
buffers	O
in	O
the	O
stack	B-General_Concept
frame	O
.	O
</s>
<s>
The	O
canary	O
technique	O
adds	O
a	O
few	O
instructions	O
of	O
overhead	O
for	O
every	O
function	O
call	O
with	O
an	O
automatic	O
array	O
,	O
immediately	O
before	O
all	O
dynamic	O
buffer	O
allocation	O
and	O
after	O
dynamic	O
buffer	O
deallocation	B-General_Concept
.	O
</s>
