Skip to content

Commit 4b76b69

Browse files
committed
Linux: hidden_modules: Add docstrings and comments to enhance the documentation of the module verification process. Move the hardcoded values to the linux constants file.
1 parent f537c4a commit 4b76b69

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

volatility3/framework/constants/linux/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,11 @@ class PT_FLAGS(Flag):
339339
def flags(self) -> str:
340340
"""Returns the ptrace flags string"""
341341
return str(self).replace(self.__class__.__name__ + ".", "")
342+
343+
344+
# Valid sizes for modules. Note that the Linux kernel does not define these values; they
345+
# are based on empirical observations of typical memory allocations for kernel modules.
346+
# We use this to verify that the found module falls within reasonable limits.
347+
MODULE_MAXIMUM_CORE_SIZE = 20000000
348+
MODULE_MAXIMUM_CORE_TEXT_SIZE = 20000000
349+
MODULE_MINIMUM_SIZE = 4096

volatility3/framework/symbols/linux/extensions/__init__.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@
1313

1414
from volatility3.framework import constants, exceptions, objects, interfaces, symbols
1515
from volatility3.framework.renderers import conversion
16-
from volatility3.framework.constants.linux import SOCK_TYPES, SOCK_FAMILY
17-
from volatility3.framework.constants.linux import IP_PROTOCOLS, IPV6_PROTOCOLS
18-
from volatility3.framework.constants.linux import TCP_STATES, NETLINK_PROTOCOLS
19-
from volatility3.framework.constants.linux import ETH_PROTOCOLS, BLUETOOTH_STATES
20-
from volatility3.framework.constants.linux import BLUETOOTH_PROTOCOLS, SOCKET_STATES
21-
from volatility3.framework.constants.linux import CAPABILITIES, PT_FLAGS
16+
from volatility3.framework.constants.linux import (
17+
SOCK_TYPES,
18+
SOCK_FAMILY,
19+
IP_PROTOCOLS,
20+
IPV6_PROTOCOLS,
21+
TCP_STATES,
22+
NETLINK_PROTOCOLS,
23+
ETH_PROTOCOLS,
24+
BLUETOOTH_STATES,
25+
BLUETOOTH_PROTOCOLS,
26+
SOCKET_STATES,
27+
CAPABILITIES,
28+
PT_FLAGS,
29+
MODULE_MAXIMUM_CORE_SIZE,
30+
MODULE_MAXIMUM_CORE_TEXT_SIZE,
31+
MODULE_MINIMUM_SIZE,
32+
)
33+
2234
from volatility3.framework.layers import linear
2335
from volatility3.framework.objects import utility
2436
from volatility3.framework.symbols import generic, linux, intermed
@@ -36,16 +48,23 @@ def __init__(self, *args, **kwargs):
3648
self._mod_mem_type = None # Initialize _mod_mem_type to None for memoization
3749

3850
def is_valid(self):
51+
"""Determine whether it is a valid module object by verifying the self-referential
52+
in module_kobject. This also confirms that the module is actively allocated and
53+
not a remnant of freed memory or a failed module load attempt by verifying the
54+
module memory section sizes.
55+
"""
3956
layer = self._context.layers[self.vol.layer_name]
4057
# Make sure the entire module content is readable
4158
if not layer.is_valid(self.vol.offset, self.vol.size):
4259
return False
4360

4461
core_size = self.get_core_size()
62+
core_text_size = self.get_core_text_size()
63+
init_size = self.get_init_size()
4564
if not (
46-
1 <= core_size <= 20000000
47-
and core_size + self.get_init_size() >= 4096
48-
and 1 <= self.get_core_text_size() <= 20000000
65+
0 < core_text_size <= MODULE_MAXIMUM_CORE_TEXT_SIZE
66+
and 0 < core_size <= MODULE_MAXIMUM_CORE_SIZE
67+
and core_size + init_size >= MODULE_MINIMUM_SIZE
4968
):
5069
return False
5170

0 commit comments

Comments
 (0)