Skip to content

Commit d1d45ca

Browse files
authored
Merge pull request #1311 from gcmoreira/linux_threads_support_from_6.7
Linux - Add support for task threads in kernels >= 6.7
2 parents a10fb5b + e352114 commit d1d45ca

File tree

1 file changed

+21
-12
lines changed
  • volatility3/framework/symbols/linux/extensions

1 file changed

+21
-12
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,29 @@ def is_user_thread(self) -> bool:
359359
"""
360360
return not self.is_kernel_thread and self.tgid != self.pid
361361

362-
def get_threads(self) -> Iterable[interfaces.objects.ObjectInterface]:
363-
"""Returns a list of the task_struct based on the list_head
364-
thread_node structure."""
362+
def _get_tasks_iterable(self) -> Iterable[interfaces.objects.ObjectInterface]:
363+
"""Returns the respective iterable to obtain the threads in this process"""
364+
vmlinux = linux.LinuxUtilities.get_module_from_volobj_type(self._context, self)
365+
task_struct_symname = f"{vmlinux.symbol_table_name}{constants.BANG}task_struct"
366+
if vmlinux.get_type("task_struct").has_member("signal") and vmlinux.get_type(
367+
"signal_struct"
368+
).has_member("thread_head"):
369+
# kernels >= 6.7 - via signals
370+
return self.signal.thread_head.to_list(task_struct_symname, "thread_node")
371+
elif vmlinux.get_type("task_struct").has_member("thread_group"):
372+
# kernels < 6.7 - via thread_group
373+
return self.thread_group.to_list(task_struct_symname, "thread_group")
365374

366-
task_symbol_table_name = self.get_symbol_table_name()
375+
raise AttributeError("Unable to find the root dentry")
367376

368-
# iterating through the thread_list from thread_group
369-
# this allows iterating through pointers to grab the
370-
# threads and using the thread_group offset to get the
371-
# corresponding task_struct
372-
for task in self.thread_group.to_list(
373-
f"{task_symbol_table_name}{constants.BANG}task_struct", "thread_group"
374-
):
375-
yield task
377+
def get_threads(self) -> Iterable[interfaces.objects.ObjectInterface]:
378+
"""Returns each thread in this process"""
379+
tasks_iterable = self._get_tasks_iterable()
380+
threads_seen = set([self.vol.offset])
381+
for task in tasks_iterable:
382+
if task.vol.offset not in threads_seen:
383+
threads_seen.add(task.vol.offset)
384+
yield task
376385

377386

378387
class fs_struct(objects.StructType):

0 commit comments

Comments
 (0)