<s>
In	O
computing	O
,	O
ioctl	B-Operating_System
(	O
an	O
abbreviation	O
of	O
input/output	B-General_Concept
control	O
)	O
is	O
a	O
system	B-Operating_System
call	I-Operating_System
for	O
device-specific	O
input/output	B-General_Concept
operations	O
and	O
other	O
operations	O
which	O
cannot	O
be	O
expressed	O
by	O
regular	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
For	O
instance	O
,	O
a	O
CD-ROM	O
device	B-Application
driver	I-Application
which	O
can	O
instruct	O
a	O
physical	O
device	O
to	O
eject	O
a	O
disc	O
would	O
provide	O
an	O
ioctl	B-Operating_System
request	O
code	O
to	O
do	O
so	O
.	O
</s>
<s>
Device-independent	O
request	O
codes	O
are	O
sometimes	O
used	O
to	O
give	O
userspace	B-Operating_System
access	O
to	O
kernel	B-Operating_System
functions	O
which	O
are	O
only	O
used	O
by	O
core	O
system	B-Application
software	I-Application
or	O
still	O
under	O
development	O
.	O
</s>
<s>
The	O
ioctl	B-Operating_System
system	B-Operating_System
call	I-Operating_System
first	O
appeared	O
in	O
Version	B-Operating_System
7	I-Operating_System
of	O
Unix	B-Application
under	O
that	O
name	O
.	O
</s>
<s>
It	O
is	O
supported	O
by	O
most	O
Unix	B-Application
and	O
Unix-like	B-Operating_System
systems	I-Operating_System
,	O
including	O
Linux	B-Application
and	O
macOS	B-Application
,	O
though	O
the	O
available	O
request	O
codes	O
differ	O
from	O
system	O
to	O
system	O
.	O
</s>
<s>
Microsoft	B-Application
Windows	I-Application
provides	O
a	O
similar	O
function	O
,	O
named	O
"	O
DeviceIoControl	O
"	O
,	O
in	O
its	O
Win32	B-Library
API	I-Library
.	O
</s>
<s>
Conventional	O
operating	O
systems	O
can	O
be	O
divided	O
into	O
two	O
layers	O
,	O
userspace	B-Operating_System
and	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
Application	O
code	O
such	O
as	O
a	O
text	B-Application
editor	I-Application
resides	O
in	O
userspace	B-Operating_System
,	O
while	O
the	O
underlying	O
facilities	O
of	O
the	O
operating	O
system	O
,	O
such	O
as	O
the	O
network	B-Protocol
stack	I-Protocol
,	O
reside	O
in	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
Kernel	B-Operating_System
code	O
handles	O
sensitive	O
resources	O
and	O
implements	O
the	O
security	O
and	O
reliability	O
barriers	O
between	O
applications	O
;	O
for	O
this	O
reason	O
,	O
user	B-Operating_System
mode	I-Operating_System
applications	O
are	O
prevented	O
by	O
the	O
operating	O
system	O
from	O
directly	O
accessing	O
kernel	B-Operating_System
resources	O
.	O
</s>
<s>
Userspace	B-Operating_System
applications	O
typically	O
make	O
requests	O
to	O
the	O
kernel	B-Operating_System
by	O
means	O
of	O
system	B-Operating_System
calls	I-Operating_System
,	O
whose	O
code	O
lies	O
in	O
the	O
kernel	B-Operating_System
layer	O
.	O
</s>
<s>
A	O
system	B-Operating_System
call	I-Operating_System
usually	O
takes	O
the	O
form	O
of	O
a	O
"	O
system	B-Operating_System
call	I-Operating_System
vector	O
"	O
,	O
in	O
which	O
the	O
desired	O
system	B-Operating_System
call	I-Operating_System
is	O
indicated	O
with	O
an	O
index	O
number	O
.	O
</s>
<s>
For	O
instance	O
,	O
exit( )	O
might	O
be	O
system	B-Operating_System
call	I-Operating_System
number	O
1	O
,	O
and	O
write( )	O
number	O
4	O
.	O
</s>
<s>
The	O
system	B-Operating_System
call	I-Operating_System
vector	O
is	O
then	O
used	O
to	O
find	O
the	O
desired	O
kernel	B-Operating_System
function	O
for	O
the	O
request	O
.	O
</s>
<s>
In	O
this	O
way	O
,	O
conventional	O
operating	O
systems	O
typically	O
provide	O
several	O
hundred	O
system	B-Operating_System
calls	I-Operating_System
to	O
the	O
userspace	B-Operating_System
.	O
</s>
<s>
Though	O
an	O
expedient	O
design	O
for	O
accessing	O
standard	O
kernel	B-Operating_System
facilities	O
,	O
system	B-Operating_System
calls	I-Operating_System
are	O
sometimes	O
inappropriate	O
for	O
accessing	O
non-standard	O
hardware	O
peripherals	O
.	O
</s>
<s>
By	O
necessity	O
,	O
most	O
hardware	O
peripherals	O
(	O
aka	O
devices	O
)	O
are	O
directly	O
addressable	O
only	O
within	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
Some	O
of	O
these	O
facilities	O
may	O
not	O
be	O
foreseen	O
by	O
the	O
kernel	B-Operating_System
designer	O
,	O
and	O
as	O
a	O
consequence	O
it	O
is	O
difficult	O
for	O
a	O
kernel	B-Operating_System
to	O
provide	O
system	B-Operating_System
calls	I-Operating_System
for	O
using	O
the	O
devices	O
.	O
</s>
<s>
To	O
solve	O
this	O
problem	O
,	O
the	O
kernel	B-Operating_System
is	O
designed	O
to	O
be	O
extensible	O
,	O
and	O
may	O
accept	O
an	O
extra	O
module	B-Application
called	O
a	O
device	B-Application
driver	I-Application
which	O
runs	O
in	O
kernel	B-Operating_System
space	I-Operating_System
and	O
can	O
directly	O
address	O
the	O
device	O
.	O
</s>
<s>
An	O
ioctl	B-Operating_System
interface	O
is	O
a	O
single	O
system	B-Operating_System
call	I-Operating_System
by	O
which	O
userspace	B-Operating_System
may	O
communicate	O
with	O
device	B-Application
drivers	I-Application
.	O
</s>
<s>
Requests	O
on	O
a	O
device	B-Application
driver	I-Application
are	O
vectored	O
with	O
respect	O
to	O
this	O
ioctl	B-Operating_System
system	B-Operating_System
call	I-Operating_System
,	O
typically	O
by	O
a	O
handle	O
to	O
the	O
device	O
and	O
a	O
request	O
number	O
.	O
</s>
<s>
The	O
basic	O
kernel	B-Operating_System
can	O
thus	O
allow	O
the	O
userspace	B-Operating_System
to	O
access	O
a	O
device	B-Application
driver	I-Application
without	O
knowing	O
anything	O
about	O
the	O
facilities	O
supported	O
by	O
the	O
device	O
,	O
and	O
without	O
needing	O
an	O
unmanageably	O
large	O
collection	O
of	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
A	O
common	O
use	O
of	O
ioctl	B-Operating_System
is	O
to	O
control	O
hardware	O
devices	O
.	O
</s>
<s>
For	O
example	O
,	O
on	O
Win32	B-Library
systems	O
,	O
ioctl	B-Operating_System
calls	O
can	O
communicate	O
with	O
USB	B-Protocol
devices	O
,	O
or	O
they	O
can	O
discover	O
drive-geometry	O
information	O
of	O
the	O
attached	O
storage-devices	O
.	O
</s>
<s>
On	O
OpenBSD	B-Operating_System
and	O
NetBSD	B-Device
,	O
ioctl	B-Operating_System
is	O
used	O
by	O
the	O
pseudo-device	O
driver	O
and	O
the	O
bioctl	B-Device
utility	O
to	O
implement	O
RAID	B-Architecture
volume	O
management	O
in	O
a	O
unified	O
vendor-agnostic	O
interface	O
similar	O
to	O
ifconfig	B-Protocol
.	O
</s>
<s>
On	O
NetBSD	B-Device
,	O
ioctl	B-Operating_System
is	O
also	O
used	O
by	O
the	O
sysmon	B-Device
framework	O
.	O
</s>
<s>
One	O
use	O
of	O
ioctl	B-Operating_System
in	O
code	O
exposed	O
to	O
end-user	O
applications	O
is	O
terminal	O
I/O	B-General_Concept
.	O
</s>
<s>
Unix	B-Application
operating	I-Application
systems	I-Application
have	O
traditionally	O
made	O
heavy	O
use	O
of	O
command-line	B-Application
interfaces	I-Application
.	O
</s>
<s>
The	O
Unix	B-Application
command-line	B-Application
interface	I-Application
is	O
built	O
on	O
pseudo	B-Protocol
terminals	I-Protocol
(	O
ptys	O
)	O
,	O
which	O
emulate	O
hardware	O
text	O
terminals	O
such	O
as	O
VT100s	B-Device
.	O
</s>
<s>
A	O
pty	O
is	O
controlled	O
and	O
configured	O
as	O
if	O
it	O
were	O
a	O
hardware	O
device	O
,	O
using	O
ioctl	B-Operating_System
calls	O
.	O
</s>
<s>
The	O
TIOCSTI	O
(	O
terminal	O
I/O	B-General_Concept
control	O
,	O
simulate	O
terminal	O
input	O
)	O
ioctl	B-Operating_System
function	O
can	O
push	O
a	O
character	O
into	O
a	O
device	O
stream	O
.	O
</s>
<s>
When	O
applications	O
need	O
to	O
extend	O
the	O
kernel	B-Operating_System
,	O
for	O
instance	O
to	O
accelerate	O
network	O
processing	O
,	O
ioctl	B-Operating_System
calls	O
provide	O
a	O
convenient	O
way	O
to	O
bridge	O
userspace	B-Operating_System
code	O
to	O
kernel	B-Application
extensions	I-Application
.	O
</s>
<s>
Kernel	B-Application
extensions	I-Application
can	O
provide	O
a	O
location	O
in	O
the	O
filesystem	O
that	O
can	O
be	O
opened	O
by	O
name	O
,	O
through	O
which	O
an	O
arbitrary	O
number	O
of	O
ioctl	B-Operating_System
calls	O
can	O
be	O
dispatched	O
,	O
allowing	O
the	O
extension	O
to	O
be	O
programmed	O
without	O
adding	O
system	B-Operating_System
calls	I-Operating_System
to	O
the	O
operating	O
system	O
.	O
</s>
<s>
According	O
to	O
an	O
OpenBSD	B-Operating_System
developer	O
,	O
ioctl	B-Operating_System
and	O
sysctl	B-Application
are	O
the	O
two	O
system	B-Operating_System
calls	I-Operating_System
for	O
extending	O
the	O
kernel	B-Operating_System
,	O
with	O
sysctl	B-Application
possibly	O
being	O
the	O
simpler	O
of	O
the	O
two	O
.	O
</s>
<s>
In	O
NetBSD	B-Device
,	O
the	O
sysmon_envsys	O
framework	O
for	O
hardware	B-Application
monitoring	I-Application
uses	O
ioctl	B-Operating_System
through	O
proplib	B-Application
;	O
whereas	O
OpenBSD	B-Operating_System
and	O
DragonFly	B-Application
BSD	I-Application
instead	O
use	O
sysctl	B-Application
for	O
their	O
corresponding	O
hw.sensors	B-Application
framework	O
.	O
</s>
<s>
The	O
original	O
revision	O
of	O
envsys	B-Device
in	O
NetBSD	B-Device
was	O
implemented	O
with	O
ioctl	B-Operating_System
before	O
proplib	B-Application
was	O
available	O
,	O
and	O
had	O
a	O
message	O
suggesting	O
that	O
the	O
framework	O
is	O
experimental	O
,	O
and	O
should	O
be	O
replaced	O
by	O
a	O
sysctl(8 )	O
interface	O
,	O
should	O
one	O
be	O
developed	O
,	O
which	O
potentially	O
explains	O
the	O
choice	O
of	O
sysctl	B-Application
in	O
OpenBSD	B-Operating_System
with	O
its	O
subsequent	O
introduction	O
of	O
hw.sensors	B-Application
in	O
2003	O
.	O
</s>
<s>
However	O
,	O
when	O
the	O
envsys	B-Device
framework	O
was	O
redesigned	O
in	O
2007	O
around	O
proplib	B-Application
,	O
the	O
system	B-Operating_System
call	I-Operating_System
remained	O
as	O
ioctl	B-Operating_System
,	O
and	O
the	O
message	O
was	O
removed	O
.	O
</s>
<s>
The	O
ioctl	B-Operating_System
system	B-Operating_System
call	I-Operating_System
first	O
appeared	O
in	O
Version	B-Operating_System
7	I-Operating_System
Unix	I-Operating_System
,	O
as	O
a	O
renamed	O
stty	O
.	O
</s>
<s>
An	O
ioctl	B-Operating_System
call	O
takes	O
as	O
parameters	O
:	O
</s>
<s>
The	O
kernel	B-Operating_System
generally	O
dispatches	O
an	O
ioctl	B-Operating_System
call	O
straight	O
to	O
the	O
device	B-Application
driver	I-Application
,	O
which	O
can	O
interpret	O
the	O
request	O
number	O
and	O
data	O
in	O
whatever	O
way	O
required	O
.	O
</s>
<s>
The	O
writers	O
of	O
each	O
driver	O
document	O
request	O
numbers	O
for	O
that	O
particular	O
driver	O
and	O
provide	O
them	O
as	O
constants	O
in	O
a	O
header	B-Language
file	I-Language
.	O
</s>
<s>
Some	O
Unix	B-Application
systems	I-Application
,	O
including	O
Linux	B-Application
,	O
have	O
conventions	O
which	O
encode	O
within	O
the	O
request	O
number	O
the	O
size	O
of	O
the	O
data	O
to	O
be	O
transferred	O
to/from	O
the	O
device	B-Application
driver	I-Application
,	O
the	O
direction	O
of	O
the	O
data	O
transfer	O
and	O
the	O
identity	O
of	O
the	O
driver	O
implementing	O
the	O
request	O
.	O
</s>
<s>
Regardless	O
of	O
whether	O
such	O
a	O
convention	O
is	O
followed	O
,	O
the	O
kernel	B-Operating_System
and	O
the	O
driver	O
collaborate	O
to	O
deliver	O
a	O
uniform	O
error	O
code	O
(	O
denoted	O
by	O
the	O
symbolic	O
constant	O
ENOTTY	B-Error_Name
)	O
to	O
an	O
application	O
which	O
makes	O
a	O
request	O
of	O
a	O
driver	O
which	O
does	O
not	O
recognise	O
it	O
.	O
</s>
<s>
The	O
mnemonic	O
ENOTTY	B-Error_Name
(	O
traditionally	O
associated	O
with	O
the	O
textual	O
message	O
"	O
Not	B-Error_Name
a	I-Error_Name
typewriter	I-Error_Name
"	O
)	O
derives	O
from	O
the	O
earliest	O
systems	O
that	O
incorporated	O
an	O
ioctl	B-Operating_System
call	O
,	O
where	O
only	O
the	O
teletype	O
(	O
tty	O
)	O
device	O
raised	O
this	O
error	O
.	O
</s>
<s>
Though	O
the	O
symbolic	O
mnemonic	O
is	O
fixed	O
by	O
compatibility	O
requirements	O
,	O
some	O
modern	O
systems	O
more	O
helpfully	O
render	O
a	O
more	O
general	O
message	O
such	O
as	O
"	O
Inappropriate	O
device	O
control	O
operation	O
"	O
(	O
or	O
a	O
localization	B-General_Concept
thereof	O
)	O
.	O
</s>
<s>
TCSETS	O
exemplifies	O
an	O
ioctl	B-Operating_System
call	O
on	O
a	O
serial	B-Protocol
port	I-Protocol
.	O
</s>
<s>
The	O
normal	O
read	O
and	O
write	O
calls	O
on	O
a	O
serial	B-Protocol
port	I-Protocol
receive	O
and	O
send	O
data	O
bytes	O
.	O
</s>
<s>
An	O
ioctl(fd,TCSETS,data )	O
call	O
,	O
separate	O
from	O
such	O
normal	O
I/O	B-General_Concept
,	O
controls	O
various	O
driver	O
options	O
like	O
handling	O
of	O
special	O
characters	O
,	O
or	O
the	O
output	O
signals	O
on	O
the	O
port	O
(	O
such	O
as	O
the	O
DTR	O
signal	O
)	O
.	O
</s>
<s>
A	O
Win32	B-Library
DeviceIoControl	O
takes	O
as	O
parameters	O
:	O
</s>
<s>
an	O
OVERLAPPED	O
structure	O
,	O
if	O
overlapped	B-Operating_System
I/O	I-Operating_System
is	O
being	O
used	O
.	O
</s>
<s>
The	O
Win32	B-Library
device	O
control	O
code	O
takes	O
into	O
consideration	O
the	O
mode	O
of	O
the	O
operation	O
being	O
performed	O
.	O
</s>
<s>
METHOD_IN_DIRECT	O
:	O
The	O
buffer	O
address	O
is	O
verified	O
to	O
be	O
readable	O
by	O
the	O
user	B-Operating_System
mode	I-Operating_System
caller	O
.	O
</s>
<s>
METHOD_OUT_DIRECT	O
:	O
The	O
buffer	O
address	O
is	O
verified	O
to	O
be	O
writable	O
by	O
the	O
user	B-Operating_System
mode	I-Operating_System
caller	O
.	O
</s>
<s>
METHOD_NEITHER	O
:	O
User	B-Operating_System
mode	I-Operating_System
virtual	O
addresses	O
are	O
passed	O
to	O
the	O
driver	O
without	O
mapping	O
or	O
validation	O
.	O
</s>
<s>
METHOD_BUFFERED	O
:	O
IO	O
Manager	O
controlled	O
shared	O
buffers	O
are	O
used	O
to	O
move	O
data	O
to	O
and	O
from	O
user	B-Operating_System
mode	I-Operating_System
.	O
</s>
<s>
Devices	O
and	O
kernel	B-Application
extensions	I-Application
may	O
be	O
linked	O
to	O
userspace	B-Operating_System
using	O
additional	O
new	O
system	B-Operating_System
calls	I-Operating_System
,	O
although	O
this	O
approach	O
is	O
rarely	O
taken	O
,	O
because	O
operating	O
system	O
developers	O
try	O
to	O
keep	O
the	O
system	B-Operating_System
call	I-Operating_System
interface	O
focused	O
and	O
efficient	O
.	O
</s>
<s>
On	O
Unix	B-Application
operating	I-Application
systems	I-Application
,	O
two	O
other	O
vectored	O
call	O
interfaces	O
are	O
popular	O
:	O
the	O
fcntl	B-Application
(	O
"	O
file	O
control	O
"	O
)	O
system	B-Operating_System
call	I-Operating_System
configures	O
open	O
files	O
,	O
and	O
is	O
used	O
in	O
situations	O
such	O
as	O
enabling	O
non-blocking	B-Architecture
I/O	I-Architecture
;	O
and	O
the	O
setsockopt	O
(	O
"	O
set	O
socket	O
option	O
"	O
)	O
system	B-Operating_System
call	I-Operating_System
configures	O
open	O
network	B-Protocol
sockets	I-Protocol
,	O
a	O
facility	O
used	O
to	O
configure	O
the	O
ipfw	B-Protocol
packet	O
firewall	O
on	O
BSD	B-Operating_System
Unix	I-Operating_System
systems	O
.	O
</s>
<s>
Unix	B-Application
Device	O
interfaces	O
and	O
input/output	B-General_Concept
capabilities	O
are	O
sometimes	O
provided	O
using	O
memory-mapped	B-General_Concept
files	I-General_Concept
.	O
</s>
<s>
Applications	O
that	O
interact	O
with	O
devices	O
open	O
a	O
location	O
on	O
the	O
filesystem	O
corresponding	O
to	O
the	O
device	O
,	O
as	O
they	O
would	O
for	O
an	O
ioctl	B-Operating_System
call	O
,	O
but	O
then	O
use	O
memory	O
mapping	O
system	B-Operating_System
calls	I-Operating_System
to	O
tie	O
a	O
portion	O
of	O
their	O
address	O
space	O
to	O
that	O
of	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
This	O
interface	O
is	O
a	O
far	O
more	O
efficient	O
way	O
to	O
provide	O
bulk	O
data	O
transfer	O
between	O
a	O
device	O
and	O
a	O
userspace	B-Operating_System
application	O
;	O
individual	O
ioctl	B-Operating_System
or	O
read/write	O
system	B-Operating_System
calls	I-Operating_System
inflict	O
overhead	O
due	O
to	O
repeated	O
userspace-to-kernel	O
transitions	O
,	O
where	O
access	O
to	O
a	O
memory-mapped	O
range	O
of	O
addresses	O
incurs	O
no	O
such	O
overhead	O
.	O
</s>
<s>
Win32	B-Library
Buffered	O
IO	O
methods	O
or	O
named	O
file	O
mapping	O
objects	O
can	O
be	O
used	O
;	O
however	O
,	O
for	O
simple	O
device	B-Application
drivers	I-Application
the	O
standard	O
DeviceIoControl	O
METHOD_	O
accesses	O
are	O
sufficient	O
.	O
</s>
<s>
Netlink	B-Application
is	O
a	O
socket-like	O
mechanism	O
for	O
inter-process	B-Operating_System
communication	I-Operating_System
(	O
IPC	O
)	O
,	O
designed	O
to	O
be	O
a	O
more	O
flexible	O
successor	O
to	O
ioctl	B-Operating_System
.	O
</s>
<s>
ioctl	B-Operating_System
calls	O
minimize	O
the	O
complexity	O
of	O
the	O
kernel	B-Operating_System
's	O
system	B-Operating_System
call	I-Operating_System
interface	O
.	O
</s>
<s>
However	O
,	O
by	O
providing	O
a	O
place	O
for	O
developers	O
to	O
"	O
stash	O
"	O
bits	O
and	O
pieces	O
of	O
kernel	B-Operating_System
programming	O
interfaces	O
,	O
ioctl	B-Operating_System
calls	O
complicate	O
the	O
overall	O
user-to-kernel	O
API	O
.	O
</s>
<s>
A	O
kernel	B-Operating_System
that	O
provides	O
several	O
hundred	O
system	B-Operating_System
calls	I-Operating_System
may	O
provide	O
several	O
thousand	O
ioctl	B-Operating_System
calls	O
.	O
</s>
<s>
Though	O
the	O
interface	O
to	O
ioctl	B-Operating_System
calls	O
appears	O
somewhat	O
different	O
from	O
conventional	O
system	B-Operating_System
calls	I-Operating_System
,	O
there	O
is	O
in	O
practice	O
little	O
difference	O
between	O
an	O
ioctl	B-Operating_System
call	O
and	O
a	O
system	B-Operating_System
call	I-Operating_System
;	O
an	O
ioctl	B-Operating_System
call	O
is	O
simply	O
a	O
system	B-Operating_System
call	I-Operating_System
with	O
a	O
different	O
dispatching	O
mechanism	O
.	O
</s>
<s>
Many	O
of	O
the	O
arguments	O
against	O
expanding	O
the	O
kernel	B-Operating_System
system	B-Operating_System
call	I-Operating_System
interface	O
could	O
therefore	O
be	O
applied	O
to	O
ioctl	B-Operating_System
interfaces	O
.	O
</s>
<s>
To	O
application	O
developers	O
,	O
system	B-Operating_System
calls	I-Operating_System
appear	O
no	O
different	O
from	O
application	O
subroutines	O
;	O
they	O
are	O
simply	O
function	O
calls	O
that	O
take	O
arguments	O
and	O
return	O
values	O
.	O
</s>
<s>
The	O
runtime	B-Device
libraries	O
of	O
the	O
OS	O
mask	O
the	O
complexity	O
involved	O
in	O
invoking	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
Unfortunately	O
,	O
runtime	B-Device
libraries	O
do	O
not	O
make	O
ioctl	B-Operating_System
calls	O
as	O
transparent	O
.	O
</s>
<s>
Simple	O
operations	O
like	O
discovering	O
the	O
IP	B-Protocol
addresses	I-Protocol
for	O
a	O
machine	O
often	O
require	O
tangled	O
messes	O
of	O
ioctl	B-Operating_System
calls	O
,	O
each	O
requiring	O
magic	O
numbers	O
and	O
argument	O
structures	O
.	O
</s>
<s>
Libpcap	B-Language
and	O
libdnet	O
are	O
two	O
examples	O
of	O
third-party	O
wrapper	O
Unix	B-Application
libraries	O
designed	O
to	O
mask	O
the	O
complexity	O
of	O
ioctl	B-Operating_System
interfaces	O
,	O
for	O
packet	O
capture	O
and	O
packet	O
I/O	B-General_Concept
,	O
respectively	O
.	O
</s>
<s>
The	O
user-to-kernel	O
interfaces	O
of	O
mainstream	O
operating	O
systems	O
are	O
often	O
audited	O
heavily	O
for	O
code	O
flaws	O
and	O
security	O
vulnerabilities	O
prior	O
to	O
release	O
.	O
</s>
<s>
These	O
audits	O
typically	O
focus	O
on	O
the	O
well-documented	O
system	B-Operating_System
call	I-Operating_System
interfaces	O
;	O
for	O
instance	O
,	O
auditors	O
might	O
ensure	O
that	O
sensitive	O
security	O
calls	O
such	O
as	O
changing	O
user	O
IDs	O
are	O
only	O
available	O
to	O
administrative	O
users	O
.	O
</s>
<s>
ioctl	B-Operating_System
interfaces	O
are	O
more	O
complicated	O
,	O
more	O
diverse	O
,	O
and	O
thus	O
harder	O
to	O
audit	O
than	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
Furthermore	O
,	O
because	O
ioctl	B-Operating_System
calls	O
can	O
be	O
provided	O
by	O
third-party	O
developers	O
,	O
often	O
after	O
the	O
core	O
operating	O
system	O
has	O
been	O
released	O
,	O
ioctl	B-Operating_System
call	O
implementations	O
may	O
receive	O
less	O
scrutiny	O
and	O
thus	O
harbor	O
more	O
vulnerabilities	O
.	O
</s>
<s>
Finally	O
,	O
many	O
ioctl	B-Operating_System
calls	O
,	O
particularly	O
for	O
third-party	O
device	B-Application
drivers	I-Application
,	O
are	O
undocumented	O
.	O
</s>
<s>
Because	O
the	O
handler	O
for	O
an	O
ioctl	B-Operating_System
call	O
resides	O
directly	O
in	O
kernel	B-Operating_System
mode	O
,	O
the	O
input	O
from	O
userspace	B-Operating_System
should	O
be	O
validated	O
carefully	O
.	O
</s>
<s>
Vulnerabilities	O
in	O
device	B-Application
drivers	I-Application
can	O
be	O
exploited	O
by	O
local	O
users	O
by	O
passing	O
invalid	O
buffers	O
to	O
ioctl	B-Operating_System
calls	O
.	O
</s>
<s>
Win32	B-Library
and	O
Unix	B-Application
operating	I-Application
systems	I-Application
can	O
protect	O
a	O
userspace	B-Operating_System
device	O
name	O
from	O
access	O
by	O
applications	O
with	O
specific	O
access	O
controls	O
applied	O
to	O
the	O
device	O
.	O
</s>
<s>
Security	O
problems	O
can	O
arise	O
when	O
device	B-Application
driver	I-Application
developers	O
do	O
not	O
apply	O
appropriate	O
access	O
controls	O
to	O
the	O
userspace	B-Operating_System
accessible	O
object	O
.	O
</s>
<s>
Some	O
modern	O
operating	O
systems	O
protect	O
the	O
kernel	B-Operating_System
from	O
hostile	O
userspace	B-Operating_System
code	O
(	O
such	O
as	O
applications	O
that	O
have	O
been	O
infected	O
by	O
buffer	B-General_Concept
overflow	I-General_Concept
exploits	O
)	O
using	O
system	B-Operating_System
call	I-Operating_System
wrappers	O
.	O
</s>
<s>
System	B-Operating_System
call	I-Operating_System
wrappers	O
implement	O
role-based	O
access	O
control	O
by	O
specifying	O
which	O
system	B-Operating_System
calls	I-Operating_System
can	O
be	O
invoked	O
by	O
which	O
applications	O
;	O
wrappers	O
can	O
,	O
for	O
instance	O
,	O
be	O
used	O
to	O
"	O
revoke	O
"	O
the	O
right	O
of	O
a	O
mail	O
program	O
to	O
spawn	O
other	O
programs	O
.	O
</s>
<s>
ioctl	B-Operating_System
interfaces	O
complicate	O
system	B-Operating_System
call	I-Operating_System
wrappers	O
because	O
there	O
are	O
large	O
numbers	O
of	O
them	O
,	O
each	O
taking	O
different	O
arguments	O
,	O
some	O
of	O
which	O
may	O
be	O
required	O
by	O
normal	O
programs	O
.	O
</s>
