Search code examples
linuxmodulekerneltaskpid

Task owner pid in a Linux kernel module when executed in swapper


Given a task instance having pid 0 and comm "swapper/0", how to get the owner pid ?

==EDIT==

This happens using Netfilter hooks.


Solution

  • The current task in a netfilter outgoing hook context will always have a TGID (PID in the userspace) if the packet is UDP.

    For a SYN TCP packets the current task will have a TGID, but a ACK packet will not have it. To retrieve the TGID you have to calculate the socket sequence from the SYN packet using the packet length.