Skip to contentSkip to conversation

Extending LOG target to display pid

DISCUSSION Nick Hay 3 participants 3 messages Jul 5, 2005 netfilter

lore
Share & tools
lore

Nick Hay

author
#0 lore raw

What I hoped to be an easy hack quickly ran into problems. I planned to add an extra printk() in dump_packet() to output the pid, and perhaps the program executable number. Since the owner module had access to the pid, I assumed there would be some way to get this information to the LOG module. After a frustrating search through source code and documentation, I have the following questions:

1. For the owner module, where/how is the struct ipt_owner_info filled in for each packet? In general, how is the ipt_entry_match/target data field filled in?

2. Any ideas on how I can get the pid of a local packet's creator in the log module? I couldn't find any structures connected to the sk_buff that might contain it, and couldn't think of where the data would originally come from.

Actually... would current->pid work?

I'm still curious about question 1, though!

-- Nick Hay

#1 lore raw
Quoted 4 lines · Nick Hay

2. Any ideas on how I can get the pid of a local packet's creator in the log module? I couldn't find any structures connected to the sk_buff that might contain it, and couldn't think of where the data would originally come from.

A security framework, with the proper auditing and accounting mechanisms in place in the network stack could make this possible (any it may already be). But in general, it would be quite a lot of work to add the necessary code to the stack to account for the sending/receiving PID at the correct stage. Unless you're doing MAC, its probably not worth it.

Quoted 1 line

Actually... would current->pid work?

No, because there's no guarantee that the same process is on the CPU by the time the packet hits your rule.

Can't check on #1 right now, but I believe that its filled in by the module itself in whatever way it chooses.

Signature · 2 lines
[ Tobias DiPasquale ]
0x636f6465736c696e67657240676d61696c2e636f6d
#2 lore raw
In reply to Nick Hay
Quoted 4 lines · Nick Hay

2. Any ideas on how I can get the pid of a local packet's creator in the log module? I couldn't find any structures connected to the sk_buff that might contain it, and couldn't think of where the data would originally come from.

You can copy-paste code from the owner match extension to LOG target to implement it.

In short, you can do it but to make it pretty requires lot of work (and knowledge).

You might find this helpful:
http://www.fsfe.org/Members/juha/thesis/thesis.pdf

FYI The owner match extension is just betting when it locates the packet owner. Although, I admit that it bets right in ~99% of cases... :)

Some body at the netfilter-devel might known could the "socket hooks" be used:
https://lists.netfilter.org/pipermail/netfilter-devel/2005-May/thread.html#19654

Quoted 1 line

Actually... would current->pid work?

No. The netfilter code executes quite often in interrupt context (e.g. when sending tcp syn packets). The current macro might or might not point to task that sends data.

Regards,
Juha Heljoranta