<s>
In	O
computing	O
,	O
a	O
loadable	B-Application
kernel	I-Application
module	I-Application
(	O
LKM	O
)	O
is	O
an	O
object	B-Application
file	I-Application
that	O
contains	O
code	O
to	O
extend	B-Architecture
the	O
running	O
kernel	B-Operating_System
,	O
or	O
so-called	O
base	O
kernel	B-Operating_System
,	O
of	O
an	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
LKMs	O
are	O
typically	O
used	O
to	O
add	O
support	O
for	O
new	O
hardware	B-Architecture
(	O
as	O
device	B-Application
drivers	I-Application
)	O
and/or	O
filesystems	B-Application
,	O
or	O
for	O
adding	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
When	O
the	O
functionality	O
provided	O
by	O
an	O
LKM	O
is	O
no	O
longer	O
required	O
,	O
it	O
can	O
be	O
unloaded	O
in	O
order	O
to	O
free	O
memory	B-Architecture
and	O
other	O
resources	O
.	O
</s>
<s>
Most	O
current	O
Unix-like	B-Operating_System
systems	I-Operating_System
and	O
Microsoft	B-Application
Windows	I-Application
support	O
loadable	B-Application
kernel	I-Application
modules	I-Application
under	O
different	O
names	O
,	O
such	O
as	O
kernel	B-Operating_System
loadable	O
module	B-Application
(	O
kld	O
)	O
in	O
FreeBSD	B-Operating_System
,	O
kernel	B-Application
extension	I-Application
(	O
kext	B-Application
)	O
in	O
macOS	B-Application
(	O
although	O
support	O
for	O
third-party	O
modules	B-Application
is	O
being	O
dropped	O
)	O
,	O
kernel	B-Application
extension	I-Application
module	B-Application
in	O
AIX	B-Application
,	O
dynamically	O
loadable	B-Application
kernel	I-Application
module	I-Application
in	O
HP-UX	B-Application
,	O
kernel-mode	O
driver	O
in	O
Windows	B-Device
NT	I-Device
and	O
downloadable	O
kernel	B-Application
module	I-Application
(	O
DKM	O
)	O
in	O
VxWorks	B-Operating_System
.	O
</s>
<s>
They	O
are	O
also	O
known	O
as	O
kernel	B-Operating_System
loadable	O
modules	B-Application
(	O
or	O
KLM	O
)	O
,	O
and	O
simply	O
as	O
kernel	B-Application
modules	I-Application
(	O
KMOD	O
)	O
.	O
</s>
<s>
Without	O
loadable	B-Application
kernel	I-Application
modules	I-Application
,	O
an	O
operating	B-General_Concept
system	I-General_Concept
would	O
have	O
to	O
include	O
all	O
possible	O
anticipated	O
functionality	O
compiled	O
directly	O
into	O
the	O
base	O
kernel	B-Operating_System
.	O
</s>
<s>
Much	O
of	O
that	O
functionality	O
would	O
reside	O
in	O
memory	B-Architecture
without	O
being	O
used	O
,	O
wasting	O
memory	B-Architecture
,	O
and	O
would	O
require	O
that	O
users	O
rebuild	O
and	O
reboot	O
the	O
base	O
kernel	B-Operating_System
every	O
time	O
they	O
require	O
new	O
functionality	O
.	O
</s>
<s>
One	O
minor	O
criticism	O
of	O
preferring	O
a	O
modular	B-Application
kernel	I-Application
over	O
a	O
static	O
kernel	B-Operating_System
is	O
the	O
so-called	O
fragmentation	B-Architecture
penalty	O
.	O
</s>
<s>
The	O
base	O
kernel	B-Operating_System
is	O
always	O
unpacked	O
into	O
real	O
contiguous	O
memory	B-Architecture
by	O
its	O
setup	O
routines	O
;	O
thus	O
,	O
the	O
base	O
kernel	B-Operating_System
code	O
is	O
never	O
fragmented	O
.	O
</s>
<s>
Once	O
the	O
system	O
is	O
in	O
a	O
state	O
in	O
which	O
modules	B-Application
may	O
be	O
inserted	O
,	O
for	O
example	O
once	O
the	O
filesystems	B-Application
have	O
been	O
mounted	O
that	O
contain	O
the	O
modules	B-Application
,	O
it	O
is	O
likely	O
that	O
any	O
new	O
kernel	B-Operating_System
code	O
insertion	O
will	O
cause	O
the	O
kernel	B-Operating_System
to	O
become	O
fragmented	O
,	O
thereby	O
introducing	O
a	O
minor	O
performance	O
penalty	O
by	O
using	O
more	O
TLB	B-Architecture
entries	O
,	O
causing	O
more	O
TLB	B-Architecture
misses	O
.	O
</s>
<s>
Loadable	B-Application
kernel	I-Application
modules	I-Application
in	O
Linux	O
are	O
loaded	O
(	O
and	O
unloaded	O
)	O
by	O
the	O
modprobe	B-Application
command	O
.	O
</s>
<s>
They	O
are	O
located	O
in	O
/lib/modules	O
or	O
/usr/lib/modules	O
and	O
have	O
had	O
the	O
extension	O
.ko	B-Application
(	O
"	O
kernel	B-Operating_System
object	O
"	O
)	O
since	O
version	O
2.6	O
(	O
previous	O
versions	O
used	O
the	O
.o	B-Application
extension	O
)	O
.	O
</s>
<s>
The	O
lsmod	B-Application
command	O
lists	O
the	O
loaded	O
kernel	B-Application
modules	I-Application
.	O
</s>
<s>
broken	O
modules	B-Application
,	O
specific	O
modules	B-Application
can	O
be	O
enabled	O
or	O
disabled	O
by	O
modifying	O
the	O
kernel	B-Operating_System
boot	O
parameters	O
list	O
(	O
for	O
example	O
,	O
if	O
using	O
GRUB	B-Application
,	O
by	O
pressing	O
'	O
e	O
 '	O
in	O
the	O
GRUB	B-Application
start	O
menu	O
,	O
then	O
editing	O
the	O
kernel	B-Operating_System
parameter	O
line	O
)	O
.	O
</s>
<s>
In	O
the	O
opinion	O
of	O
Linux	O
maintainers	O
,	O
LKM	O
are	O
derived	O
works	O
of	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
The	O
Linux	O
maintainers	O
tolerate	O
the	O
distribution	O
of	O
proprietary	B-Application
modules	B-Application
,	O
but	O
allow	O
symbols	O
to	O
be	O
marked	O
as	O
only	O
available	O
to	O
GNU	B-License
General	I-License
Public	I-License
License	I-License
(	O
GPL	B-License
)	O
modules	B-Application
.	O
</s>
<s>
Loading	O
a	O
proprietary	B-Application
or	O
non-GPL-compatible	O
module	B-Application
will	O
set	O
a	O
'	O
taint	O
 '	O
