Skip to content

Commit 9ba3d9b

Browse files
committed
Several fixes:
* The capabilities array was to have a 64bit bitwise. * Capabilities set has to be tested with the kernel maximum. We can't use the plugin capabilities set, otherwise we can have wrong interpretations when we tried to compress the list of capabilities to "all" * Supports kernels >= 6.3. They changed the kernel_cap_struct::cap type again to a u64 type.
1 parent 373d769 commit 9ba3d9b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

volatility3/framework/constants/linux/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,3 @@
279279
"bpf",
280280
"checkpoint_restore",
281281
)
282-
283-
CAP_FULL = 0xFFFFFFFF

volatility3/framework/plugins/linux/capabilities.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Iterable, List, Tuple
88

99
from volatility3.framework import interfaces, renderers, exceptions
10-
from volatility3.framework.constants.linux import CAP_FULL
1110
from volatility3.framework.configuration import requirements
1211
from volatility3.framework.interfaces import plugins
1312
from volatility3.framework.objects import utility
@@ -117,7 +116,7 @@ def _decode_cap(cap: interfaces.objects.ObjectInterface) -> str:
117116
if not cap_value:
118117
return ""
119118

120-
if cap_value == CAP_FULL:
119+
if cap_value == cap.get_kernel_cap_full():
121120
return "all"
122121

123122
return ", ".join(cap.enumerate_capabilities())

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from volatility3.framework.constants.linux import TCP_STATES, NETLINK_PROTOCOLS
1414
from volatility3.framework.constants.linux import ETH_PROTOCOLS, BLUETOOTH_STATES
1515
from volatility3.framework.constants.linux import BLUETOOTH_PROTOCOLS, SOCKET_STATES
16-
from volatility3.framework.constants.linux import CAPABILITIES, CAP_FULL
16+
from volatility3.framework.constants.linux import CAPABILITIES
1717
from volatility3.framework import exceptions, objects, interfaces, symbols
1818
from volatility3.framework.layers import linear
1919
from volatility3.framework.objects import utility
@@ -1482,6 +1482,21 @@ def get_last_cap_value(cls) -> int:
14821482
"""
14831483
return len(CAPABILITIES) - 1
14841484

1485+
def get_kernel_cap_full(self) -> int:
1486+
"""Return the maximum value allowed for this kernel for a capability
1487+
1488+
Returns:
1489+
int: _description_
1490+
"""
1491+
vmlinux = linux.LinuxUtilities.get_module_from_volobj_type(self._context, self)
1492+
try:
1493+
cap_last_cap = vmlinux.object_from_symbol(symbol_name="cap_last_cap")
1494+
except exceptions.SymbolError:
1495+
# It should be a kernel < 3.2, let's use our list of capabilities
1496+
cap_last_cap = self.get_last_cap_value()
1497+
1498+
return (1 << cap_last_cap + 1) - 1
1499+
14851500
@classmethod
14861501
def capabilities_to_string(cls, capabilities_bitfield: int) -> List[str]:
14871502
"""Translates a capability bitfield to a list of capability strings.
@@ -1506,9 +1521,17 @@ def get_capabilities(self) -> int:
15061521
Returns:
15071522
int: The capability bitfield value.
15081523
"""
1509-
# In kernels 2.6.25.20 the kernel_cap_struct::cap became and array
1510-
cap_value = self.cap[0] if isinstance(self.cap, objects.Array) else self.cap
1511-
return cap_value & CAP_FULL
1524+
1525+
if isinstance(self.cap, objects.Array):
1526+
# In 2.6.25.x <= kernels < 6.3 kernel_cap_struct::cap is an array
1527+
# to become a 64bit bitfield
1528+
cap_value = (self.cap[1] << 32) | self.cap[0]
1529+
else:
1530+
# In kernels < 2.6.25.x kernel_cap_struct::cap was a u32
1531+
# In kernels >= 6.3 kernel_cap_struct::cap is a u64
1532+
cap_value = self.cap
1533+
1534+
return cap_value & self.get_kernel_cap_full()
15121535

15131536
def enumerate_capabilities(self) -> List[str]:
15141537
"""Returns the list of capability strings.

0 commit comments

Comments
 (0)