<s>
A	O
symlink	B-Operating_System
race	I-Operating_System
is	O
a	O
kind	O
of	O
software	O
security	O
vulnerability	O
that	O
results	O
from	O
a	O
program	O
creating	O
files	B-Operating_System
in	O
an	O
insecure	O
manner	O
.	O
</s>
<s>
A	O
malicious	O
user	O
can	O
create	O
a	O
symbolic	B-Application
link	I-Application
to	O
a	O
file	O
not	O
otherwise	O
accessible	O
to	O
them	O
.	O
</s>
<s>
When	O
the	O
privileged	O
program	O
creates	O
a	O
file	O
of	O
the	O
same	O
name	O
as	O
the	O
symbolic	B-Application
link	I-Application
,	O
it	O
actually	O
creates	O
the	O
linked-to	O
file	O
instead	O
,	O
possibly	O
inserting	O
content	O
desired	O
by	O
the	O
malicious	O
user	O
(	O
see	O
example	O
below	O
)	O
,	O
or	O
even	O
provided	O
by	O
the	O
malicious	O
user	O
(	O
as	O
input	O
to	O
the	O
program	O
)	O
.	O
</s>
<s>
It	O
is	O
called	O
a	O
"	O
race	B-Operating_System
"	O
because	O
in	O
its	O
typical	O
manifestation	O
,	O
the	O
program	O
checks	O
to	O
see	O
if	O
a	O
file	O
by	O
that	O
name	O
already	O
exists	O
;	O
if	O
it	O
does	O
not	O
exist	O
,	O
the	O
program	O
then	O
creates	O
the	O
file	O
.	O
</s>
<s>
An	O
attacker	O
must	O
create	O
the	O
link	O
in	O
the	O
interval	B-Error_Name
between	I-Error_Name
the	I-Error_Name
check	I-Error_Name
and	I-Error_Name
when	I-Error_Name
the	I-Error_Name
file	I-Error_Name
is	I-Error_Name
created	I-Error_Name
.	O
</s>
<s>
A	O
symlink	B-Operating_System
race	I-Operating_System
can	O
happen	O
with	O
antivirus	B-Application
products	O
that	O
decide	O
they	O
will	O
quarantine	O
or	O
delete	O
a	O
suspicious	O
file	O
,	O
and	O
then	O
go	O
ahead	O
and	O
do	O
that	O
.	O
</s>
<s>
During	O
the	O
interval	O
between	O
decision	O
and	O
action	O
,	O
malicious	O
software	O
can	O
replace	O
the	O
suspicious	O
file	O
with	O
a	O
system	O
or	O
antivirus	B-Application
file	O
that	O
the	O
malicious	O
software	O
wants	O
overwritten	O
.	O
</s>
<s>
In	O
this	O
naive	O
example	O
,	O
the	O
Unix	B-Application
program	O
foo	O
is	O
setuid	O
.	O
</s>
<s>
Malicious	O
user	O
Mallory	O
creates	O
a	O
symbolic	B-Application
link	I-Application
to	O
the	O
file	O
/root/.rhosts	O
named	O
/tmp/foo	O
.	O
</s>
<s>
It	O
removes	O
the	O
temporary	O
file	O
(	O
merely	O
removing	O
the	O
symbolic	B-Application
link	I-Application
)	O
.	O
</s>
<s>
Now	O
the	O
/root/.rhosts	O
contains	O
password	O
information	O
,	O
which	O
(	O
if	O
it	O
even	O
happens	O
to	O
be	O
in	O
the	O
proper	O
format	O
)	O
is	O
the	O
incantation	O
necessary	O
to	O
allow	O
anyone	O
to	O
use	O
rlogin	B-Application
to	O
log	O
into	O
the	O
computer	O
as	O
the	O
superuser	B-Application
.	O
</s>
<s>
Also	O
in	O
some	O
Unix-systems	O
there	O
is	O
a	O
special	O
flag	O
O_NOFOLLOW	O
for	O
open(2 )	O
to	O
prevent	O
opening	O
a	O
file	O
via	O
a	O
symbolic-link	O
(	O
dangling	O
or	O
otherwise	O
)	O
.	O
</s>
<s>
The	O
POSIX	O
C	B-Language
standard	I-Language
library	I-Language
function	O
mkstemp	B-Language
can	O
be	O
used	O
to	O
safely	O
create	O
temporary	O
files	B-Operating_System
.	O
</s>