flag	O
in	O
the	O
running	O
kernel	B-Operating_System
—	O
meaning	O
that	O
any	O
problems	O
or	O
bugs	O
experienced	O
will	O
be	O
less	O
likely	O
to	O
be	O
investigated	O
by	O
the	O
maintainers	O
.	O
</s>
<s>
LKMs	O
effectively	O
become	O
part	O
of	O
the	O
running	O
kernel	B-Operating_System
,	O
so	O
can	O
corrupt	O
kernel	B-Operating_System
data	O
structures	O
and	O
produce	O
bugs	O
that	O
may	O
not	O
be	O
able	O
to	O
be	O
investigated	O
if	O
the	O
module	B-Application
is	O
indeed	O
proprietary	B-Application
.	O
</s>
<s>
In	O
2004	O
,	O
Linuxant	O
,	O
a	O
consulting	O
company	O
that	O
releases	O
proprietary	B-Application
device	B-Application
drivers	I-Application
as	O
loadable	B-Application
kernel	I-Application
modules	I-Application
,	O
attempted	O
to	O
abuse	O
a	O
null	O
terminator	O
in	O
their	O
MODULE_LICENSE	O
,	O
as	O
visible	O
in	O
the	O
following	O
code	O
excerpt	O
:	O
</s>
<s>
The	O
string	O
comparison	O
code	O
used	O
by	O
the	O
kernel	B-Operating_System
at	O
the	O
time	O
tried	O
to	O
determine	O
whether	O
the	O
module	B-Application
was	O
GPLed	O
stopped	O
when	O
it	O
reached	O
a	O
null	O
character	O
(	O
\0	O
)	O
,	O
so	O
it	O
was	O
fooled	O
into	O
thinking	O
that	O
the	O
module	B-Application
was	O
declaring	O
its	O
license	O
to	O
be	O
just	O
"	O
GPL	B-License
"	O
.	O
</s>
<s>
Kernel	B-Application
modules	I-Application
for	O
FreeBSD	B-Operating_System
are	O
stored	O
within	O
/boot/kernel/	O
for	O
modules	B-Application
distributed	O
with	O
the	O
operating	B-General_Concept
system	I-General_Concept
,	O
or	O
usually	O
/boot/modules/	O
for	O
modules	B-Application
installed	O
from	O
FreeBSD	B-Application
ports	I-Application
or	O
FreeBSD	B-Operating_System
packages	O
,	O
or	O
for	O
proprietary	B-Application
or	O
otherwise	O
binary-only	O
modules	B-Application
.	O
</s>
<s>
FreeBSD	B-Operating_System
kernel	B-Application
modules	I-Application
usually	O
have	O
the	O
extension	O
.ko	B-Application
.	O
</s>
<s>
Modules	B-Application
can	O
also	O
be	O
loaded	O
from	O
the	O
loader	O
before	O
the	O
kernel	B-Operating_System
starts	O
,	O
either	O
automatically	O
(	O
through	O
/boot/loader.conf	O
)	O
or	O
by	O
hand	O
.	O
</s>
<s>
Some	O
loadable	B-Application
kernel	I-Application
modules	I-Application
in	O
macOS	B-Application
can	O
be	O
loaded	O
automatically	O
.	O
</s>
<s>
Loadable	B-Application
kernel	I-Application
modules	I-Application
can	O
also	O
be	O
loaded	O
by	O
the	O
kextload	O
command	O
.	O
</s>
<s>
Loadable	B-Application
kernel	I-Application
modules	I-Application
are	O
located	O
in	O
bundles	B-Application
with	O
the	O
extension	O
.kext	O
.	O
</s>
<s>
Modules	B-Application
supplied	O
with	O
the	O
operating	B-General_Concept
system	I-General_Concept
are	O
stored	O
in	O
the	O
/System/Library/Extensions	O
directory	O
;	O
modules	B-Application
supplied	O
by	O
third	O
parties	O
are	O
in	O
various	O
other	O
directories	O
.	O
</s>
<s>
A	O
NetWare	O
kernel	B-Application
module	I-Application
is	O
referred	O
to	O
as	O
a	O
NetWare	B-Application
Loadable	I-Application
Module	I-Application
(	O
NLM	B-Application
)	O
.	O
</s>
<s>
NLMs	B-Application
are	O
inserted	O
into	O
the	O
NetWare	O
kernel	B-Operating_System
by	O
means	O
of	O
the	O
LOAD	O
command	O
,	O
and	O
removed	O
by	O
means	O
of	O
the	O
UNLOAD	O
command	O
;	O
the	O
modules	B-Application
command	O
lists	O
currently	O
loaded	O
kernel	B-Application
modules	I-Application
.	O
</s>
<s>
NLMs	B-Application
may	O
reside	O
in	O
any	O
valid	O
search	O
path	O
assigned	O
on	O
the	O
NetWare	O
server	O
,	O
and	O
they	O
have	O
.NLM	B-Application
as	O
the	O
file	B-Operating_System
name	O
extension	O
.	O
</s>
<s>
A	O
downloadable	O
kernel	B-Application
module	I-Application
(	O
DKM	O
)	O
type	O
project	O
can	O
be	O
created	O
to	O
generate	O
a	O
"	O
.out	O
"	O
file	B-Operating_System
which	O
can	O
then	O
be	O
loaded	O
to	O
kernel	B-Operating_System
space	O
using	O
"	O
ld	O
"	O
command	O
.	O
</s>
<s>
This	O
downloadable	O
kernel	B-Application
module	I-Application
can	O
be	O
unloaded	O
using	O
"	O
unld	O
"	O
command	O
.	O
</s>
<s>
Solaris	B-Application
has	O
a	O
configurable	O
kernel	B-Application
module	I-Application
load	O
path	O
,	O
which	O
defaults	O
to	O
/platform/platform-name/kernel	O
/kernel	O
/usr/kernel	O
.	O
</s>
<s>
Most	O
kernel	B-Application
modules	I-Application
live	O
in	O
subdirectories	O
under	O
/kernel	O
;	O
those	O
not	O
considered	O
necessary	O
to	O
boot	O
the	O
system	O
to	O
the	O
point	O
that	O
init	O
can	O
start	O
are	O
often	O
(	O
but	O
not	O
always	O
)	O
found	O
in	O
/usr/kernel	O
.	O
</s>
<s>
When	O
running	O
a	O
DEBUG	O
kernel	B-Operating_System
build	O
the	O
system	O
actively	O
attempts	O
to	O
unload	O
modules	B-Application
.	O
</s>
<s>
Linux	O
does	O
not	O
provide	O
a	O
stable	O
API	B-General_Concept
or	O
ABI	B-Operating_System
for	O
kernel	B-Application
modules	I-Application
.	O
</s>
<s>
This	O
means	O
that	O
there	O
are	O
differences	O
in	O
internal	O
structure	O
and	O
function	O
between	O
different	O
kernel	B-Operating_System
versions	O
,	O
which	O
can	O
cause	O
compatibility	O
problems	O
.	O
</s>
<s>
In	O
an	O
attempt	O
to	O
combat	O
those	O
problems	O
,	O
symbol	O
versioning	O
data	O
is	O
placed	O
within	O
the	O
.modinfo	O
section	O
of	O
loadable	O
ELF	O
modules	B-Application
.	O
</s>
<s>
This	O
versioning	O
information	O
can	O
be	O
compared	O
with	O
that	O
of	O
the	O
running	O
kernel	B-Operating_System
before	O
loading	O
a	O
module	B-Application
;	O
if	O
the	O
versions	O
are	O
incompatible	O
,	O
the	O
module	B-Application
will	O
not	O
be	O
loaded	O
.	O
</s>
<s>
Other	O
operating	B-General_Concept
systems	I-General_Concept
,	O
such	O
as	O
Solaris	B-Application
,	O
FreeBSD	B-Operating_System
,	O
macOS	B-Application
,	O
and	O
Windows	B-Application
keep	O
the	O
kernel	B-Operating_System
API	B-General_Concept
and	O
ABI	B-Operating_System
relatively	O
stable	O
,	O
thus	O
avoiding	O
this	O
problem	O
.	O
</s>
<s>
For	O
example	O
,	O
FreeBSD	B-Operating_System
kernel	B-Application
modules	I-Application
compiled	O
against	O
kernel	B-Operating_System
version	O
6.0	O
will	O
work	O
without	O
recompilation	O
on	O
any	O
other	O
FreeBSD	B-Operating_System
6.x	O
version	O
,	O
e.g.	O
</s>
<s>
However	O
,	O
they	O
are	O
not	O
compatible	O
with	O
other	O
major	O
versions	O
and	O
must	O
be	O
recompiled	O
for	O
use	O
with	O
FreeBSD	B-Operating_System
7.x	O
,	O
as	O
API	B-General_Concept
and	O
ABI	B-Operating_System
compatibility	O
is	O
maintained	O
only	O
within	O
a	O
branch	O
.	O
</s>
<s>
While	O
loadable	B-Application
kernel	I-Application
modules	I-Application
are	O
a	O
convenient	O
method	O
of	O
modifying	O
the	O
running	O
kernel	B-Operating_System
,	O
this	O
can	O
be	O
abused	O
by	O
attackers	O
on	O
a	O
compromised	O
system	O
to	O
prevent	O
detection	O
of	O
their	O
processes	B-Operating_System
or	O
files	O
,	O
allowing	O
them	O
to	O
maintain	O
control	O
over	O
the	O
system	O
.	O
</s>
<s>
Note	O
that	O
,	O
on	O
most	O
operating	B-General_Concept
systems	I-General_Concept
,	O
modules	B-Application
do	O
not	O
help	O
privilege	O
elevation	O
in	O
any	O
way	O
,	O
as	O
elevated	O
privilege	O
is	O
required	O
to	O
load	O
a	O
LKM	O
;	O
they	O
merely	O
make	O
it	O
easier	O
for	O
the	O
attacker	O
to	O
hide	O
the	O
break-in	O
.	O
</s>
<s>
Linux	O
allows	O
disabling	O
module	B-Application
loading	O
via	O
sysctl	B-Application
option	O
/proc/sys/kernel/modules_disabled	O
.	O
</s>
<s>
An	O
initramfs	B-Application
system	O
may	O
load	O
specific	O
modules	B-Application
needed	O
for	O
a	O
machine	O
at	O
boot	O
and	O
then	O
disable	O
module	B-Application
loading	O
.	O
</s>
<s>
This	O
makes	O
the	O
security	O
very	O
similar	O
to	O
a	O
monolithic	O
kernel	B-Operating_System
.	O
</s>
<s>
If	O
an	O
attacker	O
can	O
change	O
the	O
initramfs	B-Application
,	O
they	O
can	O
change	O
the	O
kernel	B-Operating_System
binary	O
.	O
</s>
<s>
In	O
OS	B-Device
X	I-Device
Yosemite	I-Device
and	O
later	O
releases	O
,	O
a	O
kernel	B-Application
extension	I-Application
has	O
to	O
be	O
code-signed	O
with	O
a	O
developer	O
certificate	O
that	O
holds	O
a	O
particular	O
"	O
entitlement	O
"	O
for	O
this	O
.	O
</s>
<s>
Such	O
a	O
developer	O
certificate	O
is	O
only	O
provided	O
by	O
Apple	O
on	O
request	O
and	O
not	O
automatically	O
given	O
to	O
Apple	B-Operating_System
Developer	I-Operating_System
members	O
.	O
</s>
<s>
This	O
feature	O
,	O
called	O
"	O
kext	B-Operating_System
signing	I-Operating_System
"	O
,	O
is	O
enabled	O
by	O
default	O
and	O
it	O
instructs	O
the	O
kernel	B-Operating_System
to	O
stop	O
booting	O
if	O
unsigned	O
kernel	B-Application
extensions	I-Application
are	O
present	O
.	O
</s>
<s>
In	O
El	O
Capitan	O
and	O
later	O
releases	O
,	O
it	O
is	O
part	O
of	O
System	B-Operating_System
Integrity	I-Operating_System
Protection	I-Operating_System
.	O
</s>
<s>
In	O
older	O
versions	O
of	O
macOS	B-Application
,	O
or	O
if	O
kext	B-Operating_System
signing	I-Operating_System
is	O
disabled	O
,	O
a	O
loadable	B-Application
kernel	I-Application
module	I-Application
in	O
a	O
kernel	B-Application
extension	I-Application
bundle	B-Application
can	O
be	O
loaded	O
by	O
non-root	O
users	O
if	O
the	O
OSBundleAllowUserLoad	O
property	O
is	O
set	O
to	O
True	O
in	O
the	O
bundle	B-Application
's	O
property	O
list	O
.	O
</s>
<s>
However	O
,	O
if	O
any	O
of	O
the	O
files	O
in	O
the	O
bundle	B-Application
,	O
including	O
the	O
executable	O
code	O
file	B-Operating_System
,	O
are	O
not	O
owned	O
by	O
root	O
and	O
group	O
wheel	O
,	O
or	O
are	O
writable	O
by	O
the	O
group	O
or	O
"	O
other	O
"	O
,	O
the	O
attempt	O
to	O
load	O
the	O
kernel	B-Operating_System
loadable	O
module	B-Application
will	O
fail	O
.	O
</s>
<s>
Kernel	B-Application
modules	I-Application
can	O
optionally	O
have	O
a	O
cryptographic	O
signature	O
ELF	O
section	O
which	O
is	O
verified	O
on	O
load	O
depending	O
on	O
the	O
Verified	O
Boot	O
policy	O
settings	O
.	O
</s>
<s>
The	O
kernel	B-Operating_System
can	O
enforce	O
that	O
modules	B-Application
are	O
cryptographically	O
signed	O
by	O
a	O
set	O
of	O
trusted	O
certificates	O
;	O
the	O
list	O
of	O
trusted	O
certificates	O
is	O
held	O
outside	O
of	O
the	O
OS	O
in	O
the	O
ILOM	O
on	O
some	O
SPARC	O
based	O
platforms	O
.	O
</s>
<s>
Userspace	O
initiated	O
kernel	B-Application
module	I-Application
loading	O
is	O
only	O
possible	O
from	O
the	O
Trusted	O
Path	O
when	O
the	O
system	O
is	O
running	O
with	O
the	O
Immutable	O
Global	O
Zone	O
feature	O
enabled	O
.	O
</s>
